Add sample text for voices

This commit is contained in:
Michael Hansen 2022-05-10 14:11:27 -04:00
commit de0097c034
4 changed files with 244 additions and 11 deletions

View file

@ -18,6 +18,7 @@ import asyncio
import dataclasses
import json
import logging
import re
import typing
from pathlib import Path
from queue import Queue
@ -36,7 +37,7 @@ from quart import (
from swagger_ui import api_doc
from mimic3_tts import DEFAULT_VOICE, Mimic3Settings, Mimic3TextToSpeechSystem
from mimic3_tts.utils import LANG_NAMES
from mimic3_tts.utils import LANG_NAMES, SAMPLE_SENTENCES
from ._resources import _DIR, _PACKAGE
from .args import _MISSING
@ -234,6 +235,11 @@ def get_app(args: argparse.Namespace, request_queue: Queue, temp_dir: str):
# Add more fields to voices
for voice_dict in voice_dicts:
voice_lang = voice_dict["language"]
# en_US => en
short_lang = voice_lang.split("_", maxsplit=1)[0]
# en_US => English (US)
lang_name = LANG_NAMES.get(voice_lang, voice_lang)
if isinstance(lang_name, str):
@ -246,6 +252,10 @@ def get_app(args: argparse.Namespace, request_queue: Queue, temp_dir: str):
voice_dict["language_native"] = native_lang
voice_dict["language_english"] = english_lang
sample_text = SAMPLE_SENTENCES.get(short_lang, "")
sample_text = re.sub(r"\s+", " ", sample_text)
voice_dict["sample_text"] = sample_text
return jsonify(voice_dicts)
@app.route("/process", methods=["GET", "POST"])

View file

@ -235,6 +235,7 @@
<!-- Bootstrap core JavaScript -->
<script>
var voicesInfo = {}
var isUserText = false
function q(selector) {return document.querySelector(selector)}
q('#text').focus()
@ -378,6 +379,12 @@
)
}
var textArea = q('#text')
if ((textArea.value.length == 0) || !isUserText) {
textArea.value = voice.sample_text
isUserText = false
}
// Update inference settings
if (voice.properties) {
q('#length-scale').value = voice.properties.length_scale || 1.0
@ -433,18 +440,22 @@
})
}
function copyVoiceKey() {
var voiceName = q('#voice-name')
var speakerList = q('#speaker-list')
function copyVoiceKey() {
var voiceName = q('#voice-name')
var speakerList = q('#speaker-list')
var voiceKey = voiceName.options[voiceName.selectedIndex].value
if (speakerList.options.length > 1) {
voiceKey += '#' + speakerList.options[speakerList.selectedIndex].value
}
var voiceKey = voiceName.options[voiceName.selectedIndex].value
if (speakerList.options.length > 1) {
voiceKey += '#' + speakerList.options[speakerList.selectedIndex].value
}
navigator.clipboard.writeText(voiceKey)
}
navigator.clipboard.writeText(voiceKey)
}
function textChanged() {
isUserText = true
}
window.addEventListener('load', function() {
loadVoices()
@ -453,6 +464,7 @@
q('#voice-name').addEventListener('change', nameChanged)
q('#copy-voice').addEventListener('click', copyVoiceKey)
q('#text').addEventListener('change', textChanged)
})
</script>