Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add default voice dir for flite_plugin #191

Merged
merged 1 commit into from May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions sound_play/package.xml
Expand Up @@ -46,6 +46,7 @@
<exec_depend>festival</exec_depend>
<exec_depend>flite</exec_depend>
<exec_depend>message_runtime</exec_depend>
<exec_depend>resource_retriever</exec_depend>

<export>
<cpp cflags="-I${prefix}/include -I${prefix}/msg/cpp" />
Expand Down
1 change: 1 addition & 0 deletions sound_play/resources/flitevox/.gitignore
@@ -0,0 +1 @@
*.flitevox
14 changes: 14 additions & 0 deletions sound_play/src/sound_play/flite_plugin.py
@@ -1,6 +1,8 @@
import os
import tempfile

import resource_retriever
import rospkg
import rospy

from sound_play.sound_play_plugin import SoundPlayPlugin
Expand All @@ -12,10 +14,22 @@ class FlitePlugin(SoundPlayPlugin):

def __init__(self):
super(FlitePlugin, self).__init__()
self.rospack = rospkg.RosPack()
self.default_voice_path = os.path.join(
self.rospack.get_path('sound_play'),
'resources/flitevox')

def sound_play_say_plugin(self, text, voice):
if voice is None or voice == '':
voice = self._default_voice
if voice.endswith('.flitevox'):
if voice.startswith('package://'):
voice = resource_retriever.get(voice)
elif voice.startswith('/'):
voice = voice
else:
voice = os.path.join(
self.default_voice_path, voice)
(wavfile, wavfilename) = tempfile.mkstemp(
prefix='sound_play', suffix='.wav')
os.close(wavfile)
Expand Down