Skip to content

TTSSession

Sub classes

Name Children Inherits
EdgeTTSSession
anyvoice.providers.edge
TTS session using Microsoft Edge's TTS service.
    OpenAITTSSession
    anyvoice.providers.openai
    TTS session using OpenAI's streaming API.

      Base classes

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

      ⋔ Inheritance diagram

      graph TD
        2396137972["base.TTSSession"]
        925645236["abc.ABC"]
        2751680898["builtins.object"]
        925645236 --> 2396137972
        2751680898 --> 925645236

      🛈 DocStrings

      Bases: ABC

      Abstract base class for TTS synthesis sessions.

      A session represents a single synthesis context with specific configuration (voice, speed, etc.). Sessions are lightweight and created by providers.

      Usage

      session = provider.session(voice="nova") async for chunk in session.synthesize("Hello world"): await sink.write(chunk)

      Source code in src/anyvoice/base.py
      class TTSSession(ABC):
          """Abstract base class for TTS synthesis sessions.
      
          A session represents a single synthesis context with specific
          configuration (voice, speed, etc.). Sessions are lightweight
          and created by providers.
      
          Usage:
              session = provider.session(voice="nova")
              async for chunk in session.synthesize("Hello world"):
                  await sink.write(chunk)
          """
      
          async def __aenter__(self) -> Self:
              """Enter the session context."""
              return self
      
          async def __aexit__(  # noqa: B027
              self,
              exc_type: type[BaseException] | None,
              exc_val: BaseException | None,
              exc_tb: TracebackType | None,
          ) -> None:
              """Exit the session context, cleanup resources."""
      
          @abstractmethod
          def synthesize(self, text: str) -> AsyncIterator[bytes]:
              """Synthesize text to PCM audio.
      
              Args:
                  text: Text to synthesize.
      
              Yields:
                  PCM audio chunks (16-bit signed, mono).
              """
              ...
      

      __aenter__ async

      __aenter__() -> Self
      

      Enter the session context.

      Source code in src/anyvoice/base.py
      async def __aenter__(self) -> Self:
          """Enter the session context."""
          return self
      

      __aexit__ async

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

      Exit the session context, cleanup resources.

      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 session context, cleanup resources."""
      

      synthesize abstractmethod

      synthesize(text: str) -> AsyncIterator[bytes]
      

      Synthesize text to PCM audio.

      Parameters:

      Name Type Description Default
      text str

      Text to synthesize.

      required

      Yields:

      Type Description
      AsyncIterator[bytes]

      PCM audio chunks (16-bit signed, mono).

      Source code in src/anyvoice/base.py
      @abstractmethod
      def synthesize(self, text: str) -> AsyncIterator[bytes]:
          """Synthesize text to PCM audio.
      
          Args:
              text: Text to synthesize.
      
          Yields:
              PCM audio chunks (16-bit signed, mono).
          """
          ...
      

      :fa-brands-github: Show source on GitHub