Skip to content

fix: fix_loudness to -12 dB #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
@@ -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.fix_loudness(audio,self.hps.data.sampling_rate))
torch.cuda.empty_cache()
audio = self.audio_numpy_concat(audio_list, sr=self.hps.data.sampling_rate, speed=speed)

11 changes: 11 additions & 0 deletions melo/utils.py
Original file line number Diff line number Diff line change
@@ -13,11 +13,22 @@
from melo.text.cleaner import clean_text
from melo import commons

import pyloudnorm as pyln

MATPLOTLIB_FLAG = False

logger = logging.getLogger(__name__)

def fix_loudness(input, rate):
# 峰值归一化至 -1 dB
peak_normalized_audio = pyln.normalize.peak(input, -1.0)

# 测量响度
meter = pyln.Meter(rate)
loudness = meter.integrated_loudness(peak_normalized_audio)

# 响度归一化至 -12 dB LUFS
return pyln.normalize.loudness(peak_normalized_audio, loudness, -12.0)

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)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -27,3 +27,4 @@ langid==1.1.6
tqdm
tensorboard==2.16.2
loguru==0.7.2
pyloudnorm