web dev & more!

Text to Speech in Python

Published: July 5, 2016

I finally got around to looking at the Linux Voice 18 and I have to say, the Summer hacks section is really cool. I’ve always been curious about recompiling a kernel and playing around with the different settings, but the project that really caught my attention was the Python script that converted IRC chat into voice. That really just sounds like fun. So I tried going through with it, but ran into some issues with my Python versioning. And since I don’t really use IRC, I thought it might be fun to just whip up a quick script that converts whatever text is typed into the terminal into voice. It’s simple enough to do, so here it is!

from espeak import espeak
import time
while True:
response = input(">> ")
espeak.synth(response)
time.sleep(1)

To install, make sure that the package espeak is installed. To install espeak, run:
sudo apt-get install espeak espeak-data
Then, to run the script, run
python3 scriptname.py
Here’s a link to the Gist

At some point, I think it’d be pretty cool to turn this into a Telegram Bot via their API. Maybe use this to convert all text into a voice (like Gigolo Joe’s “say” function), but it would also be cool to allow Telegram to convert something a user says into text.