Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Python speak

How could I make Python say some text?

I could use Festival with subprocess but I won't be able to control it (or maybe in interactive mode, but it won't be clean).

Is there a Python TTS library? Like an API for Festival, eSpeak, ... ?

like image 518
dugres Avatar asked Oct 23 '09 15:10

dugres


People also ask

How do I get text to speech in Python?

There are several APIs available to convert text to speech in Python. One of such APIs is the Google Text to Speech API commonly known as the gTTS API. gTTS is a very easy to use tool which converts the text entered, into audio which can be saved as a mp3 file.

What is Python speech?

Speech recognition is a machine's ability to listen to spoken words and identify them. You can then use speech recognition in Python to convert the spoken words into text, make a query or give a reply. You can even program some devices to respond to these spoken words.


2 Answers

You should try using the PyTTSx package since PyTTS is outdated. PyTTSx works with Python 2. For Python 3, install the PyTTSx3 package.

http://pypi.python.org/pypi/pyttsx/

https://pypi.org/project/pyttsx3/

like image 79
Eligio Becerra Avatar answered Oct 09 '22 08:10

Eligio Becerra


A bit cheesy, but if you use a mac you can pass a terminal command to the console from python.

Try typing the following in the terminal:

$ say 'hello world'  

And there will be a voice from the mac that will speak that. From python such a thing is relatively easy:

import os os.system("echo 'hello world'") os.system("say 'hello world'")  
like image 40
cantdutchthis Avatar answered Oct 09 '22 07:10

cantdutchthis