How to make Python talk

How can I get Python to say some text?

I could use the Festival with a subprocess, but I will not be able to control it (or maybe interactively, but it will not be clean).

Is there a Python TTS library? How is the API for the festival, eSpeak, ...?

+63
python text-to-speech
Oct 23 '09 at 15:02
source share
12 answers

Please note that this only works with python 2.x

You should try using the PyTTSx package since PyTTS is deprecated. PyTTSx works with the latest version of python.

http://pypi.python.org/pypi/pyttsx/1.0 → Package

Hope this helps

+36
Dec 01 '09 at 5:30 p.m.
source share
— -

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

Try entering the following into the terminal:

$ say 'hello world' 

And there will be a voice from the poppy who will talk about it. From python, such a thing is relatively simple:

 import os os.system("echo 'hello world'") os.system("say 'hello world'") 
+30
Aug 25 '13 at 11:27
source share

How to use text-to-speech features on a Windows PC

 from win32com.client import Dispatch speak = Dispatch("SAPI.SpVoice") speak.Speak("Ciao") 

Using Google Api to convert text to speech to create mp3 and listen to it

After you installed the gtts module in cmd: pip install gtts

 from gtts import gTTS import os tts = gTTS(text="This is the pc speaking", lang='en') tts.save("pcvoice.mp3") # to start the file from python os.system("start pcvoice.mp3") 
+23
Oct 30 '16 at 8:33
source share

The python-espeak package is available on Debian, Ubuntu, Redhat, and other Linux distributions. It has the latest updates and works great.

 from espeak import espeak espeak.synth("Hello world.") 

Jonathan Leaders notes that he also runs on Windows, and you can also install mbrola voices. See the espeak website at http://espeak.sourceforge.net

+15
Jun 07 '14 at 19:00
source share

A simple google led me to pyTTS and a few docs about it . However, it looks immune and specific to Microsoft's speech engine.

At least for Mac OS X, you can use subprocess to invoke the say command, which is pretty funny for talking to your colleagues, but it may not be very useful for your needs.

It looks like the Festival has several public APIs:

The festival offers a BSD-based interface. This allows the Festival to work as a server and allow client programs access to it. Basically, the server offers a new command interpreter for each client that connects to it. A server forks for each client, but this is much faster than waiting for the festival process to start from scratch. Also, the server can run on a larger machine, offering much faster synthesis. linky

There is also a fully functional C ++ API from which you can make a Python module (this is fun!). The festival also offers a simplified C API - keep scrolling in this document - you can drop ctypes for one-time use.

Did you find a hole in the market?

+9
Oct 23 '09 at 15:08
source share

There are several ways to get Python to speak both Python3 and Python2, two great methods:

  • OS usage

If you are using a Mac, the os module will be integrated into your computer. You can import the os module using:

 import os 

Then you can use os to run terminal commands using the os.system command:

 os.system("Your terminal") 

In the terminal, the computer forces you to speak using the "say" command, so to make the computer speak, you simply use:

 os.system("say 'some text'") 

If you want to use this to pronounce a variable, you can use:

 os.system("say " + myVariable) 

The second way to get Python to talk is to use

  • Pyttsx module

You will have to install this using

 pip isntall pyttsx3 

or for Python3

 pip3 install pyttsx3 

Then you can use the following code to make it speak:

 import pyttsx3 engine = pyttsx3.init() engine.say("Your Text") engine.runAndWait() 

Hope this helps! :)

+4
May 30 '18 at 6:52
source share

There may not be anything "Python-specific", but the KDE and GNOME desktops offer text-to-speech as part of their accessibility support, and also offer python library bindings. You can use python bundles to manage desktop libraries for text to speech.

If you are using the Jython Python implementation for the JVM, you can use FreeTTS .

Finally, OSX and Windows have built-in APIs for text to speech. They can be used from python via ctypes or other mechanisms such as COM.

+2
Oct 23 '09 at 15:19
source share

You can use espeak using python to convert text to speech.
Here is a python code example

     from subprocess import call
     speech = "Hello World!"
     call (["espeak", speech])

PS: if espeak is not installed on your Linux system, you need to install it first.
Open a terminal (using ctrl + alt + T) and type

     sudo apt install espeak
+2
Jan 26 '17 at 10:11
source share

If you are using Python 3 and Windows 10, the best solution I have found to work is from Giovanni Gianni. It played for me in a man's voice:

 import win32com.client as wincl speak = wincl.Dispatch("SAPI.SpVoice") speak.Speak("This is the pc voice speaking") 

I also found this video on YouTube, so if you really want to, you can find someone you know and make your own voice.

+2
Aug 11 '17 at 4:21 on
source share

This is what you are looking for. Complete TTS Solution for Mac. You can use this standalone or as a local Mac server for web applications:

http://wolfpaulus.com/jounal/mac/ttsserver/

+1
Jul 05 '14 at 22:03
source share

PYTTSX3 !

THE COMPLETE SOLUTION TO ALL YOU PYTHON TEXT-TO-SPEECH NEEDS

WHAT:

Pyttsx3 is a python module that is a clone of the pyttsx module for Python 2.x, except that it is modified to work in the latest versions of Python 3!

WHY:

It is 100% MULTI-PLATFORM AND WORKS OFFLINE AND ACTIVELY / DEVELOPS AGAIN AND WORKS WITH ANY VERSION OF THE PYTHON

AS:

It can be easily installed using pip install pyttsx3 and use it just like pyttsx:

 import pyttsx3; engine = pyttsx3.init(); engine.say("I will speak this text"); engine.runAndWait(); 

CONCLUSION:

It works easily and without complaints, so I think this is the best solution

+1
May 6 '18 at 2:48
source share

For text to speech, I found this package called " gTTS " in Python. You can try this. It works with Python 3.5.

The github repository for this gTTS-github package.

0
Jan 21 '17 at 21:47 on
source share



All Articles