Speech Node
This node is responsible for text-to-speech and sending this audio to the available output device. This node does not manage the audio output device - the robot assumes an audio device is attached to the Raspberry PI:
loading...
Initializing Audio and Background Thread
This node uses the pygame library to manage the audio device. During initialization, the node initializes the pygame mixer and sets the volume:
loading...
The node uses a background thread to process text to speech. This thread is initialized during node startup:
loading...
Processing Text to Speech
Text to Speech is performed by the gTTS library, a wrapper for Google Text to Speech service.
During startup the node subscribed to the speech-node-speak event. This event calls the method speak when fired, passing the text to be converted to the method:
loading...
This method appends the phrase to be spoken to the message list and triggers the background processor:
loading...
If any messages are to be processed, an mp3 stream is created for the message audio and the message audio is written to this stream. The mp3 stream is then sent to the mixer and played. The thread then waits for the mixer to end playing the audio.