Converting Speech to Text
Learn how to convert audio recordings into accurate text transcriptions using Synexa AI’s speech recognition API.
Basic Usage
Our API makes it simple to convert speech to text using advanced models.
Python Example
import synexa
# Convert speech to text
output = synexa.run(
"openai/whisper",
input={
"audio": "path/to/audio.wav" # Local audio file
}
)
# Get the transcription
transcript = output[0]["text"]
print(transcript)
Node.js Example
import Synexa from 'synexa';
import fs from 'fs';
const synexa = new Synexa.default({
auth: process.env.SYNEXA_API_TOKEN
});
// Convert speech to text
const audioBuffer = fs.readFileSync('path/to/audio.wav');
const [output] = await synexa.run("openai/whisper", {
input: {
audio: audioBuffer
}
});
// Get the transcription
console.log(output.text);
Advanced Options
You can customize the transcription with additional parameters:
# Python example with advanced options
output = synexa.run(
"openai/whisper",
input={
"audio": "https://replicate.delivery/mgxm/e5159b1b-508a-4be4-b892-e1eb47850bdc/OSR_uk_000_0050_8k.wav",
"language": "auto",
"translate": False,
"temperature": 0,
"transcription": "plain text",
"suppress_tokens": "-1",
"logprob_threshold": -1,
"no_speech_threshold": 0.6,
"condition_on_previous_text": True,
"compression_ratio_threshold": 2.4,
"temperature_increment_on_fallback": 0.2
}
)
# Get detailed output
transcript = output[0]["text"]
timestamps = output[0]["timestamps"]
// Node.js example with advanced options
const [output] = await synexa.run("openai/whisper", {
input: {
audio: "https://replicate.delivery/mgxm/e5159b1b-508a-4be4-b892-e1eb47850bdc/OSR_uk_000_0050_8k.wav",
language: "auto",
translate: false,
temperature: 0,
transcription: "plain text",
suppress_tokens: "-1",
logprob_threshold: -1,
no_speech_threshold: 0.6,
condition_on_previous_text: true,
compression_ratio_threshold: 2.4,
temperature_increment_on_fallback: 0.2
}
});
// Get detailed output
const { text, timestamps } = output;
Error Handling
Always handle potential errors when processing audio:
# Python error handling
try:
output = synexa.run(
"openai/whisper",
input={"audio": "path/to/audio.wav"}
)
except Exception as e:
print(f"Error processing audio: {e}")
// Node.js error handling
try {
const [output] = await synexa.run("openai/whisper", {
input: { audio: "path/to/audio.wav" }
});
} catch (error) {
console.error("Error processing audio:", error);
}