Skip to content

base_text_to_speech_driver

BaseTextToSpeechDriver

Bases: SerializableMixin, ExponentialBackoffMixin, ABC

Source code in griptape/drivers/text_to_speech/base_text_to_speech_driver.py
@define
class BaseTextToSpeechDriver(SerializableMixin, ExponentialBackoffMixin, ABC):
    model: str = field(kw_only=True, metadata={"serializable": True})

    def before_run(self, prompts: list[str]) -> None:
        EventBus.publish_event(StartTextToSpeechEvent(prompts=prompts))

    def after_run(self) -> None:
        EventBus.publish_event(FinishTextToSpeechEvent())

    def run_text_to_audio(self, prompts: list[str]) -> AudioArtifact:
        for attempt in self.retrying():
            with attempt:
                self.before_run(prompts)
                result = self.try_text_to_audio(prompts)
                self.after_run()

                return result

        else:
            raise Exception("Failed to run text to audio generation")

    @abstractmethod
    def try_text_to_audio(self, prompts: list[str]) -> AudioArtifact: ...

model: str = field(kw_only=True, metadata={'serializable': True}) class-attribute instance-attribute

after_run()

Source code in griptape/drivers/text_to_speech/base_text_to_speech_driver.py
def after_run(self) -> None:
    EventBus.publish_event(FinishTextToSpeechEvent())

before_run(prompts)

Source code in griptape/drivers/text_to_speech/base_text_to_speech_driver.py
def before_run(self, prompts: list[str]) -> None:
    EventBus.publish_event(StartTextToSpeechEvent(prompts=prompts))

run_text_to_audio(prompts)

Source code in griptape/drivers/text_to_speech/base_text_to_speech_driver.py
def run_text_to_audio(self, prompts: list[str]) -> AudioArtifact:
    for attempt in self.retrying():
        with attempt:
            self.before_run(prompts)
            result = self.try_text_to_audio(prompts)
            self.after_run()

            return result

    else:
        raise Exception("Failed to run text to audio generation")

try_text_to_audio(prompts) abstractmethod

Source code in griptape/drivers/text_to_speech/base_text_to_speech_driver.py
@abstractmethod
def try_text_to_audio(self, prompts: list[str]) -> AudioArtifact: ...