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  txtfile = tempfile.NamedTemporaryFile(
20  prefix='sound_play', suffix='.txt')
21  (wavfile, wavfilename) = tempfile.mkstemp(
22  prefix='sound_play', suffix='.wav')
23  txtfilename = txtfile.name
24  os.close(wavfile)
25  try:
26  try:
27  if hasattr(text, 'decode'):
28  txtfile.write(
29  text.decode('UTF-8').encode('ISO-8859-15'))
30  else:
31  txtfile.write(
32  text.encode('ISO-8859-15'))
33  except UnicodeEncodeError:
34  if hasattr(text, 'decode'):
35  txtfile.write(text)
36  else:
37  txtfile.write(text.encode('UTF-8'))
38  txtfile.flush()
39  cmd = "text2wave -eval '({0})' {1} -o {2}".format(
40  voice, txtfilename, wavfilename)
41  os.system(cmd)
42  try:
43  if os.stat(wavfilename).st_size == 0:
44  # So we hit the same catch block
45  raise OSError
46  except OSError:
47  rospy.logerr(
48  'Sound synthesis failed.'
49  'Is festival installed?'
50  'Is a festival voice installed?'
51  'Try running "rosdep satisfy sound_play|sh".'
52  'Refer to http://wiki.ros.org/'
53  'sound_play/Troubleshooting'
54  )
55  return None
56  finally:
57  txtfile.close()
58  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 Sep 1 2023 02:42:30