agents.components.texttospeech
#
Module Contents#
Classes#
This component takes in text input and outputs an audio representation of the text using TTS models (e.g. SpeechT5). The generated audio can be played using any audio playback device available on the agent. |
API#
- class agents.components.texttospeech.TextToSpeech(*, inputs: List[agents.ros.Topic], outputs: Optional[List[agents.ros.Topic]] = None, model_client: agents.clients.model_base.ModelClient, config: Optional[agents.config.TextToSpeechConfig] = None, trigger: Union[agents.ros.Topic, List[agents.ros.Topic]], component_name: str, **kwargs)#
Bases:
agents.components.model_component.ModelComponent
This component takes in text input and outputs an audio representation of the text using TTS models (e.g. SpeechT5). The generated audio can be played using any audio playback device available on the agent.
- Parameters:
inputs (list[Topic]) β The input topics for the TTS. This should be a list of Topic objects, limited to String type.
outputs (list[Topic]) β Optional output topics for the TTS. This should be a list of Topic objects, Audio type is handled automatically.
model_client (ModelClient) β The model client for the TTS. This should be an instance of ModelClient.
config (Optional[TextToSpeechConfig]) β The configuration for the TTS. This should be an instance of TextToSpeechConfig. If not provided, it defaults to TextToSpeechConfig()
trigger (Union[Topic, list[Topic]) β The trigger value or topic for the TTS. This can be a single Topic object or a list of Topic objects.
component_name (str) β The name of the TTS component. This should be a string.
Example usage:
text_topic = Topic(name="text", msg_type="String") audio_topic = Topic(name="audio", msg_type="Audio") config = TextToSpeechConfig(play_on_device=True) model_client = ModelClient(model=SpeechT5(name="speecht5")) tts_component = TextToSpeech( inputs=[text_topic], outputs=[audio_topic], model_client=model_client, config=config, component_name='tts_component' )
- custom_on_configure()#
Create model client if provided and initialize model.
- custom_on_deactivate()#
Destroy model client if it exists
- stop_playback(wait_for_thread: bool = True)#
Stops the playback thread and clears any pending audio. Can be used to interrupt the audio playback through an event.
- say(text: str)#
Say the input text.
This method converts the input text to speech and plays the speech on device if play_on_device is set to True and publishes to Audio topics if any publishers have been provided to the component. Any current playback is stopped.
The method can be invoked as an action consequence of an event. For example, the robot can say βI am low on batteryβ when a low battery event gets triggered.
- property warmup: bool#
Enable warmup of the model.
- custom_on_activate()#
Custom configuration for creating triggers.
- create_all_subscribers()#
Override to handle trigger topics and fixed inputs. Called by parent BaseComponent
- activate_all_triggers() None #
Activates component triggers by attaching execution step to callbacks
- destroy_all_subscribers() None #
Destroys all node subscribers
- trigger(trigger: Union[agents.ros.Topic, List[agents.ros.Topic], float]) None #
Set component trigger
- validate_topics(topics: Sequence[Union[agents.ros.Topic, agents.ros.FixedInput]], allowed_topic_types: Optional[Dict[str, List[Union[Type[agents.ros.SupportedType], List[Type[agents.ros.SupportedType]]]]]] = None, topics_direction: str = 'Topics')#
Verify component specific inputs or outputs using allowed topics if provided