Skip to content

Commit

Permalink
Allow to select vocoder in web
Browse files Browse the repository at this point in the history
  • Loading branch information
babysor committed Nov 8, 2021
1 parent 2bd323b commit 6c8f3f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
10 changes: 6 additions & 4 deletions web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down Expand Up @@ -107,12 +107,14 @@ def synthesize():
embeds = [embed] * len(texts)
specs = current_synt.synthesize_spectrograms(texts, embeds)
spec = np.concatenate(specs, axis=1)
# wav = rnn_vocoder.infer_waveform(spec)
wav = gan_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'])
Expand Down
22 changes: 18 additions & 4 deletions web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 6c8f3f4

Please sign in to comment.