-
Notifications
You must be signed in to change notification settings - Fork 0
Text to Speech
Mark Niemann-Ross edited this page Jan 22, 2017
·
8 revisions
Text-to-speech on the fish involves several steps:
- Obtain a string to speak
- Convert the string to an audio file
- Play the audio file
These steps should happen asynchronously. That is:
- Any program, at any time, should be able to request speech
- Converting text to an audio file shouldn't block anything else
- Playing back the sound should be FIFO. The second sound in the queue shouldn't play until the first is finished.
- There should be a way to dump the queue or set a priority. (to come if necessary)
To implement this, I'm using SQLite. A record looks like:
- UID - unique id
- creation date of record - second sort
- priority - first sort
- string to be spoken
- BLOB - wav file to be spoken
- Result or Error code
The process is broken into three code chunks:
-
bmbb_fish.fishSays
- a common function to queue speech requests to SQLite. It has two arguments: priority and the string to speak. -
do_TTS.py &
- sweeps SQLite for phrases that need to be converted to audio, handles the conversion, then inserts the BLOB into the record. If there is a problem with the conversion service, the return code is stashed in the record.do_TTS
constantly loops through the records, selecting a list of strings with no blobs. It is throttled to 20 requests per minute. Bing requires an authentication token which expires every ten minutes. do_TTS checks to ensure it has a valid token every six minutes. If not, it gets a new one. -
speakNextPhrase.py &
- pulls the next phrase from SQLite and plays it. When that phrase is finished, delete it from SQLite and get the next phrase.
sudo apt-get install espeak
If you are using python 2
wget https://pypi.python.org/packages/source/p/pyttsx/pyttsx-1.1.tar.gz
gunzip pyttsx-1.1.tar.gz
tar -xf pyttsx-1.1.tar
cd pyttsx-1.1/
sudo python setup.py install
If you are using python 3
sudo apt-get install python3-pip (this may not be necessary python)
sudo pip install pyttsx
or
wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python3
wget https://pypi.python.org/packages/source/p/pyttsx/pyttsx-1.1.tar.gz
gunzip pyttsx-1.1.tar.gz
tar -xf pyttsx-1.1.tar
cd pyttsx-1.1/
sudo python3 setup.py install