Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Jan 30, 2025
1 parent 69de89a commit f23cd3e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ovos_tts_plugin_piper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self, config=None):
if isinstance(self.voice, list):
self.voice = self.voice[0]

self.accent = self.config.get("accent", None)
self.use_cuda = self.config.get("use_cuda", False)
self.noise_scale = self.config.get("noise-scale") # generator noise
self.length_scale = self.config.get("length-scale") # Phoneme length
Expand Down Expand Up @@ -171,7 +172,10 @@ def get_tts(self, sentence, wav_file, lang=None, voice=None, speaker=None):
LOG.warning("Legacy Neon TTS signature found, pass speaker as a str")
speaker = None

phonemizer_lang = None # model's default accent
phonemizer_lang = None # if None use model's default accent
if self.accent:
phonemizer_lang = get_espeak_voice(self.accent)

if voice:
# user requested a specific voice model to be used
lang = lang or self.lang
Expand All @@ -184,7 +188,6 @@ def get_tts(self, sentence, wav_file, lang=None, voice=None, speaker=None):
# force a specific espeak phonemizer to match lang pronunciation
# this allows a voice to speak a different language a bit better
phonemizer_lang = get_espeak_voice(lang)
LOG.debug(f"Forcing Piper accent: {phonemizer_lang}")
engine, speaker, voice = self.lang2model(self.lang, self.voice)
except: # change to a voice that supports the lang
LOG.debug("Switching TTS model for one that supports target language")
Expand All @@ -193,6 +196,9 @@ def get_tts(self, sentence, wav_file, lang=None, voice=None, speaker=None):
# default case, no specific voice or lang requested
engine, speaker, voice = self.lang2model(self.lang, self.voice)

if phonemizer_lang:
LOG.debug(f"Forcing Piper accent: {phonemizer_lang}")

with wave.open(wav_file, "wb") as f:
engine.synthesize(sentence, f,
speaker_id=speaker,
Expand Down

0 comments on commit f23cd3e

Please sign in to comment.