Working with speech synthesis in ROS Indigo and Python

In ROS, there are some ROS packages that perform speech synthesis. Here, we will discuss one ROS package. This package uses Festival as the backend. The package name is sound_play. It has nodes and launch scripts that enable speech synthesis. We need to perform the following steps for speech synthesis:

  1. We can install the sound_play package using the following command:
    $ sudo apt-get install ros-indigo-sound-play
    
  2. After the installation of package, we have to create a sample ROS package to interact with the sound-play node. The following is the command to create a sample package in ROS with the sound-play package as dependency:
    $ catkin_create_pkg sample_tts rospy roscpp sound_play std_msgs
    
  3. We have to create a sound_play python client code for sending text to sound play server node. This client will send the text that needs to be converted to speech to the sound_play server node. The client will send the text to convert to speech in a Topic called /robotsound. The sound play node in the sound play package will subscribe to this Topic and convert the string from Topic to speech.
  4. Create a folder inside this sample_tts package named scripts and create the following code in the scripts folder and name it test.py. The code snippets of test.py is given.
  5. The following code will import the rospy and sound_play modules. This script will act as a SoundClient, which will connect to the sound_play server and synthesize the speech:
    #!/usr/bin/env python
    import roslib; roslib.load_manifest('sample_tts')
    import rospy, os, sys
    from sound_play.msg import SoundRequest
    from sound_play.libsoundplay import SoundClient
  6. This code will initialize the soundplay_test node and create an object of SoundClient:
    if __name__ == '__main__':
        rospy.init_node('soundplay_test', anonymous = True)
        soundhandle = SoundClient()
        rospy.sleep(1)
    
        soundhandle.stopAll()
  7. This code will call a function to synthesize the speech. It can be used to synthesize speech in any package that includes sound_play as dependency.
        print 'Starting TTS'
        soundhandle.say('Hello world!')
        rospy.sleep(3)
            
        s = soundhandle.voiceSound("Hello World")
        s.play()
        rospy.sleep(3)
  8. The following command starts the sound play server:
    $ roslaunch sound_play soundplay_node.launch
    
  9. The following command will start the test script for speech synthesis:
    $ rosrun sample_tts test.py
    
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.223.168