Text to Speech

Create speech

Convert text to speech and receive the audio file in the response.

POST/v1/tts

Send JSON with the text and a voice. The response body is the audio file; generation metadata comes back in headers. Requires an API key with all permission. Accepts an Idempotency-Key header for safe retries.

from wistfareai import WistfareAI

client = WistfareAI()  # reads WISTFARE_API_KEY

audio = client.text_to_speech.convert(
    text="Muraho neza, murakaza neza kuri Wistfare.",
    voice_id="vc_9f2ae1",
    model="wistfare-tts-v1-beta",
    output_format="mp3",   # mp3 | wav
    speed=1.0,             # 0.5–2.0
)
with open("muraho.mp3", "wb") as f:
    f.write(audio)
print(audio.generation_id, audio.audio_seconds, audio.cost_cents)

Request

JSON body:

FieldTypeDefaultDescription
textstringrequiredThe text to speak, 1 to 5,000 characters.
voice_idstringrequiredThe voice, e.g. vc_9f2ae1. List voices with GET /v1/voices.
modelstringwistfare-tts-v1-betaThe text-to-speech model (alias wistfare-tts-beta).
formatstringmp3mp3 or wav. SDKs: output_format / outputFormat.
speednumber1.0Speaking rate, 0.5 to 2.0.

Response

200 OK with the audio bytes as the body: Content-Type: audio/mpeg for MP3, audio/wav for WAV. There's no streaming synthesis: the whole clip comes back at once.

The SDKs return the bytes (a bytes subclass in Python, a Uint8Array subclass in JavaScript) with the headers below attached as generation_id, audio_seconds, cost_cents and content_type (camelCase in JavaScript), so you can write the result straight to a file.

HeaderExampleDescription
X-Generation-Idgen_7c31be92a1f04d2e8b9cId of this generation. Include it in support requests.
X-Audio-Seconds4.62Duration of the generated audio.
X-Credits-Charged-Cents2What the request cost, in US cents.
X-Request-Id9b2f4c1e6a8d4e0fb3c7a5d2e1f09a64The request's correlation id.

Billing: $0.15 per minute of max(output seconds, output seconds × speed), rounded up to the next cent, minimum 1¢. X-Audio-Seconds is the clip's playback length. An estimate from the text is held before generating and settled at the actual cost.

Errors

StatusCodeMeaning
401unauthorizedMissing, invalid or revoked API key.
402insufficient_credits / budget_exceededNot enough credits, or the project's budget is reached. Nothing was charged.
403read_only_key / account_suspendedThe key is read-only, or spending is suspended on the account.
409idempotency_in_progressA request with the same Idempotency-Key is still running.
404not_foundUnknown voice_id.
422validation_error / idempotency_mismatchEmpty or too-long text, unknown model, speed out of range, or a bad format; or an Idempotency-Key reused with a different body.
429rate_limitedRequest-rate limit reached. Retry after Retry-After seconds.

On this page