Skip to main content

voicesynth

Offline voice synthesis library

Install

pip install voicesynth
pip install torch --index-url https://download.pytorch.org/whl/cpu

PyTorch is not pulled in automatically so you can pick the build you want (CPU, CUDA, ...). pip install voicesynth[torch] installs the default one.

Quick start

from voicesynth import Model, Synthesizer

synthesizer = Synthesizer(Model("v5_6_ru"))
synthesizer.say("В н+едрах т+ундры в+ыдры в г+етрах т+ырят в в+ёдра +ядра к+едров.")

The model is downloaded on first use into ~/.cache/voicesynth (override with model_path= or the VOICESYNTH_HOME environment variable).

Models

from voicesynth import show_available_models, available_models

show_available_models()
show_available_models("tatar")
available_models("russian")
Family Models
Russian v5_6_ru, v5_5_ru, v5_4_ru, v5_3_ru, v5_2_ru, v5_1_ru, v5_ru, v4_ru, v3_1_ru
CIS languages v5_cis_base, v5_cis_base_nostress, v5_cis_ext
Turkic / Caucasian v5_turkic, v5_caucasian
Cyrillic v4_cyrillic
Ukrainian / Uzbek / Tatar / Kalmyk v4_ua, v3_ua, v4_uz, v3_uz, v3_tt, v3_xal
Indic v4_indic, v3_indic, v3_en_indic
English / German / Spanish / French v3_en, v3_de, v3_es, v3_fr

v5_cis_base, v5_cis_ext, v5_turkic and v5_caucasian expect stress marks (к+ошка) in the text; the nostress variant needs them only for Slavic languages. Speakers are prefixed with the language code, for example tat_albina or kaz_abai.

Speakers and speed

model = Model("v3_en", speaker="en_73")
model.set_speaker("en_12")

synthesizer = Synthesizer(model)
synthesizer.say("Hello there", speaker="en_5", prosody_rate=90)
print(synthesizer.speakers)

Saving audio and other outputs

synthesizer.synthesize("Saved for later", path="audio.wav")
synthesizer.say("Saved and played", path="audio.wav")

wav = synthesizer.synthesize_bytes("In memory")
samples = synthesizer.generate("As a numpy array")
synthesizer.synthesize("Into a buffer", io.BytesIO())

say() without a path plays through a temporary file. Pass ssml=True to send your own SSML, sample_rate= (8000, 24000 or 48000) to change quality, and device="cuda" or threads=4 to the Synthesizer constructor.

Long text

Text longer than max_chars (500 by default) is split on sentence and clause boundaries, synthesized piece by piece and joined with pause seconds of silence:

synthesizer = Synthesizer(model, max_chars=300, pause=0.4)
from voicesynth import split_text
split_text(long_text, 300)

Non-blocking playback and asyncio

playback = synthesizer.say("Talking in the background", blocking=False)
playback.is_playing
playback.wait(timeout=2)
playback.stop()

await synthesizer.say_async("Does not block the event loop")
await synthesizer.synthesize_async("hello", "hello.wav")

Audio playback is native: winsound on Windows, afplay on macOS and the first available of paplay, pw-play, aplay, ffplay, mpv, play on Linux.

Speakers

Some catalog entries (Indic, German, Tatar, Kalmyk and a few more) list only the speakers known in advance. After loading a model, synthesizer.speakers holds the real list. Without creating a synthesizer:

Model("v3_de").fetch_speakers()

Model cache

Models are stored in ~/.cache/voicesynth (or $VOICESYNTH_HOME). Every download is checked: the size, the archive CRCs and a SHA-256 checksum saved next to the file, which is re-verified on every Model(...). A damaged file is deleted and downloaded again. Interrupted downloads resume where they stopped.

from voicesynth import cache

cache.download("v3_en")
cache.cached_models()
cache.verify("v3_en")
cache.remove("v3_en")
cache.clear()

Mixed language text

Cyrillic models read Cyrillic and Latin models read Latin letters. When text contains words in the other script, a warning is logged because those words are skipped or mispronounced. Silence it with Synthesizer(model, warn_mixed_language=False).

Command line

voicesynth models
voicesynth models --language russian
voicesynth speakers v3_en
voicesynth speakers v3_de --load
voicesynth say "Hello world" -m v3_en -s en_73
voicesynth say "Saved only" -m v3_en -o hello.wav --no-play
echo "Piped text" | voicesynth say -m v3_en
voicesynth cache list
voicesynth cache download v3_en v5_6_ru
voicesynth cache verify
voicesynth cache remove v3_en
voicesynth cache clear

Logging

from voicesynth import disable_logging, enable_logging

disable_logging()

Errors

All exceptions derive from voicesynth.exceptions.VoiceSynthError: IncorrectModel, IncorrectSpeaker, ModelDownloadError, SynthesisError, AudioPlayingError, ModelIntegrityError, PackageError and others.

Tests

pip install voicesynth[dev]
pytest
mypy

Metadata

Release files for voicesynth 0.5.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 voicesynth 0.5.0
File Size Uploaded Provenance
voicesynth-0.5.0.tar.gz 30.8 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 55.1 kB

Release files / voicesynth-0.5.0.tar.gz

Download URL voicesynth-0.5.0.tar.gz
Size 30.8 kB
Tags Source
SHA-256 checksum
How to use checksums
848bfa56a0a74bfbeced3b22e0bc5a04fc045176433f46cd589672880f253ef2
BLAKE2b-256 checksum
How to use checksums
14a34944e1569b9452d98f90a32d8107d498aa4d22edd03ac8ead3aaa53ebb65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / voicesynth-0.5.0-py3-none-any.whl

Download URL voicesynth-0.5.0-py3-none-any.whl
Size 24.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7db43867a42ace388533aac24824eceb97f21625d9de8a91e48dcc35ba2e1381
BLAKE2b-256 checksum
How to use checksums
d892af922534f7bcbe3c4a4be1b2a46e9b6583c71fcc1b033a856c2a071d897b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for voicesynth 0.5.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.5.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