Skip to content

Commit

Permalink
Have to a strip voice because of default value bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
mchilvers committed Mar 21, 2024
1 parent b99ef06 commit 6ca6dbf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/invent/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
from .compatability import proxy


_VOICES_BY_NAME = {}
_VOICES_BY_NAME = None


def on_voices_changed(event):
"""Voices are loaded asynchronously."""

global _VOICES_BY_NAME

_VOICES_BY_NAME = {voice.name: voice for voice in synth.getVoices()}
voices_by_name = {voice.name: voice for voice in synth.getVoices()}

_VOICES_BY_NAME = voices_by_name


try:
Expand Down Expand Up @@ -41,7 +43,9 @@ def get_voice_by_name(voice_name):
Defaults to the first voice.
"""

if _VOICES_BY_NAME:
voice_name = voice_name.strip()

if _VOICES_BY_NAME is not None:
voice = _VOICES_BY_NAME.get(voice_name)

else:
Expand Down Expand Up @@ -70,7 +74,7 @@ def say(text):
voice = selected_voice

else:
voice = get_voice_by_name("Catherine")
voice = get_voice_by_name("Fred")

if voice:
utterance.voice = voice
Expand Down

0 comments on commit 6ca6dbf

Please sign in to comment.