Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejgray committed Jun 25, 2024
1 parent c57585f commit fe8e454
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
16 changes: 11 additions & 5 deletions ovos_plugin_manager/templates/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,11 +1015,17 @@ class StreamingTTSCallbacks:
def __init__(self, bus, play_args=None, tts_config=None):
self.bus = bus
self.config = tts_config
# Prefer directly passed play args, then config from plugin, then default WAV config
self.play_args = play_args \
or [get_plugin_config(tts_config, "tts").get("streaming_tts_cmd")] \
or [get_plugin_config().get("play_wav_cmdline")] \
or ["paplay"]
if play_args is not None:
self.play_args = play_args
# Prefer directly passed play args, then config from plugin, then default WAV config, then finally paplay
else:
self.play_args = [get_plugin_config(tts_config, "tts").get("streaming_tts_cmd")]
if self.play_args == [None]:
self.play_args = [get_plugin_config().get("play_wav_cmdline")]
if self.play_args == [None]:
self.play_args = ["paplay"]
for i, arg in enumerate(self.play_args):
self.play_args[i] = arg.replace(" %1", "")
self._process = None

def stream_start(self, message=None):
Expand Down
11 changes: 6 additions & 5 deletions test/unittests/test_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,11 @@ def test_play_args_from_tts_config(self):
self.assertEqual(tts_callbacks.play_args, ["vlc"])

def test_play_args_from_default_config(self):
environ["XDG_CONFIG_HOME"] = os.getcwd()
os.makedirs(f"{os.getcwd()}/mycroft", exist_ok=True)
with open(f"{os.getcwd()}/mycroft/mycroft.conf", "w", encoding="utf-8") as f:
f.write('{"play_wav_cmdline": "afplay"}')
environ["OVOS_CONFIG_BASE_FOLDER"] = "mycroft"
environ["OVOS_CONFIG_FILENAME"] = "test.conf"
os.makedirs(f"{os.path.expanduser('~')}/.config/mycroft", exist_ok=True)
with open(f"{os.path.expanduser('~')}/.config/mycroft/test.conf", "w", encoding="utf-8") as f:
f.write('{"play_wav_cmdline": "afplay %1"}')
tts_callbacks = StreamingTTSCallbacks(FakeBus(), None)
self.assertEqual(tts_callbacks.play_args, ["afplay"])
os.removedirs(f"{os.getcwd()}/mycroft")
os.remove(f"{os.path.expanduser('~')}/.config/mycroft/test.conf")

0 comments on commit fe8e454

Please sign in to comment.