Add auto append text for punctuation

This commit is contained in:
Michael Hansen 2022-05-10 10:41:44 -04:00
commit 938b5eff70
3 changed files with 14 additions and 5 deletions

View file

@ -14,7 +14,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import argparse
import asyncio
import io
import logging
import threading
@ -131,9 +130,7 @@ def do_synthesis_proc(args: argparse.Namespace, request_queue: Queue):
_LOGGER.exception("Error during inference")
# Signal error on main loop
item.loop.call_soon_threadsafe(
item.future.set_exception, e
)
item.loop.call_soon_threadsafe(item.future.set_exception, e)
except Exception:
_LOGGER.exception("Unexpected error in inference thread")

View file

@ -262,7 +262,13 @@ class InferenceConfig:
noise_w: float = 0.8
minor_break_ms: typing.Optional[int] = None
"""Automatically add milliseconds of silence after a minor break (comma)"""
major_break_ms: typing.Optional[int] = None
"""Automatically add milliseconds of silence after a major break (period)"""
auto_append_text: typing.Optional[str] = None
"""Automatically append text to the end of an utterance if not present (e.g., punctuation)"""
@dataclass

View file

@ -364,13 +364,19 @@ class Mimic3TextToSpeechSystem(TextToSpeechSystem):
def begin_utterance(self):
pass
# pylint: disable=arguments-differ
def speak_text(self, text: str, text_language: typing.Optional[str] = None):
voice = self._get_or_load_voice(self.voice)
# Automatically append text (e.g., punctuation) if not present
append_text = voice.config.inference.auto_append_text
if append_text and (not text.endswith(append_text)):
text += append_text
# Automatic silence after major/minor breaks (optional)
minor_break_ms = voice.config.inference.minor_break_ms
major_break_ms = voice.config.inference.major_break_ms
# Process chunks
for sent_phonemes, break_type in voice.text_to_phonemes(
text, text_language=text_language
):