festival_plugin.py
Go to the documentation of this file.
1 import os
2 import tempfile
3 
4 import rospy
5 
6 from sound_play.sound_play_plugin import SoundPlayPlugin
7 
8 
10 
11  _default_voice = 'voice_kal_diphone'
12 
13  def __init__(self):
14  super(FestivalPlugin, self).__init__()
15 
16  def sound_play_say_plugin(self, text, voice):
17  if voice is None or voice == '':
18  voice = self._default_voice
19  encoding = 'ISO-8859-15'
20  if ':' in voice:
21  voice, encoding = voice.split(':', maxsplit=1)
22  txtfile = tempfile.NamedTemporaryFile(
23  prefix='sound_play', suffix='.txt')
24  (wavfile, wavfilename) = tempfile.mkstemp(
25  prefix='sound_play', suffix='.wav')
26  txtfilename = txtfile.name
27  os.close(wavfile)
28  try:
29  try:
30  if hasattr(text, 'decode'):
31  txtfile.write(
32  text.decode('UTF-8').encode(encoding))
33  else:
34  txtfile.write(
35  text.encode(encoding))
36  except UnicodeEncodeError:
37  if hasattr(text, 'decode'):
38  txtfile.write(text)
39  else:
40  txtfile.write(text.encode('UTF-8'))
41  txtfile.flush()
42  cmd = "text2wave -eval '({0})' {1} -o {2}".format(
43  voice, txtfilename, wavfilename)
44  os.system(cmd)
45  try:
46  if os.stat(wavfilename).st_size == 0:
47  # So we hit the same catch block
48  raise OSError
49  except OSError:
50  rospy.logerr(
51  'Sound synthesis failed.'
52  'Is festival installed?'
53  'Is a festival voice installed?'
54  'Try running "rosdep satisfy sound_play|sh".'
55  'Refer to http://wiki.ros.org/'
56  'sound_play/Troubleshooting'
57  )
58  return None
59  finally:
60  txtfile.close()
61  return wavfilename
sound_play.festival_plugin.FestivalPlugin._default_voice
string _default_voice
Definition: festival_plugin.py:11
sound_play.festival_plugin.FestivalPlugin.sound_play_say_plugin
def sound_play_say_plugin(self, text, voice)
Definition: festival_plugin.py:16
sound_play.festival_plugin.FestivalPlugin
Definition: festival_plugin.py:9
sound_play.festival_plugin.FestivalPlugin.__init__
def __init__(self)
Definition: festival_plugin.py:13
sound_play.sound_play_plugin.SoundPlayPlugin
Definition: sound_play_plugin.py:1
sound_play.sound_play_plugin
Definition: sound_play_plugin.py:1


sound_play
Author(s): Blaise Gassend
autogenerated on Fri Aug 16 2024 02:42:13