sinks
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| CallbackSink anyvoice.sinks Audio sink that passes audio chunks to a user-provided callback. |
||
| FileSink anyvoice.sinks Audio sink that writes PCM audio to a WAV file. |
||
| SoundDeviceSink anyvoice.sinks Audio sink that plays PCM audio through the system speakers. |
🛈 DocStrings¶
Audio sink implementations for TTS output.
CallbackSink
¶
Bases: AudioSink
Audio sink that passes audio chunks to a user-provided callback.
Useful for custom audio processing, streaming, or integration with other systems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[bytes], Awaitable[None]] | Callable[[bytes], None]
|
Async or sync callable that receives audio chunks. |
required |
on_close
|
Callable[[], Awaitable[None]] | Callable[[], None] | None
|
Optional callback invoked when sink closes. |
None
|
Source code in src/anyvoice/sinks.py
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Invoke close callback if provided.
Source code in src/anyvoice/sinks.py
write
async
¶
Pass audio chunk to the callback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk
|
bytes
|
PCM audio data. |
required |
FileSink
¶
Bases: AudioSink
Audio sink that writes PCM audio to a WAV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
Path to the output WAV file. |
required |
sample_rate
|
int
|
Audio sample rate in Hz. Defaults to 24000. |
24000
|
channels
|
int
|
Number of audio channels. Defaults to 1 (mono). |
1
|
Source code in src/anyvoice/sinks.py
__aenter__
async
¶
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Write collected audio to WAV file.
Source code in src/anyvoice/sinks.py
write
async
¶
Buffer audio chunk for later writing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk
|
bytes
|
PCM audio data to save. |
required |
SoundDeviceSink
¶
Bases: AudioSink
Audio sink that plays PCM audio through the system speakers.
Uses sounddevice for real-time audio playback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_rate
|
int
|
Audio sample rate in Hz. Defaults to 24000. |
24000
|
channels
|
int
|
Number of audio channels. Defaults to 1 (mono). |
1
|
Source code in src/anyvoice/sinks.py
__aenter__
async
¶
Start the audio output stream.
Source code in src/anyvoice/sinks.py
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Stop and close the audio output stream.
Source code in src/anyvoice/sinks.py
write
async
¶
Write audio chunk to the output stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk
|
bytes
|
PCM audio data to play. |
required |