add synthesize helper as option, change export to return alignments

pull/15/head
Michael Nguyen 2018-07-20 13:58:41 -05:00
parent 126ef34d44
commit b4447fa9a3
3 changed files with 25 additions and 5 deletions

View File

@ -9,7 +9,7 @@ from flask_cors import CORS
import io import io
import numpy as np import numpy as np
import math import math
from synthesize_helper import synthesize_helper from synthesize_helper import synthesize_helper, replace_acronym, custom_splitter
app = Flask(__name__) app = Flask(__name__)
CORS(app) CORS(app)
@ -72,6 +72,7 @@ synthesizer = Synthesizer()
class Mimic2(MethodView): class Mimic2(MethodView):
def get(self): def get(self):
text = request.args.get('text') text = request.args.get('text')
text = " ".join(replace_acronym(custom_splitter(text)))
if text: if text:
if use_synthesize_helper: if use_synthesize_helper:
wav = synthesize_helper(text, synthesizer) wav = synthesize_helper(text, synthesizer)

View File

@ -26,8 +26,12 @@ if __name__ == "__main__":
synth.model.input_lengths synth.model.input_lengths
) )
wav_output = tf.saved_model.utils.build_tensor_info(synth.wav_output) w_o = audio.inv_spectrogram_tensorflow(
# alignment = tf.saved_model.utils.build_tensor_info(synth.alignment) synth.model.linear_outputs
)
wav_output = tf.saved_model.utils.build_tensor_info(w_o)
alignment = tf.saved_model.utils.build_tensor_info(synth.model.alignments)
prediction_signature = ( prediction_signature = (
tf.saved_model.signature_def_utils.build_signature_def( tf.saved_model.signature_def_utils.build_signature_def(
@ -36,8 +40,8 @@ if __name__ == "__main__":
"input_lengths": input_lengths "input_lengths": input_lengths
}, },
outputs={ outputs={
'wav_output': wav_output #, 'wav_output': wav_output,
# 'alignment': alignment 'alignment': alignment
}, },
method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME) method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME)
) )

View File

@ -40,6 +40,8 @@ letter_lookup = {
def replace_acronym(text): def replace_acronym(text):
for idx, word in enumerate(text): for idx, word in enumerate(text):
if "{" in word and "}" in word:
continue
if len(word) == 1: if len(word) == 1:
continue continue
if word.isupper(): if word.isupper():
@ -50,6 +52,19 @@ def replace_acronym(text):
text[idx] = sound text[idx] = sound
return text return text
def custom_splitter(text):
if "{" in text and "}" in text:
acc = []
split = text.split("}")
for word in split:
if "{" in word:
acc.append(word + "}")
else:
acc.append(word)
return acc
else:
return text.split()
def add_punctuation(text): def add_punctuation(text):
if len(text) < 1: if len(text) < 1:
return text return text