From 53bc94ebd6713941ffb2b7b3b1be330c3360cbd3 Mon Sep 17 00:00:00 2001 From: Martin Pecka Date: Wed, 3 Apr 2024 10:49:25 +0200 Subject: [PATCH] festival_plugin: add support for different encodings --- sound_play/src/sound_play/festival_plugin.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sound_play/src/sound_play/festival_plugin.py b/sound_play/src/sound_play/festival_plugin.py index 28464b6b..fb57e97b 100644 --- a/sound_play/src/sound_play/festival_plugin.py +++ b/sound_play/src/sound_play/festival_plugin.py @@ -16,6 +16,9 @@ def __init__(self): def sound_play_say_plugin(self, text, voice): if voice is None or voice == '': voice = self._default_voice + encoding = 'ISO-8859-15' + if ':' in voice: + voice, encoding = voice.split(':', maxsplit=1) txtfile = tempfile.NamedTemporaryFile( prefix='sound_play', suffix='.txt') (wavfile, wavfilename) = tempfile.mkstemp( @@ -26,10 +29,10 @@ def sound_play_say_plugin(self, text, voice): try: if hasattr(text, 'decode'): txtfile.write( - text.decode('UTF-8').encode('ISO-8859-15')) + text.decode('UTF-8').encode(encoding)) else: txtfile.write( - text.encode('ISO-8859-15')) + text.encode(encoding)) except UnicodeEncodeError: if hasattr(text, 'decode'): txtfile.write(text)