|
1 | | -## AWS Ros Tts Ros1 |
| 1 | +# tts |
2 | 2 |
|
3 | | -ROS packages for facilitating text-to-speech and the use of Amazon Polly. |
4 | 3 |
|
5 | | -## License |
| 4 | +## Overview |
| 5 | +The `tts` ROS node enables a robot to speak with a human voice by providing a Text-To-Speech service. |
| 6 | +Out of the box this package listens to a speech topic, submits text to the Amazon Polly cloud service to generate an audio stream file, |
| 7 | +retrieves the audio stream from Amazon Polly, and plays the audio stream via the default output device. |
| 8 | +The nodes can be configured to use different voices as well as custom lexicons and SSML tags which enable you to control aspects of speech, |
| 9 | +such as pronunciation, volume, pitch, speed rate, etc. A [sample ROS application] with this node, |
| 10 | +and more details on speech customization are available within the [Amazon Polly documentation]. |
6 | 11 |
|
7 | | -This library is licensed under the Apache 2.0 License. |
| 12 | +**Amazon Polly Summary**: Amazon Polly is a service that turns text into lifelike speech, allowing you to create applications that talk, |
| 13 | +and build entirely new categories of speech-enabled products. Amazon Polly is a Text-to-Speech service that uses advanced deep learning technologies to synthesize speech that sounds like a human voice. |
| 14 | +With dozens of lifelike voices across a variety of languages, you can select the ideal voice and build speech-enabled applications that work in many different countries. |
| 15 | + |
| 16 | +**Features in Active Development**: |
| 17 | +- Offline TTS |
| 18 | + |
| 19 | +### License |
| 20 | +The source code is released under an [Apache 2.0]. |
| 21 | + |
| 22 | +**Author**: AWS RoboMaker<br/> |
| 23 | +**Affiliation**: [Amazon Web Services (AWS)]<br/> |
| 24 | +**Maintainer**: AWS RoboMaker, ros-contributions@amazon.com |
| 25 | + |
| 26 | +### Supported ROS Distributions |
| 27 | +- Kinetic |
| 28 | +- Lunar |
| 29 | +- Melodic |
| 30 | + |
| 31 | + |
| 32 | +## Installation |
| 33 | + |
| 34 | +### AWS Credentials |
| 35 | +You will need to create an AWS Account and configure the credentials to be able to communicate with AWS services. You may find [AWS Configuration and Credential Files] helpful. |
| 36 | + |
| 37 | +This node will require the following AWS account IAM role permissions: |
| 38 | +- `polly:SynthesizeSpeech` |
| 39 | + |
| 40 | +### Build and Test |
| 41 | + |
| 42 | +#### Build from Source |
| 43 | + |
| 44 | +If you test this package on versions of Ubuntu older than 18.x (16.04 for example), please upgrade `mock` to the latest version by using `pip`. |
| 45 | + |
| 46 | + sudo apt-get python-pip |
| 47 | + pip install -U mock requests |
| 48 | + |
| 49 | +Create a ROS workspace and a source directory |
| 50 | + |
| 51 | + mkdir -p ~/ros-workspace/src |
| 52 | + |
| 53 | +To install from source, clone the latest version from master branch and compile the package |
| 54 | + |
| 55 | +- Clone the package into the source directory |
| 56 | + |
| 57 | + cd ~/ros-workspace |
| 58 | + git clone https://github.com/aws-robotics/tts-ros1.git |
| 59 | + |
| 60 | +- Install dependencies |
| 61 | + |
| 62 | + cd ~/ros-workspace && sudo apt-get update |
| 63 | + rosdep install --from-paths src --ignore-src -r -y |
| 64 | + |
| 65 | +- Install the packages |
| 66 | + |
| 67 | + cd ~/ros-workspace && colcon build |
| 68 | + |
| 69 | +- Configure ROS library Path |
| 70 | + |
| 71 | + source ~/ros-workspace/install/setup.bash |
| 72 | + |
| 73 | +- Build and run the unit tests |
| 74 | + |
| 75 | + colcon test --packages-select tts && colcon test-result --all |
| 76 | + |
| 77 | +#### Test on Containers/Virtual Machines |
| 78 | + |
| 79 | +Even if your container or virtual machine does not have audio device, you can still test TTS by leveraging an audio server. |
| 80 | + |
| 81 | +The following is an example setup on a MacBook with PulseAudio as the audio server. |
| 82 | +If you are new to PulseAudio, you may want to read the [PulseAudio Documentation]. |
| 83 | + |
| 84 | +**Step 1: Start PulseAudio on your laptop** |
| 85 | + |
| 86 | +After installation, start the audio server with *module-native-protocol-tcp* loaded: |
| 87 | + |
| 88 | + pulseaudio --load=module-native-protocol-tcp --exit-idle-time=-1 --log-target=stderr -v |
| 89 | + |
| 90 | +Note the extra arguments `-v` and `--log-target` are used for easier troubleshooting. |
| 91 | + |
| 92 | +**Step 2: Run TTS nodes in container** |
| 93 | + |
| 94 | +In your container, make sure you set the right environment variables. |
| 95 | +For example, you can start the container using `docker run -it -e PULSE_SERVER=docker.for.mac.localhost ubuntu:16.04`. |
| 96 | + |
| 97 | +Then you will be able to run ROS nodes in the container and hear the audio from your laptop speakers. |
| 98 | + |
| 99 | +**Troubleshooting** |
| 100 | + |
| 101 | +If your laptop has multiple audio output devices, make sure the right one has the right volume. |
| 102 | +This command will give you a list of output devices and tell you which one has been selected: |
| 103 | + |
| 104 | + pacmd list-sinks | grep -E '(index:|name:|product.name)' |
| 105 | + |
| 106 | +## Launch Files |
| 107 | +An example launch file called `sample_application.launch` is provided. |
| 108 | + |
| 109 | + |
| 110 | +## Usage |
| 111 | + |
| 112 | +### Run the node |
| 113 | +- **Plain text** |
| 114 | + - `roslaunch tts sample_application.launch` |
| 115 | + - `rosrun tts voicer.py 'Hello World'` |
| 116 | + |
| 117 | +- **SSML** |
| 118 | + - `roslaunch tts sample_application.launch` |
| 119 | + - `rosrun tts voicer.py '<speak>Mary has a <amazon:effect name="whispered">little lamb.</amazon:effect></speak>' '{"text_type":"ssml"}'` |
| 120 | + |
| 121 | + |
| 122 | +## Configuration File and Parameters |
| 123 | +| Parameter Name | Type | Description | |
| 124 | +| -------------- | ---- | ----------- | |
| 125 | +| polly_action | *string* | Currently only one action named `SynthesizeSpeech` is supported. | |
| 126 | +| text | *string* | The text to be synthesized. It can be plain text or SSML. See also `text_type`. | |
| 127 | +| text_type | *string* | A user can choose from `text` and `ssml`. Default: `text`. | |
| 128 | +| voice_id | *string* | The list of supported voices can be found on [official Amazon Polly document]. Default: Joanna | |
| 129 | +| output_format | *string* | Valid formats are `ogg_vorbis`, `mp3` and `pcm`. Default: `ogg_vorbis` | |
| 130 | +| output_path | *string* | The audio data will be saved as a local file for playback and reuse/inspection purposes. This parameter is to provide a preferred path to save the file. Default: `.` | |
| 131 | +| sample_rate | *string* | Note `16000` is a valid sample rate for all supported formats. Default: `16000`. | |
| 132 | + |
| 133 | + |
| 134 | +## Performance and Benchmark Results |
| 135 | +We evaluated the performance of this node by runnning the followning scenario on a Raspberry Pi 3 Model B: |
| 136 | +- Launch a baseline graph containing the talker and listener nodes from the [roscpp_tutorials package](https://wiki.ros.org/roscpp_tutorials), plus two additional nodes that collect CPU and memory usage statistics. Allow the nodes to run for 60 seconds. |
| 137 | +- Launch the nodes `polly_node`, `synthesizer_node` and `tts_node` by using the launch file `sample_application.launch` as described above. At the same time, perform several calls to the action `tts/action/Speech.action` using the `voicer.py` script descried above, by running the following script in the background: |
| 138 | + |
| 139 | +```bash |
| 140 | +rosrun tts voicer.py '<speak>Amazon Polly is a <emphasis level="strong">Text-to-Speech</emphasis> (TTS) cloud service</speak>' '{"text_type":"ssml"}' ; sleep 1 |
| 141 | +rosrun tts voicer.py '<speak>that converts text into lifelike speech</speak>' '{"text_type":"ssml"}' ; sleep 1 |
| 142 | +rosrun tts voicer.py '<speak>You can use Amazon Polly to develop applications that increase <emphasis level="moderate">engagement and accessibility</emphasis></speak>' '{"text_type":"ssml"}' ; sleep 1 |
| 143 | +rosrun tts voicer.py '<speak>Amazon Polly supports multiple languages and includes a variety of lifelike voices</speak>' '{"text_type":"ssml"}' ; sleep 1 |
| 144 | +rosrun tts voicer.py '<speak>so you can build speech-enabled applications that work in multiple locations</speak>' '{"text_type":"ssml"}' ; sleep 1 |
| 145 | +rosrun tts voicer.py '<speak>and use the ideal voice for your customers</speak>' '{"text_type":"ssml"}' ; sleep 1 |
| 146 | +``` |
| 147 | + |
| 148 | +- Allow the nodes to run for 180 seconds. |
| 149 | +- Terminate the `polly_node`, `synthesizer_node` and `tts_node` nodes, and allow the reamaining nodes to run for 60 seconds. |
| 150 | + |
| 151 | +The following graph shows the CPU usage during that scenario. The 1 minute average CPU usage starts at 16.75% during the launch of the baseline graph, and stabilizes at 6%. When we launch the Polly nodes around second 85, the 1 minute average CPU increases up to a peak of 22.25% and stabilizes around 20%. After we stop making requests with the script `voicer.py` around second 206 the 1 minute average CPU usage moves to around 12%, and decreases gradually, and goes down again to 2.5 % after we stop the Polly nodes at the end of the scenario. |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | +The following graph shows the memory usage during that scenario. We start with a memory usage of around 227 MB that increases to around 335 MB (+47.58%) when we lanch the Polly nodes around second 85, and gets to a peak of 361 MB (+59% wrt. initial value) while we are calling the script `voicer.py`. The memory usage goes back to the initial values after stopping the Polly nodes. |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | + |
| 160 | +## Nodes |
| 161 | + |
| 162 | +### polly |
| 163 | +Polly node is the engine for the synthesizing job. It provides user-friendly yet powerful APIs so a user doesn't have to deal with technical details of AWS service calls. |
| 164 | + |
| 165 | +#### Services |
| 166 | +- **`polly (tts/Polly)`** |
| 167 | + |
| 168 | + Call the service to use Amazon Polly to synthesize the audio. |
| 169 | + |
| 170 | +#### Reserved for future usage |
| 171 | +- `language_code (string, default: None)` |
| 172 | + |
| 173 | + A user doesn't have to provide a language code and this is reserved for future usage. |
| 174 | + |
| 175 | +- `lexicon_content (string, default: None)` |
| 176 | + |
| 177 | +- `lexicon_name (string, default: None)` |
| 178 | + |
| 179 | +- `lexicon_names (string[], default: empty)` |
| 180 | + |
| 181 | +- `speech_mark_types (string[], default: empty)` |
| 182 | + |
| 183 | +- `max_results (uint32, default: None)` |
| 184 | + |
| 185 | +- `next_token (string, default: None)` |
| 186 | + |
| 187 | +- `sns_topic_arn (string, default: None)` |
| 188 | + |
| 189 | +- `task_id (string, default: None)` |
| 190 | + |
| 191 | +- `task_status (string, default: iNone)` |
| 192 | + |
| 193 | +- `output_s3_bucket_name (string, default: None)` |
| 194 | + |
| 195 | +- `output_s3_key_prefix (string, default: None)` |
| 196 | + |
| 197 | +- `include_additional_language_codes (bool, default: None)` |
| 198 | + |
| 199 | +### synthesizer node |
| 200 | + |
| 201 | +#### Services |
| 202 | +- **`synthesizer (tts/Synthesizer)`** |
| 203 | + |
| 204 | + Call the service to synthesize. |
| 205 | + |
| 206 | +#### Parameters |
| 207 | + |
| 208 | +- **`text (string)`** |
| 209 | + |
| 210 | + The text to be synthesized. |
| 211 | + |
| 212 | +- **`metadata (string, JSON format)`** |
| 213 | + |
| 214 | + Optional, for user to have control over how synthesis happens. |
| 215 | + |
| 216 | +### tts node |
| 217 | + |
| 218 | +#### Action |
| 219 | + |
| 220 | +- **`speech`** |
| 221 | + |
| 222 | +#### Parameters |
| 223 | + |
| 224 | +- **`text (string)`** |
| 225 | + |
| 226 | + The text to be synthesized. |
| 227 | + |
| 228 | +- **`metadata (string, JSON format)`** |
| 229 | + |
| 230 | + Optional, for user to have control over how synthesis happens. |
| 231 | + |
| 232 | + |
| 233 | +## Bugs & Feature Requests |
| 234 | +Please contact the team directly if you would like to request a feature. |
| 235 | + |
| 236 | +Please report bugs in [Issue Tracker]. |
| 237 | + |
| 238 | + |
| 239 | +[AWS Configuration and Credential Files]: https://docs.aws.amazon.com/cli/latest/userguide/cli-config-files.html |
| 240 | +[Amazon Polly documentation]: https://docs.aws.amazon.com/polly/latest/dg/what-is.html |
| 241 | +[Amazon Web Services (AWS)]: https://aws.amazon.com/ |
| 242 | +[Apache 2.0]: https://aws.amazon.com/apache-2-0/ |
| 243 | +[Issue Tracker]: https://github.com/aws-robotics/tts-ros1/issues |
| 244 | +[PulseAudio Documentation]: https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/ |
| 245 | +[official Amazon Polly document]: https://docs.aws.amazon.com/polly/latest/dg/voicelist.html |
| 246 | +[sample ROS application]: https://github.com/aws-robotics/aws-robomaker-sample-application-voiceinteraction |
0 commit comments