Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion melo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def tts_to_file(self, text, speaker_id, output_path=None, sdp_ratio=0.2, noise_s
)[0][0, 0].data.cpu().float().numpy()
del x_tst, tones, lang_ids, bert, ja_bert, x_tst_lengths, speakers
#
audio_list.append(audio)
audio_list.append(utils.normalize_loudness(audio))
torch.cuda.empty_cache()
audio = self.audio_numpy_concat(audio_list, sr=self.hps.data.sampling_rate, speed=speed)

Expand Down
20 changes: 19 additions & 1 deletion melo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,25 @@

logger = logging.getLogger(__name__)


def normalize_loudness(audio):
max_val = np.max(np.abs(audio))
if max_val == 0:
return audio
scale_factor = (1 - 1e-6) / max_val
normalized_audio = audio * scale_factor

if False:
print(f'--- normalize ---')
print(f"Before normalization:")
print(f" Min value: {np.min(audio)}")
print(f" Max value: {np.max(audio)}")
print(f" Length: {len(audio)}")
print(f"After normalization:")
print(f" Min value: {np.min(normalized_audio)}")
print(f" Max value: {np.max(normalized_audio)}")
print(f" Length: {len(normalized_audio)}")

return normalized_audio

def get_text_for_tts_infer(text, language_str, hps, device, symbol_to_id=None):
norm_text, phone, tone, word2ph = clean_text(text, language_str)
Expand Down