Skip to content

AudioSink

Sub classes

Name Children Inherits
SoundDeviceSink
anyvoice.sinks
Audio sink that plays PCM audio through the system speakers.
    FileSink
    anyvoice.sinks
    Audio sink that writes PCM audio to a WAV file.
      CallbackSink
      anyvoice.sinks
      Audio sink that passes audio chunks to a user-provided callback.

        Base classes

        Name Children Inherits
        ABC
        abc
        Helper class that provides a standard way to create an ABC using

        ⋔ Inheritance diagram

        graph TD
          3407701203["base.AudioSink"]
          925645236["abc.ABC"]
          2751680898["builtins.object"]
          925645236 --> 3407701203
          2751680898 --> 925645236

        🛈 DocStrings

        Bases: ABC

        Abstract base class for audio output backends.

        Audio sinks receive PCM audio chunks and handle output (playback, file writing, etc.).

        Usage as context manager

        async with SoundDeviceSink() as sink: await sink.write(audio_chunk)

        Source code in src/anyvoice/base.py
        class AudioSink(ABC):
            """Abstract base class for audio output backends.
        
            Audio sinks receive PCM audio chunks and handle output
            (playback, file writing, etc.).
        
            Usage as context manager:
                async with SoundDeviceSink() as sink:
                    await sink.write(audio_chunk)
            """
        
            async def __aenter__(self) -> Self:
                """Enter the sink context, prepare for receiving audio."""
                return self
        
            async def __aexit__(  # noqa: B027
                self,
                exc_type: type[BaseException] | None,
                exc_val: BaseException | None,
                exc_tb: TracebackType | None,
            ) -> None:
                """Exit the sink context, finalize and cleanup."""
        
            @abstractmethod
            async def write(self, chunk: bytes) -> None:
                """Write a PCM audio chunk to the sink.
        
                Args:
                    chunk: Raw PCM audio data (16-bit signed, mono).
                """
                ...
        

        __aenter__ async

        __aenter__() -> Self
        

        Enter the sink context, prepare for receiving audio.

        Source code in src/anyvoice/base.py
        async def __aenter__(self) -> Self:
            """Enter the sink context, prepare for receiving audio."""
            return self
        

        __aexit__ async

        __aexit__(
            exc_type: type[BaseException] | None,
            exc_val: BaseException | None,
            exc_tb: TracebackType | None,
        ) -> None
        

        Exit the sink context, finalize and cleanup.

        Source code in src/anyvoice/base.py
        async def __aexit__(  # noqa: B027
            self,
            exc_type: type[BaseException] | None,
            exc_val: BaseException | None,
            exc_tb: TracebackType | None,
        ) -> None:
            """Exit the sink context, finalize and cleanup."""
        

        write abstractmethod async

        write(chunk: bytes) -> None
        

        Write a PCM audio chunk to the sink.

        Parameters:

        Name Type Description Default
        chunk bytes

        Raw PCM audio data (16-bit signed, mono).

        required
        Source code in src/anyvoice/base.py
        @abstractmethod
        async def write(self, chunk: bytes) -> None:
            """Write a PCM audio chunk to the sink.
        
            Args:
                chunk: Raw PCM audio data (16-bit signed, mono).
            """
            ...
        

        :fa-brands-github: Show source on GitHub