Pi Speech Synthesis
Output (English) sentences from your Pi which are sent as text via WAMP.
The example uses the flite text-to-speech engine to convert english sentences to voice which is then output via the Pi's audio output.
Try it out¶
The code for the example consists of an adapter written in Python and AutobahnPython using Twisted. The adapter runs on the Pi and connects to Crossbar.io running on a network accessible from the Pi.
Preparations on the Pi¶
Enable audio output on the 3.5mm plug:
sudo amixer cset numid=3 1
Install the flite text-to-speech processor:
sudo apt-get install -y flite
Test the text-to-speech engine:
flite -voice slt "Hi, my name is Susan. How can I help you?"
The volume may be a bit low. To increase that to (near) the maximum, do
sudo amixer set PCM -- -100
to set this to near maximun (and try larger values instead of
-100 to decrease the volume a bit again).
sudo pip install autobahn[twisted]
Running the Speech Synthesis¶
You need a Crossbar.io instance for the Speech Synthesis adapter on the Pi and the browser frontend to connect to.
The simplest way is to navigate to
iotcookbook/device/pi/speechsynt in your local
crossbarexamples repo, and do
This will also serve the browser frontend under
speechsynth_adapter.py onto the Pi, e.g. via scp
scp speechsynth_adapter.py pi@<IP of your Pi>:~/
and then start it, passing the URL of Crossbar.io and the realm to connect to, e.g.
python speechsynth_adapter.py \ --router 'ws://192.168.1.134:8080/ws' \ --realm 'iot_cookbook'
Then use the browser frontend to send a text of your choice. (Be aware that the full text you send is rendered to audio before playback starts. Long texts can take a while to start - so better to chunk them into smaller bits.)
The adapter exposes these procedures
io.crossbar.examples.iot.devices.pi.<DEVICE ID>.speechsynth.say- takes a string as argument ([string]). Returns once the text has been processed and spoken. Fails if text is currently being spoken (so check first using the procedure below).
io.crossbar.examples.iot.devices.pi.<DEVICE ID>.speechsynth.is_busy- returns true if a text is presently being spoken or processed.
and publishes event to these topics
io.crossbar.examples.iot.devices.pi.<DEVICE ID>.speechsynth.on_ready- sent once the component is initialized
io.crossbar.examples.iot.devices.pi.<DEVICE ID>.speechsynth.on_speech_start- sent when the processing of received text has started
io.crossbar.examples.iot.devices.pi.<DEVICE ID>.speechsynth.on_speech_end- sent when the processing and output of speech has finished.
No real difference to the trying out - run 'speechsynth_adapter.py' on the Pi, connect to a WAMP router, call from any WAMP component using the above API.