Audio (TTS & STT)

View as Markdown

Audio

Text-to-Speech

client.audio.synthesize sends POST /v1/audio/speech and returns raw audio bytes.

1from meshapi import MeshAPI, SpeechParams
2
3client = MeshAPI(base_url="https://api.meshapi.ai", token="rsk_...")
4
5audio_bytes = client.audio.synthesize(
6 SpeechParams(
7 input="Hello from MeshAPI.",
8 model="sarvam/bulbul:v2",
9 voice="meera",
10 )
11)
12
13with open("output.wav", "wb") as f:
14 f.write(audio_bytes)

Async

1from meshapi import AsyncMeshAPI, SpeechParams
2
3async with AsyncMeshAPI(base_url="https://api.meshapi.ai", token="rsk_...") as client:
4 audio_bytes = await client.audio.synthesize(
5 SpeechParams(
6 input="Hello from MeshAPI.",
7 model="sarvam/bulbul:v2",
8 )
9 )

SpeechParams fields

FieldTypeNotes
inputstrRequired. Text to synthesize.
modelstrRequired. e.g. "sarvam/bulbul:v2"
voicestr | NoneVoice ID or name
response_formatstr | NoneAudio format, e.g. "wav", "mp3"
speedfloat | NonePlayback speed multiplier

Speech-to-Text (Transcription)

client.audio.transcribe sends POST /v1/audio/transcriptions as a multipart upload and returns a TranscriptionResponse.

1from meshapi import TranscriptionParams
2
3with open("audio.wav", "rb") as f:
4 file_bytes = f.read()
5
6result = client.audio.transcribe(
7 file_bytes,
8 TranscriptionParams(
9 model="sarvam/saaras:v3",
10 # Optional: language_code is model-specific (e.g. Sarvam expects "en-IN", not "en").
11 ),
12 filename="audio.wav",
13)
14
15print(result.text)

TranscriptionParams key fields

FieldTypeNotes
modelstrRequired. e.g. "sarvam/saaras:v3"
language_codestr | NoneOptional. Model-specific language code (e.g. Sarvam expects "en-IN")
diarizebool | NoneEnable speaker diarization
num_speakersint | NoneExpected number of speakers
timestamps_granularitystr | Nonee.g. "word" for word-level timestamps
tag_audio_eventsbool | NoneTag non-speech audio events
additional_formatsstr | NoneRequest extra output formats

Translation

client.audio.translate sends POST /v1/audio/transcriptions/translate and returns the audio transcribed and translated to English.

1from meshapi import TranscriptionTranslateParams
2
3with open("audio.wav", "rb") as f:
4 file_bytes = f.read()
5
6result = client.audio.translate(
7 file_bytes,
8 TranscriptionTranslateParams(
9 model="sarvam/saaras:v3",
10 ),
11 filename="audio.wav",
12)
13
14print(result.text)

Translation (to English)

client.audio.audio_translate sends POST /v1/audio/translations and returns the audio translated directly to English. This is a distinct endpoint from the transcribe-and-translate helper above.

1from meshapi import MeshAPI, AudioTranslationsParams
2
3client = MeshAPI(base_url="https://api.meshapi.ai", token="rsk_...")
4
5with open("audio.mp3", "rb") as f:
6 file_bytes = f.read()
7
8result = client.audio.audio_translate(
9 file_bytes,
10 AudioTranslationsParams(
11 model="openai/whisper-large-v3",
12 ),
13 filename="audio.mp3",
14)
15
16print(result.text) # English translation

Async

1from meshapi import AsyncMeshAPI, AudioTranslationsParams
2
3async with AsyncMeshAPI(base_url="https://api.meshapi.ai", token="rsk_...") as client:
4 with open("audio.mp3", "rb") as f:
5 file_bytes = f.read()
6
7 result = await client.audio.audio_translate(
8 file_bytes,
9 AudioTranslationsParams(model="openai/whisper-large-v3"),
10 filename="audio.mp3",
11 )
12 print(result.text)

AudioTranslationsParams fields

FieldTypeNotes
modelstrRequired. A translation-capable model (see the Models list).
promptstr | NoneOptional context hint to guide the translation.
response_formatstr | None"json", "text", or "verbose_json".
temperaturefloat | NoneSampling temperature (0–2).

The response .text field contains the English translation.


List Voices

client.audio.list_voices sends GET /v1/audio/voices.

1from meshapi import ListVoicesParams
2
3voices = client.audio.list_voices(ListVoicesParams(page_size=10))
4print(voices)

ListVoicesParams fields

FieldTypeNotes
page_sizeint | NoneResults per page
next_page_tokenstr | NonePagination cursor
searchstr | NoneFilter by name
voice_typestr | None"standard", "cloned", etc.
categorystr | NoneVoice category filter

Get Voice

client.audio.get_voice sends GET /v1/audio/voices/{voice_id}.

1voice = client.audio.get_voice("voice-id")
2print(voice)