mirror of
https://github.com/storytold/storyteller-ml.git
synced 2026-10-29 09:18:21 +00:00
New entry point for subprocess/CLI-based inference
This commit is contained in:
@@ -284,16 +284,21 @@ class FakeYouTt2Pipeline:
|
|||||||
len(self.tacotron_model_cache)))
|
len(self.tacotron_model_cache)))
|
||||||
|
|
||||||
def infer(self, args):
|
def infer(self, args):
|
||||||
|
# Model parameters
|
||||||
assert('synthesizer_checkpoint_path' in args)
|
assert('synthesizer_checkpoint_path' in args)
|
||||||
assert('vocoder_type' in args)
|
assert('vocoder_type' in args)
|
||||||
|
assert('text_pipeline_type' in args)
|
||||||
|
# Optional mel scaling before vocodinng
|
||||||
assert('use_default_mel_multiply_factor' in args)
|
assert('use_default_mel_multiply_factor' in args)
|
||||||
assert('maybe_custom_mel_multiply_factor' in args)
|
assert('maybe_custom_mel_multiply_factor' in args)
|
||||||
assert('text_pipeline_type' in args)
|
# Premium features
|
||||||
|
assert('max_decoder_steps' in args)
|
||||||
|
# User input
|
||||||
assert('raw_text' in args)
|
assert('raw_text' in args)
|
||||||
|
# Output files
|
||||||
assert('output_audio_filename' in args)
|
assert('output_audio_filename' in args)
|
||||||
assert('output_spectrogram_filename' in args)
|
assert('output_spectrogram_filename' in args)
|
||||||
assert('output_metadata_filename' in args)
|
assert('output_metadata_filename' in args)
|
||||||
assert('max_decoder_steps' in args)
|
|
||||||
|
|
||||||
LOGGER.info(f"raw inference text: {args['raw_text']}")
|
LOGGER.info(f"raw inference text: {args['raw_text']}")
|
||||||
|
|
||||||
|
|||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
"""
|
||||||
|
Vocodes Tacotron Inference Engine
|
||||||
|
This is a work in progress and is likely going to be slow for now.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# ========== ARGUMENTS (FAIL EARLY IF ABSENT) ==========
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Run TTS inference')
|
||||||
|
|
||||||
|
# Model parameters
|
||||||
|
parser.add_argument('--synthesizer_checkpoint_path', type=str, help='path the TTS synthesizer model', required=True)
|
||||||
|
parser.add_argument('--text_pipeline_type', type=str, help='', required=True)
|
||||||
|
parser.add_argument('--vocoder_type', type=str, help='', required=True)
|
||||||
|
parser.add_argument('--waveglow_vocoder_checkpoint_path', type=str, help='path the TTS vocoder model')
|
||||||
|
parser.add_argument('--hifigan_vocoder_checkpoint_path', type=str, help='path the TTS vocoder model')
|
||||||
|
parser.add_argument('--hifigan_superres_vocoder_checkpoint_path', type=str, help='path the TTS vocoder model')
|
||||||
|
|
||||||
|
# Optional mel scaling before vocoding
|
||||||
|
parser.add_argument('--use_default_mel_multiply_factor', type=bool, help='', action='store_true')
|
||||||
|
parser.add_argument('--maybe_custom_mel_multiply_factor', type=int, help='')
|
||||||
|
|
||||||
|
# Premium features
|
||||||
|
parser.add_argument('--max_decoder_steps', type=int, help='')
|
||||||
|
|
||||||
|
# User input
|
||||||
|
parser.add_argument('--input_text_filename', type=str, help='path the file containing text to run', required=True)
|
||||||
|
|
||||||
|
# Output files
|
||||||
|
parser.add_argument('--output_audio_filename', type=str, help='where to save result audio', required=True)
|
||||||
|
parser.add_argument('--output_spectrogram_filename', type=str, help='where to save result spectrogram', required=True)
|
||||||
|
parser.add_argument('--output_metadata_filename', type=str, help='where to save extra metadata', required=True)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
# ========== IMPORTS ==========
|
||||||
|
|
||||||
|
import sys
|
||||||
|
sys.path.append('waveglow/')
|
||||||
|
import shutil
|
||||||
|
import json
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import torch
|
||||||
|
|
||||||
|
from hparams import create_hparams
|
||||||
|
from model import Tacotron2
|
||||||
|
from text import text_to_sequence
|
||||||
|
from denoiser import Denoiser
|
||||||
|
|
||||||
|
from vocodes_common import FakeYouTt2Pipeline
|
||||||
|
from vocodes_common import print_gpu_info
|
||||||
|
from vocodes_common import parse_int_or_default
|
||||||
|
|
||||||
|
# For metadata
|
||||||
|
import subprocess
|
||||||
|
import magic
|
||||||
|
import os
|
||||||
|
|
||||||
|
from logger import LOGGER
|
||||||
|
|
||||||
|
|
||||||
|
# ========== PRINT GPU INFO ==========
|
||||||
|
|
||||||
|
import tensorflow as tf
|
||||||
|
print("TensorFlow version: {}".format(tf.version.VERSION))
|
||||||
|
print_gpu_info()
|
||||||
|
|
||||||
|
|
||||||
|
# ========== LOAD MODEL + SETUP ==========
|
||||||
|
|
||||||
|
pipeline = FakeYouTt2Pipeline()
|
||||||
|
|
||||||
|
# NB: Not sure if there was a historical decision to load the models first outside of the pipeline.
|
||||||
|
# Probably not, though. Seems like this could be cleaned up.
|
||||||
|
if args.vocoder_type == 'hifigan-superres':
|
||||||
|
pipeline.maybe_load_waveglow_model(args.waveglow_vocoder_checkpoint_path)
|
||||||
|
elif args.vocoder_type == 'waveglow':
|
||||||
|
pipeline.maybe_load_waveglow_model(args.hifigan_vocoder_checkpoint_path)
|
||||||
|
pipeline.maybe_load_waveglow_model(args.hifigan_superres_vocoder_checkpoint_path)
|
||||||
|
else:
|
||||||
|
raise Exception('Wrong vocoder type: {}'.format(args.vocoder_type))
|
||||||
|
|
||||||
|
|
||||||
|
pipeline.maybe_load_tacotron_model_to_cache(args.synthesizer_checkpoint_path)
|
||||||
|
|
||||||
|
# NB: 1000 is the default and is roughly 12 seconds.
|
||||||
|
max_decoder_steps = parse_int_or_default(args.max_decoder_steps, 1000)
|
||||||
|
|
||||||
|
inference_args = {
|
||||||
|
'raw_text': args.inference_text,
|
||||||
|
'use_default_mel_multiply_factor': args.use_default_mel_multiply_factor,
|
||||||
|
'maybe_custom_mel_multiply_factor': args.maybe_custom_mel_multiply_factor,
|
||||||
|
'synthesizer_checkpoint_path': args.synthesizer_checkpoint_path,
|
||||||
|
'vocoder_type': args.vocoder_type,
|
||||||
|
'text_pipeline_type': args.text_pipeline_type,
|
||||||
|
'output_audio_filename': args.output_audio_filename,
|
||||||
|
'output_spectrogram_filename': args.output_spectrogram_filename,
|
||||||
|
'output_metadata_filename': args.output_metadata_filename,
|
||||||
|
'max_decoder_steps': max_decoder_steps,
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGGER.info(f"running inference with args: {inference_args}")
|
||||||
|
|
||||||
|
|
||||||
|
# ========== INFERENCE ==========
|
||||||
|
|
||||||
|
pipeline.infer(inference_args)
|
||||||
|
|
||||||
@@ -222,25 +222,31 @@ class ApiHandler():
|
|||||||
|
|
||||||
LOGGER.info(f"TTS Request: {raw_data}")
|
LOGGER.info(f"TTS Request: {raw_data}")
|
||||||
|
|
||||||
# ========== RUST SERVICE ARGUMENTS ==========
|
# ========== RUST SERVICE ARGUMENTS (REQUEST PARAMETERS) ==========
|
||||||
|
|
||||||
# Request parameters
|
# Model parameters
|
||||||
synthesizer_checkpoint_path = raw_data.get('synthesizer_checkpoint_path')
|
synthesizer_checkpoint_path = raw_data.get('synthesizer_checkpoint_path')
|
||||||
text_pipeline_type = raw_data.get('text_pipeline_type')
|
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')
|
vocoder_type = raw_data.get('vocoder_type')
|
||||||
waveglow_vocoder_checkpoint_path = raw_data.get('waveglow_vocoder_checkpoint_path')
|
waveglow_vocoder_checkpoint_path = raw_data.get('waveglow_vocoder_checkpoint_path')
|
||||||
hifigan_vocoder_checkpoint_path = raw_data.get('hifigan_vocoder_checkpoint_path')
|
hifigan_vocoder_checkpoint_path = raw_data.get('hifigan_vocoder_checkpoint_path')
|
||||||
hifigan_superres_vocoder_checkpoint_path = raw_data.get('hifigan_superres_vocoder_checkpoint_path')
|
hifigan_superres_vocoder_checkpoint_path = raw_data.get('hifigan_superres_vocoder_checkpoint_path')
|
||||||
|
|
||||||
|
# Optional mel scaling before vocoding
|
||||||
|
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')
|
||||||
|
|
||||||
|
# Premium features
|
||||||
|
maybe_max_decoder_steps = raw_data.get('max_decoder_steps')
|
||||||
|
|
||||||
|
# User input
|
||||||
inference_text = raw_data.get('inference_text')
|
inference_text = raw_data.get('inference_text')
|
||||||
|
|
||||||
|
# Output files
|
||||||
output_audio_filename = raw_data.get('output_audio_filename')
|
output_audio_filename = raw_data.get('output_audio_filename')
|
||||||
output_spectrogram_filename = raw_data.get('output_spectrogram_filename')
|
output_spectrogram_filename = raw_data.get('output_spectrogram_filename')
|
||||||
output_metadata_filename = raw_data.get('output_metadata_filename')
|
output_metadata_filename = raw_data.get('output_metadata_filename')
|
||||||
|
|
||||||
# Temporarily optional request parameters
|
|
||||||
maybe_max_decoder_steps = raw_data.get('max_decoder_steps')
|
|
||||||
|
|
||||||
# Optional request parameters
|
# Optional request parameters
|
||||||
maybe_clear_synthesizer_checkpoint_path = \
|
maybe_clear_synthesizer_checkpoint_path = \
|
||||||
raw_data.get('maybe_clear_synthesizer_checkpoint_path')
|
raw_data.get('maybe_clear_synthesizer_checkpoint_path')
|
||||||
|
|||||||
Reference in New Issue
Block a user