@@ -101,6 +101,9 @@ def __init__(
101101 silence_time_s : float = 2.0 ,
102102 # if True, we will pause processing frames while we are receiving audio
103103 pause_frame_processing : bool = False ,
104+ # if True, append a trailing space to text before sending to TTS
105+ # (helps prevent some TTS services from vocalizing trailing punctuation)
106+ append_trailing_space : bool = False ,
104107 # TTS output sample rate
105108 sample_rate : Optional [int ] = None ,
106109 # Text aggregator to aggregate incoming tokens and decide when to push to the TTS.
@@ -132,6 +135,8 @@ def __init__(
132135 push_silence_after_stop: Whether to push silence audio after TTSStoppedFrame.
133136 silence_time_s: Duration of silence to push when push_silence_after_stop is True.
134137 pause_frame_processing: Whether to pause frame processing during audio generation.
138+ append_trailing_space: Whether to append a trailing space to text before sending to TTS.
139+ This helps prevent some TTS services from vocalizing trailing punctuation (e.g., "dot").
135140 sample_rate: Output sample rate for generated audio.
136141 text_aggregator: Custom text aggregator for processing incoming text.
137142
@@ -161,6 +166,7 @@ def __init__(
161166 self ._push_silence_after_stop : bool = push_silence_after_stop
162167 self ._silence_time_s : float = silence_time_s
163168 self ._pause_frame_processing : bool = pause_frame_processing
169+ self ._append_trailing_space : bool = append_trailing_space
164170 self ._init_sample_rate = sample_rate
165171 self ._sample_rate = 0
166172 self ._voice_id : str = ""
@@ -273,6 +279,19 @@ def language_to_service_language(self, language: Language) -> Optional[str]:
273279 """
274280 return Language (language )
275281
282+ def _prepare_text_for_tts (self , text : str ) -> str :
283+ """Prepare text for TTS by applying any transformations required by the TTS service.
284+
285+ Args:
286+ text: The text to prepare.
287+
288+ Returns:
289+ The prepared text with transformations applied.
290+ """
291+ if self ._append_trailing_space and not text .endswith (" " ):
292+ return text + " "
293+ return text
294+
276295 async def update_setting (self , key : str , value : Any ):
277296 """Update a service-specific setting.
278297
@@ -603,7 +622,10 @@ async def _push_tts_frames(
603622 for aggregation_type , transform in self ._text_transforms :
604623 if aggregation_type == type or aggregation_type == "*" :
605624 transformed_text = await transform (transformed_text , type )
606- await self .process_generator (self .run_tts (transformed_text ))
625+
626+ # Apply any final text preparation (e.g., trailing space)
627+ prepared_text = self ._prepare_text_for_tts (transformed_text )
628+ await self .process_generator (self .run_tts (prepared_text ))
607629
608630 await self .stop_processing_metrics ()
609631
0 commit comments