Allow to select vocoder in web

This commit is contained in:
babysor00 2021-11-08 23:55:16 +08:00
parent 2bd323b7df
commit 6c8f3f4515
2 changed files with 24 additions and 8 deletions

View File

@ -31,7 +31,7 @@ def webApp():
synthesizers = list(Path(syn_models_dirt).glob("**/*.pt"))
synthesizers_cache = {}
encoder.load_model(Path("encoder/saved_models/pretrained.pt"))
# rnn_vocoder.load_model(Path("vocoder/saved_models/pretrained/pretrained.pt"))
rnn_vocoder.load_model(Path("vocoder/saved_models/pretrained/pretrained.pt"))
gan_vocoder.load_model(Path("vocoder/saved_models/pretrained/g_hifigan.pt"))
def pcm2float(sig, dtype='float32'):
@ -107,12 +107,14 @@ def webApp():
embeds = [embed] * len(texts)
specs = current_synt.synthesize_spectrograms(texts, embeds)
spec = np.concatenate(specs, axis=1)
# wav = rnn_vocoder.infer_waveform(spec)
if "vocoder" in request.form and request.form["vocoder"] == "WaveRNN":
wav = rnn_vocoder.infer_waveform(spec)
else:
wav = gan_vocoder.infer_waveform(spec)
# Return cooked wav
out = io.BytesIO()
write(out, Synthesizer.sample_rate, wav)
write(out, Synthesizer.sample_rate, wav.astype(np.float32))
return Response(out, mimetype="audio/wav")
@app.route('/', methods=['GET'])

View File

@ -61,7 +61,16 @@
<div class="pd btns" style="margin-left: 5%;margin-top: 20px;width: 90%; ">
<div style="font-size: larger;font-weight: bolder;">3. 选择Synthesizer模型</div>
<span class="box">
<select id="select">
<select id="selectSynt">
</select>
</span>
</div>
<div class="pd btns" style="margin-left: 5%;margin-top: 20px;width: 90%; ">
<div style="font-size: larger;font-weight: bolder;">4. 选择Vocoder模型</div>
<span class="box">
<select id="selectVocoder">
<option>WaveRNN</option>
<option>HifiGAN</option>
</select>
</span>
</div>
@ -116,7 +125,7 @@
var option = document.createElement('option');
option.text = synt.name
option.value = synt.path
$("#select").append(option);
$("#selectSynt").append(option);
}
}).catch(function (err) {
console.log('Error: ' + err.message);
@ -266,11 +275,16 @@
var postData = new FormData();
postData.append("text", input_text)
postData.append("file", blob)
var sel = document.getElementById("select");
var path = sel.options[sel.selectedIndex].value;
var syntSelect = document.getElementById("selectSynt");
var path = syntSelect.options[syntSelect.selectedIndex].value;
if (!!path) {
postData.append("synt_path", path);
}
var vocoderSelect = document.getElementById("selectVocoder");
var vocoder = vocoderSelect.options[vocoderSelect.selectedIndex].value;
if (!!vocoder) {
postData.append("vocoder", vocoder);
}
fetch(api, {
method: 'post',