Skip to content

Commit fb1cec3

Browse files
committed
Fix console output issue in tts function of synthesizer class
Fix Console Printing Issue in synthesizer Class This update addresses an issue with the tts function in the synthesizer class where console output, including the array of split sentences, processing time, and real-time factor, was being printed during execution. This was causing unwanted console output when the synthesizer function is run in a thread. Changes Made: Added criteria SuppresPrintStatements type boolen to suppress console output generated by the tts function. Ensured that print statements are only triggered when explicitly required, preventing cluttered console output during threaded execution. This modification improves the usability of the synthesizer class when integrated into threaded applications and enhances the overall user experience by minimizing unnecessary console output.
1 parent dbf1a08 commit fb1cec3

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

TTS/api.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def models(self):
8888

8989
@property
9090
def is_multi_speaker(self):
91-
if hasattr(self.synthesizer.tts_model, "speaker_manager") and self.synthesizer.tts_model.speaker_manager:
91+
if hasattr(self.synthesizer.tts_model, "speaker_Smanager") and self.synthesizer.tts_model.speaker_manager:
9292
return self.synthesizer.tts_model.speaker_manager.num_speakers > 1
9393
return False
9494

@@ -243,6 +243,7 @@ def tts(
243243
emotion: str = None,
244244
speed: float = None,
245245
split_sentences: bool = True,
246+
SuppresPrintStatements: bool = False,
246247
**kwargs,
247248
):
248249
"""Convert text to speech.
@@ -267,6 +268,9 @@ def tts(
267268
Split text into sentences, synthesize them separately and concatenate the file audio.
268269
Setting it False uses more VRAM and possibly hit model specific text length or VRAM limits. Only
269270
applicable to the 🐸TTS models. Defaults to True.
271+
SuppresPrintStatements (bool, optional):
272+
Suppress All the Print statements so that when runnging the function in thread the print statement will not apears in the terminal.
273+
Setting it to True will suppress the print statements
270274
kwargs (dict, optional):
271275
Additional arguments for the model.
272276
"""
@@ -283,6 +287,7 @@ def tts(
283287
style_text=None,
284288
reference_speaker_name=None,
285289
split_sentences=split_sentences,
290+
SuppresPrintStatements=SuppresPrintStatements,
286291
**kwargs,
287292
)
288293
return wav

TTS/utils/synthesizer.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def tts(
265265
reference_wav=None,
266266
reference_speaker_name=None,
267267
split_sentences: bool = True,
268+
SuppresPrintStatements: bool= False,
268269
**kwargs,
269270
) -> List[int]:
270271
"""🐸 TTS magic. Run all the models and generate speech.
@@ -279,6 +280,7 @@ def tts(
279280
reference_wav ([type], optional): reference waveform for voice conversion. Defaults to None.
280281
reference_speaker_name ([type], optional): speaker id of reference waveform. Defaults to None.
281282
split_sentences (bool, optional): split the input text into sentences. Defaults to True.
283+
SuppresPrintStatements (bool, optional): Suppress the Print statements.
282284
**kwargs: additional arguments to pass to the TTS model.
283285
Returns:
284286
List[int]: [description]
@@ -294,9 +296,11 @@ def tts(
294296
if text:
295297
sens = [text]
296298
if split_sentences:
297-
print(" > Text splitted to sentences.")
299+
if not SuppresPrintStatements:
300+
print(" > Text splitted to sentences.")
298301
sens = self.split_into_sentences(text)
299-
print(sens)
302+
if not SuppresPrintStatements:
303+
print(sens)
300304

301305
# handle multi-speaker
302306
if "voice_dir" in kwargs:
@@ -420,7 +424,8 @@ def tts(
420424
self.vocoder_config["audio"]["sample_rate"] / self.tts_model.ap.sample_rate,
421425
]
422426
if scale_factor[1] != 1:
423-
print(" > interpolating tts model output.")
427+
if not SuppresPrintStatements:
428+
print(" > interpolating tts model output.")
424429
vocoder_input = interpolate_vocoder_input(scale_factor, vocoder_input)
425430
else:
426431
vocoder_input = torch.tensor(vocoder_input).unsqueeze(0) # pylint: disable=not-callable
@@ -484,7 +489,8 @@ def tts(
484489
self.vocoder_config["audio"]["sample_rate"] / self.tts_model.ap.sample_rate,
485490
]
486491
if scale_factor[1] != 1:
487-
print(" > interpolating tts model output.")
492+
if not SuppresPrintStatements:
493+
print(" > interpolating tts model output.")
488494
vocoder_input = interpolate_vocoder_input(scale_factor, vocoder_input)
489495
else:
490496
vocoder_input = torch.tensor(vocoder_input).unsqueeze(0) # pylint: disable=not-callable
@@ -500,6 +506,7 @@ def tts(
500506
# compute stats
501507
process_time = time.time() - start_time
502508
audio_time = len(wavs) / self.tts_config.audio["sample_rate"]
503-
print(f" > Processing time: {process_time}")
504-
print(f" > Real-time factor: {process_time / audio_time}")
509+
if not SuppresPrintStatements:
510+
print(f" > Processing time: {process_time}")
511+
print(f" > Real-time factor: {process_time / audio_time}")
505512
return wavs

0 commit comments

Comments
 (0)