Skip to main content

vaakini

The Python SDK for Vaakini: text to speech in 12 Indian languages with one model, vaakini-tts-1.

Full documentation: docs.vaakini.com/python.

Install

pip install vaakini

Usage

from vaakini import Vaakini

client = Vaakini()  # reads VAAKINI_API_KEY; or Vaakini(api_key="vk_…")

audio = client.speech.create(input="नमस्ते, आप कैसे हैं?", voice="Monika", language="hi")
with open("hello.mp3", "wb") as f:
    f.write(audio)

Your API key is in the dashboard at vaakini.com. AsyncVaakini is the same client for asyncio: every call below is awaited.

Speech

# The audio as it arrives: the first of it follows the text's first sentence.
for chunk in client.speech.stream(input=text, voice="Monika", response_format="pcm"):
    play(chunk)

speech.create() and speech.stream() take:

Argument Default
input required the text, up to 20,000 characters
voice required a Vaakini voice's name, in any case ("Monika"), or the id of one of your org's custom voices ("cv_…")
language None "as", "bn", "en", "gu", "hi", "kn", "ml", "mr", "or", "pa", "ta" or "te". Left out, the model picks it from the text's script
response_format "mp3" "mp3", "pcm" (16-bit little-endian mono, 24000 Hz) or "wav"
model "vaakini-tts-1" the model; this is the only one
normalize on numbers, currency, dates, times, phone numbers, URLs and emails spoken as words
temperature, top_k, top_p, repetition_penalty the model's sampling settings

Voices and models

for voice in client.voices.list():
    print(voice.id, voice.category, voice.gender, voice.languages)

model = client.models.list()[0]
print(model.id, model.languages, model.formats)

Streamed text

For text that arrives as it is written, such as an LLM's reply, client.stream() opens a connection: text goes in piece by piece, and each sentence's audio comes back as soon as the sentence is complete.

with client.stream(voice="Monika", language="hi") as stream:
    for token in llm_tokens:
        stream.send_text(token)
    stream.flush()

    for event in stream:
        if event.type == "audio":
            play(event.data)  # 16-bit mono PCM, 24000 Hz
        elif event.type == "sentence":
            print(event.index, event.text)
        elif event.type == "done":
            print(event.sentences, "sentences,", event.characters, "characters")

A reply is one segment: send_text() any number of times, then flush(). Its events are a SentenceEvent before each sentence's AudioEvents, and a DoneEvent at the end, where the iteration stops. The next send_text() starts the next segment on the same connection; iterate again for its events.

  • stream(...) takes voice, language, model and the options that speech.create() takes, and format: "pcm" (the default) or "mp3".
  • stream.cancel() ends a segment early, for a barge-in: its remaining audio is dropped, and its iteration stops at a CancelledEvent. The next segment's text can be sent at once.
  • To play audio while the text is still arriving, send on one thread and iterate on another, once the segment's first send_text() has been called. With AsyncVaakini, use two tasks:
async with client.stream(voice="Monika") as stream:
    await stream.send_text(first_token)
    sender = asyncio.create_task(send_rest_and_flush(stream))
    async for event in stream:
        ...
  • Vaakini closes a connection that sends nothing for 30 minutes, and when one of its servers restarts. A closed connection raises APIConnectionError: open a new one.

Custom voices

Your org's own voices, each cloned from one reference recording. They are off until Vaakini enables them for your org: write to hello@vaakini.com.

voice = client.custom_voices.create(
    name="Priya (support)",
    audio="priya.wav",  # a path, bytes or an open binary file: WAV, FLAC or Ogg, 0.5 to 30 seconds
    transcript="नमस्ते, मैं प्रिया बोल रही हूँ।",
    language="hi",
)
client.speech.create(input="आपका स्वागत है।", voice=voice.id)

client.custom_voices.list()  # .enabled, .limit, .voices
client.custom_voices.get(voice.id)
client.custom_voices.update(voice.id, name="Priya", gender="female")
client.custom_voices.replace_recording(voice.id, audio="priya2.wav", transcript="…", language="hi")
client.custom_voices.delete(voice.id)

Errors

Every error is a vaakini.VaakiniError.

Error code
BadRequestError bad_request the request is invalid; the message names the field
AuthenticationError unauthorized the API key is missing or invalid
InsufficientCreditsError insufficient_credits the org is out of credit
NotFoundError not_found no such custom voice in your org
CustomVoicesNotEnabledError custom_voices_not_enabled custom voices aren't enabled for your org
CustomVoiceLimitError custom_voice_limit your org holds as many custom voices as it can
RateLimitError rate_limited the model is at capacity; try again
UnavailableError unavailable the model is unavailable; try again
ModelTimeoutError timeout the model sent no audio in time; try again
InternalServerError internal the request failed on Vaakini's side; try again
APIConnectionError the API could not be reached, or the connection ended early
APITimeoutError the API did not answer within the client's timeout

The first ten are APIErrors, with code, message, status_code (None on a stream() connection) and retryable. If speech.stream() raises APIConnectionError in the middle of the audio, the take failed: treat the request as failed.

Client options

Vaakini(api_key=None, base_url="https://api.vaakini.com", timeout=60.0): timeout is the seconds to wait for a connection, and for each piece of a response. Close a client with client.close(), or use it in a with statement.

License

Apache-2.0.

Metadata

Release files for vaakini 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vaakini 0.1.0
File Size Uploaded Provenance Actions
vaakini-0.1.0.tar.gz 19.7 kB Without provenance Details for vaakini-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vaakini 0.1.0
File Interpreter ABI Platform Actions
vaakini-0.1.0-py3-none-any.whl Python 3 none any Details for vaakini-0.1.0-py3-none-any.whl

Total release size: 45.1 kB

Release files / vaakini-0.1.0.tar.gz

Download URL vaakini-0.1.0.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6cf9627d39b62d21a314ab1c7ef481d130f7731c6423c8f5ce5fa8b23587124c
BLAKE2b-256 checksum
How to use checksums
e10955feeada285b6c0b5cd1f11560033d8d0a30a0bd32ae249783cc044e0f2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / vaakini-0.1.0-py3-none-any.whl

Download URL vaakini-0.1.0-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4944002f5757d9b11e0a6fc436889d2fe1e32e2033bf10d8bdf2e67ba1f5f43f
BLAKE2b-256 checksum
How to use checksums
978d6f5cf3621eff3d38f9b0b64d0fad8f60cb9a76dc4927829b526ed3d98a6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for vaakini 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page