TTS
Generate and manage API-created Text-to-Speech (TTS) audios, exposed through client.tts.
List TTS audios
Returns a paginated list of API-created TTS audios belonging to your team. Audios created by a different API key for the same team are included; audios created without an API key are not.
audios = client.tts.list(
search=None, # search by title
per_page=10,
page=1,
sort=None, # created_at, -created_at, updated_at, -updated_at, uuid, -uuid (default -created_at)
voice=None, # filter by voice slug
date_from=None, # only audios created on/after this date
date_to=None, # only audios created on/before this date
extra_params=None, # dict of additional query parameters
timeout=None, # override the client's default timeout, in seconds
)
Generate a TTS audio
Converts text into speech, charges your team for the usage, and associates the generated audio with the current API key.
audio = client.tts.generate(
text="ދިވެހިޖީޕީޓީއަށް މަރުޙަބާ", # up to 10,000 characters
voice="hajja", # a slug returned by client.voices.list()
extra_params=None, # dict of additional body parameters
timeout=None, # override the request timeout, in seconds (defaults to 120)
)
Generation defaults to a 120 second request timeout (rather than the client's default of 30 seconds) since audio generation can take a while. Pass timeout= to override this per call.
{
"data": {
"uuid": "b7d7a270-7dc3-46c9-be27-d68f0ce55f36",
"title": "ދިވެހިޖީޕީޓީއަށް މަރުޙަބާ",
"text": "ދިވެހިޖީޕީޓީއަށް މަރުޙަބާ",
"normalized_text": "ދިވެހިޖީޕީޓީއަށް މަރުހަބާ",
"duration": 1860,
"audio_url": "https://...",
"voice": "hajja",
"usage": {"charged_credits": 0.25, "usage_units": 25, ...},
"created_at": "...",
"updated_at": "...",
}
}
Raises dhivehigpt_sdk.PermissionDeniedError when your team has no credits available, and dhivehigpt_sdk.ServerError if the speech provider fails to generate the audio.
Get a TTS audio
audio = client.tts.get("b7d7a270-7dc3-46c9-be27-d68f0ce55f36")
Update a TTS audio
Updates the display title of an API-created TTS audio (up to 255 characters).
audio = client.tts.update("b7d7a270-7dc3-46c9-be27-d68f0ce55f36", title="Welcome message")
update and delete also accept extra_params (body parameters, update only) and timeout keyword arguments, same as above.
Delete a TTS audio
client.tts.delete("b7d7a270-7dc3-46c9-be27-d68f0ce55f36")
Returns None on success (HTTP 204).
All of the above raise dhivehigpt_sdk.NotFoundError when the TTS audio was not created through the API, does not exist, or does not belong to your team.