flite_plugin.py
Go to the documentation of this file.
1 import os
2 import tempfile
3 
4 import resource_retriever
5 import rospkg
6 import rospy
7 
8 from sound_play.sound_play_plugin import SoundPlayPlugin
9 
10 
12 
13  _default_voice = 'kal'
14 
15  def __init__(self):
16  super(FlitePlugin, self).__init__()
17  self._default_voice_path = None
18 
20  if self._default_voice_path is None:
21  self._default_voice_path = os.path.join(
22  rospkg.RosPack().get_path('sound_play'),
23  'resources/flitevox')
24  return self._default_voice_path
25 
26  def sound_play_say_plugin(self, text, voice):
27  if voice is None or voice == '':
28  voice = self._default_voice
29  if voice.endswith('.flitevox'):
30  if voice.startswith('package://'):
31  voice = resource_retriever.get(voice)
32  elif voice.startswith('/'):
33  voice = voice
34  else:
35  voice = os.path.join(
36  self.get_default_voice_path(), voice)
37  (wavfile, wavfilename) = tempfile.mkstemp(
38  prefix='sound_play', suffix='.wav')
39  os.close(wavfile)
40  cmd = "flite -voice {0} -t \"{1}\" -o {2}".format(
41  voice, text, wavfilename)
42  os.system(cmd)
43  try:
44  if os.stat(wavfilename).st_size == 0:
45  # So we hit the same catch block
46  raise OSError
47  except OSError:
48  rospy.logerr(
49  'Sound synthesis failed.'
50  'Is flite installed?'
51  'Is a flite voice installed?'
52  'Try running "rosdep satisfy sound_play|sh".'
53  'Refer to http://wiki.ros.org/'
54  'sound_play/Troubleshooting'
55  )
56  return None
57  return wavfilename
sound_play.flite_plugin.FlitePlugin._default_voice_path
_default_voice_path
Definition: flite_plugin.py:17
resource_retriever::get
def get(url)
sound_play.flite_plugin.FlitePlugin.__init__
def __init__(self)
Definition: flite_plugin.py:15
sound_play.flite_plugin.FlitePlugin.sound_play_say_plugin
def sound_play_say_plugin(self, text, voice)
Definition: flite_plugin.py:26
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.flite_plugin.FlitePlugin
Definition: flite_plugin.py:11
sound_play.flite_plugin.FlitePlugin._default_voice
string _default_voice
Definition: flite_plugin.py:13
sound_play.flite_plugin.FlitePlugin.get_default_voice_path
def get_default_voice_path(self)
Definition: flite_plugin.py:19


sound_play
Author(s): Blaise Gassend
autogenerated on Fri Sep 1 2023 02:42:30