Add support for Ozzy's mel multiplier constant

This commit is contained in:
Brandon Thomas
2023-03-11 01:18:19 -05:00
parent 51199e8a6c
commit b5355de94e
3 changed files with 31 additions and 5 deletions
+23 -1
View File
@@ -38,6 +38,11 @@ from text.pipeline_components.phonetization.english_phonetization import English
from logger import LOGGER
# Multiplying the mel output postnet by a constant factor scales it before vocoding,
# often resulting in "better" (less tinny) sound.
# This value was determined by Ozzy via experimentation.
DEFAULT_MEL_MULTIPLIER = 1.4
def print_gpu_info():
print('========================================')
print('Python interpreter', sys.executable)
@@ -211,7 +216,7 @@ def generate_metadata_file(output_audio_filename, output_metadata_filename):
json.dump(metadata, json_file)
class TacotronWaveglowPipeline:
class FakeYouTt2Pipeline:
def __init__(self):
# Cache of "path" => loaded model
@@ -281,6 +286,8 @@ class TacotronWaveglowPipeline:
def infer(self, args):
assert('synthesizer_checkpoint_path' in args)
assert('vocoder_type' in args)
assert('use_default_mel_multiply_factor' in args)
assert('maybe_custom_mel_multiply_factor' in args)
assert('text_pipeline_type' in args)
assert('raw_text' in args)
assert('output_audio_filename' in args)
@@ -300,6 +307,20 @@ class TacotronWaveglowPipeline:
with torch.no_grad():
mel_outputs, mel_outputs_postnet, _, alignments = tacotron.inference(sequence)
# Multiply the mel outputs for "better" sound.
use_multiplier = False
mel_multiplier = DEFAULT_MEL_MULTIPLIER
if args['maybe_custom_mel_multiply_factor']:
use_multiplier = True
mel_multiplier = float(args['maybe_custom_mel_multiply_factor'])
elif args['use_default_mel_multiply_factor']:
use_multiplier = True
if use_multiplier:
LOGGER.info(f'Scaling audio by {mel_multiplier}')
mel_outputs_postnet = mel_outputs_postnet * mel_multiplier
if args['vocoder_type'] == 'hifigan-superres':
self.vocode_hifigan_superres(args, mel_outputs_postnet)
@@ -362,6 +383,7 @@ class TacotronWaveglowPipeline:
self.hifigan_super_resolution_h.fmin,
self.hifigan_super_resolution_h.fmax,
)
y_g_hat2 = self.hifigan_super_resolution(new_mel)
audio2 = y_g_hat2.squeeze()
audio2 = audio2 * MAX_WAV_VALUE
+6 -2
View File
@@ -24,7 +24,7 @@ from falcon_multipart.middleware import MultipartMiddleware
#from preprocess import *
from wsgiref import simple_server
from vocodes_common import TacotronWaveglowPipeline
from vocodes_common import FakeYouTt2Pipeline
from vocodes_common import load_hifigan_model
from vocodes_common import load_tacotron_model
from vocodes_common import load_waveglow_model
@@ -200,7 +200,7 @@ INDEX_HTML = '''
#tacotron = load_tacotron_model('/home/bt/models/tacotron2/tacotron2_uberduck_Noire.pt')
#waveglow = load_waveglow_model('/home/bt/models/waveglow/waveglow_256channels_universal_v5.pt')
pipeline = TacotronWaveglowPipeline()
pipeline = FakeYouTt2Pipeline()
class IndexHandler():
def on_get(self, request, response):
@@ -227,6 +227,8 @@ class ApiHandler():
# Request parameters
synthesizer_checkpoint_path = raw_data.get('synthesizer_checkpoint_path')
text_pipeline_type = raw_data.get('text_pipeline_type')
use_default_mel_multiply_factor = raw_data.get('use_default_mel_multiply_factor')
maybe_custom_mel_multiply_factor = raw_data.get('maybe_custom_mel_multiply_factor')
vocoder_type = raw_data.get('vocoder_type')
waveglow_vocoder_checkpoint_path = raw_data.get('waveglow_vocoder_checkpoint_path')
hifigan_vocoder_checkpoint_path = raw_data.get('hifigan_vocoder_checkpoint_path')
@@ -259,6 +261,8 @@ class ApiHandler():
inference_args = {
'raw_text': inference_text,
'use_default_mel_multiply_factor': use_default_mel_multiply_factor,
'maybe_custom_mel_multiply_factor': maybe_custom_mel_multiply_factor,
'synthesizer_checkpoint_path': synthesizer_checkpoint_path,
'vocoder_type': vocoder_type,
'text_pipeline_type': text_pipeline_type,
+2 -2
View File
@@ -24,7 +24,7 @@ from falcon_multipart.middleware import MultipartMiddleware
#from preprocess import *
from wsgiref import simple_server
from vocodes_common_talknet import TacotronWaveglowPipeline
from vocodes_common_talknet import FakeYouTt2Pipeline
from vocodes_common_talknet import print_gpu_info
from vocodes_common_talknet import load_tacotron_model
from vocodes_common_talknet import load_waveglow_model
@@ -197,7 +197,7 @@ INDEX_HTML = '''
#tacotron = load_tacotron_model('/home/bt/models/tacotron2/tacotron2_uberduck_Noire.pt')
#waveglow = load_waveglow_model('/home/bt/models/waveglow/waveglow_256channels_universal_v5.pt')
pipeline = TacotronWaveglowPipeline()
pipeline = FakeYouTt2Pipeline()
class IndexHandler():
def on_get(self, request, response):