From 0394568704479a600a576a4f596e1df41eca0293 Mon Sep 17 00:00:00 2001 From: Kris Gesling <kris.gesling@mycroft.ai> Date: Mon, 28 Jun 2021 11:54:39 +0930 Subject: [PATCH] Use returned TTS audio file path This reverts an unintentional breaking change. A TTS engine may return a different file path than was requested. This again uses the returned path but adds a deprecation warning that this behaviour will no longer be supported in an upcoming release. Fixes #2929 --- mycroft/tts/tts.py | 14 +++++++++++++- test/unittests/tts/test_tts.py | 7 +++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/mycroft/tts/tts.py b/mycroft/tts/tts.py index 8b894f8e04..1360c1cb36 100644 --- a/mycroft/tts/tts.py +++ b/mycroft/tts/tts.py @@ -19,6 +19,7 @@ import re from abc import ABCMeta, abstractmethod from threading import Thread from time import time +from warnings import warn import os.path from os.path import dirname, exists, isdir, join @@ -370,7 +371,18 @@ class TTS(metaclass=ABCMeta): # of the TTS cache. But this requires changing the public # API of the get_tts method in each engine. audio_file = self.cache.define_audio_file(sentence_hash) - _, phonemes = self.get_tts(sentence, str(audio_file.path)) + # TODO 21.08: remove mutation of audio_file.path. + returned_file, phonemes = self.get_tts( + sentence, str(audio_file.path)) + if returned_file.path != audio_file.path: + warn( + DeprecationWarning( + f"{self.tts_name} is saving files " + "to a different path than requested. If you are " + "the maintainer of this plugin, please adhere to " + "the file path argument provided. Modified paths " + "will be ignored in a future release.")) + audio_file = returned_file if phonemes: phoneme_file = self.cache.define_phoneme_file( sentence_hash diff --git a/test/unittests/tts/test_tts.py b/test/unittests/tts/test_tts.py index 2f4b562cca..35577be30a 100644 --- a/test/unittests/tts/test_tts.py +++ b/test/unittests/tts/test_tts.py @@ -96,11 +96,14 @@ class TestTTS(unittest.TestCase): with mock.patch('mycroft.tts.tts.open') as mock_open: tts.cache.temporary_cache_dir = Path('/tmp/dummy') tts.execute('Oh no, not again', 42) - self.assertTrue(tts.get_tts.called) + tts.get_tts.assert_called_with( + 'Oh no, not again', + '/tmp/dummy/8da7f22aeb16bc3846ad07b644d59359.wav' + ) tts.queue.put.assert_called_with( ( 'wav', - '/tmp/dummy/8da7f22aeb16bc3846ad07b644d59359.wav', + str(mock_audio.path), mock_viseme, 42, False