Skip to content

Commit

Permalink
festival_plugin: add support for different encodings
Browse files Browse the repository at this point in the history
  • Loading branch information
peci1 authored Apr 3, 2024
1 parent f95f9c8 commit 53bc94e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sound_play/src/sound_play/festival_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down

0 comments on commit 53bc94e

Please sign in to comment.