Skip to main content

AnyVoice

PyPI License Package status Monthly downloads Distribution format Wheel availability Python version Implementation Releases Github Contributors Github Discussions Github Forks Github Issues Github Issues Github Watchers Github Stars Github Repository size Github last commit Github release date Github language count Github commits this month Package status PyUp

Read the documentation!

AnyVoice is a small async library that puts streaming Text-to-Speech providers behind one interface. Feed it text as it arrives (for example token by token from an LLM), and it buffers the text into sentences, synthesizes them and sends raw PCM audio to a pluggable sink: your speakers, a WAV file or your own callback.

Features

  • Multiple TTS providers: OpenAI TTS and Microsoft Edge TTS (free, no API key)
  • Pluggable audio sinks: speaker playback, WAV file output, custom callbacks
  • Streaming input: incremental feed() with sentence-boundary buffering
  • Synchronization modes: choose whether feed() waits for audio or synthesis runs in the background
  • Lightweight: no required dependencies; provider libraries are optional extras and imported lazily

Installation

# OpenAI TTS (needs an OpenAI API key)
pip install "anyvoice[openai]"

# Edge TTS (free, no API key)
pip install "anyvoice[tts-edge]"

Speaker playback uses sounddevice, which needs the PortAudio system library.

Quick Start

Basic usage with OpenAI

import asyncio

from anyvoice import OpenAITTSProvider, SoundDeviceSink, TTSStream


async def main():
    provider = OpenAITTSProvider()  # uses OPENAI_API_KEY, or pass api_key="sk-..."
    session = provider.session(voice="nova", speed=1.0)

    async with TTSStream(session, sink=SoundDeviceSink()) as tts:
        await tts.feed("Hello! ")
        await tts.feed("This is streaming TTS. ")
        await tts.feed("Pretty cool, right?")


asyncio.run(main())

Using Edge TTS (free, no API key)

import asyncio

from anyvoice import EdgeTTSProvider, SoundDeviceSink, TTSStream


async def main():
    provider = EdgeTTSProvider()
    session = provider.session(voice="en-GB-SoniaNeural", rate="+10%")

    async with TTSStream(session, sink=SoundDeviceSink()) as tts:
        await tts.feed("Hello from Edge TTS!")


asyncio.run(main())

Streaming from an LLM

Any async iterator of text chunks works:

from collections.abc import AsyncIterator

from anyvoice import OpenAITTSProvider, TTSStream


async def speak(chunks: AsyncIterator[str]):
    session = OpenAITTSProvider().session(voice="nova")

    async with TTSStream(session, mode="sync_run") as tts:  # plays through the speakers
        async for chunk in chunks:
            print(chunk, end="", flush=True)
            await tts.feed(chunk)
    # Audio has finished playing when the context exits

Save to a file

from anyvoice import EdgeTTSProvider, FileSink, TTSStream


async def save_audio():
    session = EdgeTTSProvider().session()

    async with TTSStream(session, sink=FileSink("output.wav")) as tts:
        await tts.feed("This will be saved to a WAV file.")

Custom audio handling

from anyvoice import CallbackSink, OpenAITTSProvider, TTSStream


async def custom_handler():
    chunks: list[bytes] = []

    session = OpenAITTSProvider().session(voice="echo")

    async with TTSStream(session, sink=CallbackSink(chunks.append)) as tts:
        await tts.feed("Process this audio yourself!")

    total_bytes = sum(len(c) for c in chunks)
    print(f"Received {total_bytes} bytes of audio")

Callbacks may be sync or async. Audio is always 16-bit signed mono PCM (24 kHz by default).

Using a session directly

Skip the orchestrator if you just want the audio chunks:

from anyvoice import EdgeTTSProvider


async def synthesize():
    session = EdgeTTSProvider().session()
    async for pcm_chunk in session.synthesize("Hello world."):
        ...

Synchronization Modes

Text is buffered until a sentence terminator (., !, ?, newline) appears after at least min_text_length characters; the remainder is synthesized when the context exits.

Mode Behavior
sync_sentence feed() waits until each sentence has been synthesized and written to the sink
sync_run feed() returns immediately, sentences are synthesized in the background; the context exit waits for all audio (default)
async_queue Like sync_run, but the context exit does not wait for pending audio
async_cancel Currently behaves like async_queue; use await tts.cancel() to drop pending audio
async with TTSStream(session, mode="sync_sentence") as tts:
    await tts.feed("This sentence plays completely.")
    # Audio finished before the next feed()
    await tts.feed("Then this one plays.")

API Overview

Providers

OpenAITTSProvider

provider = OpenAITTSProvider(api_key="...", base_url=None)
session = provider.session(
    model="tts-1",  # or "tts-1-hd"
    voice="alloy",  # alloy, echo, fable, onyx, nova, shimmer
    speed=1.0,  # 0.25 to 4.0
    chunk_size=1024,
)

EdgeTTSProvider

provider = EdgeTTSProvider(default_voice="en-US-AriaNeural", sample_rate=24000)
session = provider.session(
    voice="en-US-AriaNeural",  # list voices with `edge-tts --list-voices`
    rate="+0%",  # e.g., "+25%", "-10%"
    volume="+0%",
    pitch="+0Hz",
)

Sinks

  • SoundDeviceSink(sample_rate=24000, channels=1): play through the speakers
  • FileSink(path, sample_rate=24000, channels=1): save to a WAV file
  • CallbackSink(callback, on_close=None): custom handling

Implement your own by subclassing anyvoice.AudioSink and defining async write(chunk). New providers subclass TTSProvider and TTSSession.

TTSStream

TTSStream(
    session,  # From provider.session()
    sink=SoundDeviceSink(),  # Audio output (default: SoundDeviceSink)
    mode="sync_run",  # Synchronization mode
    min_text_length=20,  # Minimum characters before a sentence is synthesized
    sentence_terminators=None,  # Defaults to {".", "!", "?", "\n"}
)

Methods:

  • await tts.feed(text): add text to the stream
  • await tts.cancel(): drop pending synthesis and buffered text

License

MIT

Metadata

Release files for anyvoice 0.0.3

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

Source distribution (sdist)

Source distribution for anyvoice 0.0.3
File Size Uploaded Provenance Actions
anyvoice-0.0.3.tar.gz 16.8 kB With provenance Details for anyvoice-0.0.3.tar.gz

Built distribution (wheel)

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

Total release size: 32.0 kB

Release files / anyvoice-0.0.3.tar.gz

Download URL anyvoice-0.0.3.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
edc102e11f4274b5d15956bdf9a64ad7d53163137184ac88b51e760aa804cda3
BLAKE2b-256 checksum
How to use checksums
b9ac94dd665322a5bf72dd971d3565f6003e7969059c0c400f5514df65912b4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / anyvoice-0.0.3-py3-none-any.whl

Download URL anyvoice-0.0.3-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0cbe31a9f75aa822744a72bd3e1db42f60ff00d08690ca2ace38e20d99d100f4
BLAKE2b-256 checksum
How to use checksums
11ce87bd3922a0dcedd04ff902ecd65a603a7712f30d43257a0e67f640481ef4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for anyvoice 0.0.3

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for anyvoice-0.0.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

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.

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