Skip to content

Commit

Permalink
Fix console output issue in tts function of synthesizer class
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dilshad24 committed Aug 16, 2024
1 parent dbf1a08 commit fb1cec3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
7 changes: 6 additions & 1 deletion TTS/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def models(self):

@property
def is_multi_speaker(self):
if hasattr(self.synthesizer.tts_model, "speaker_manager") and self.synthesizer.tts_model.speaker_manager:
if hasattr(self.synthesizer.tts_model, "speaker_Smanager") and self.synthesizer.tts_model.speaker_manager:
return self.synthesizer.tts_model.speaker_manager.num_speakers > 1
return False

Expand Down Expand Up @@ -243,6 +243,7 @@ def tts(
emotion: str = None,
speed: float = None,
split_sentences: bool = True,
SuppresPrintStatements: bool = False,
**kwargs,
):
"""Convert text to speech.
Expand All @@ -267,6 +268,9 @@ def tts(
Split text into sentences, synthesize them separately and concatenate the file audio.
Setting it False uses more VRAM and possibly hit model specific text length or VRAM limits. Only
applicable to the 🐸TTS models. Defaults to True.
SuppresPrintStatements (bool, optional):
Suppress All the Print statements so that when runnging the function in thread the print statement will not apears in the terminal.
Setting it to True will suppress the print statements
kwargs (dict, optional):
Additional arguments for the model.
"""
Expand All @@ -283,6 +287,7 @@ def tts(
style_text=None,
reference_speaker_name=None,
split_sentences=split_sentences,
SuppresPrintStatements=SuppresPrintStatements,
**kwargs,
)
return wav
Expand Down
19 changes: 13 additions & 6 deletions TTS/utils/synthesizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def tts(
reference_wav=None,
reference_speaker_name=None,
split_sentences: bool = True,
SuppresPrintStatements: bool= False,
**kwargs,
) -> List[int]:
"""🐸 TTS magic. Run all the models and generate speech.
Expand All @@ -279,6 +280,7 @@ def tts(
reference_wav ([type], optional): reference waveform for voice conversion. Defaults to None.
reference_speaker_name ([type], optional): speaker id of reference waveform. Defaults to None.
split_sentences (bool, optional): split the input text into sentences. Defaults to True.
SuppresPrintStatements (bool, optional): Suppress the Print statements.
**kwargs: additional arguments to pass to the TTS model.
Returns:
List[int]: [description]
Expand All @@ -294,9 +296,11 @@ def tts(
if text:
sens = [text]
if split_sentences:
print(" > Text splitted to sentences.")
if not SuppresPrintStatements:
print(" > Text splitted to sentences.")
sens = self.split_into_sentences(text)
print(sens)
if not SuppresPrintStatements:
print(sens)

# handle multi-speaker
if "voice_dir" in kwargs:
Expand Down Expand Up @@ -420,7 +424,8 @@ def tts(
self.vocoder_config["audio"]["sample_rate"] / self.tts_model.ap.sample_rate,
]
if scale_factor[1] != 1:
print(" > interpolating tts model output.")
if not SuppresPrintStatements:
print(" > interpolating tts model output.")
vocoder_input = interpolate_vocoder_input(scale_factor, vocoder_input)
else:
vocoder_input = torch.tensor(vocoder_input).unsqueeze(0) # pylint: disable=not-callable
Expand Down Expand Up @@ -484,7 +489,8 @@ def tts(
self.vocoder_config["audio"]["sample_rate"] / self.tts_model.ap.sample_rate,
]
if scale_factor[1] != 1:
print(" > interpolating tts model output.")
if not SuppresPrintStatements:
print(" > interpolating tts model output.")
vocoder_input = interpolate_vocoder_input(scale_factor, vocoder_input)
else:
vocoder_input = torch.tensor(vocoder_input).unsqueeze(0) # pylint: disable=not-callable
Expand All @@ -500,6 +506,7 @@ def tts(
# compute stats
process_time = time.time() - start_time
audio_time = len(wavs) / self.tts_config.audio["sample_rate"]
print(f" > Processing time: {process_time}")
print(f" > Real-time factor: {process_time / audio_time}")
if not SuppresPrintStatements:
print(f" > Processing time: {process_time}")
print(f" > Real-time factor: {process_time / audio_time}")
return wavs

0 comments on commit fb1cec3

Please sign in to comment.