Newer
Older
cortex-hub / ai-hub / app / core / services / tts.py
from typing import AsyncGenerator
from app.core.providers.base import TTSProvider

class TTSService:
    """
    Service class for generating speech from text using a TTS provider.
    """
    def __init__(self, tts_provider: TTSProvider):
        """
        Initializes the TTSService with a concrete TTS provider.
        """
        self.tts_provider = tts_provider

    async def create_speech_stream(self, text: str) -> AsyncGenerator[bytes, None]:
        """
        Generates a stream of audio bytes from the given text using the configured
        TTS provider.

        Args:
            text: The text to be converted to speech.

        Returns:
            An async generator that yields chunks of audio bytes.
        """
        return self.tts_provider.generate_speech(text)