Text-to-speech (TTS) module that runs Python 3

I've tried PyTTS (deprecated) and PyTTSx (most recommended) and two Google TTS solutions (gTTS and the other is some guy named Hung Truong) but neither worked under Python 3.4. It seems they haven't been ported to 3.x.

I have searched here on StackOverflow and Google but all suggested TTS solutions do not work under Python 3. I am on Windows 7.

+4


source to share


5 answers


A Reddit user found a solution .

It turns out that gTTS works under Python 3.x, I imported the module incorrectly.

I used:

import gtts
blabla = ("Spoken text")
tts = gTTS(text=blabla, lang='en')
tts.save("C:/test.mp3")

      



As a result, the following error:

NameError: name 'gTTS' is not defined

      

When the correct path is:

from gtts import gTTS
blabla = ("Spoken text")
tts = gTTS(text=blabla, lang='en')
tts.save("C:/test.mp3")

      

+7


source


Best solution for this:

pyttsx3


Pyttsx3 is a stand-alone, cross-platform Test-to-Speech library that is compatible with both Python 3 and Python 2 and supports multiple TTS engines.

I found this very useful and there is no latency in audio production, unlike gTTS, which requires an internet connection and also has some latency.

For installation:



pip install pyttsx3

Here's some sample code:

``,

import pyttsx3
engine = pyttsx3.init()
engine.say("Hello this is me talking")
engine.setProperty('rate',120)  #120 words per minute
engine.setProperty('volume',0.9) 
engine.runAndWait()

      

``,

+3


source


I just installed gtts 1.0.7 which was uploaded on 2015-10-07

The following code works for me in Python 3.5:

import subprocess
from gtts import gTTS

audio_file = "hello.mp3"
tts = gTTS(text="Hello World!", lang="en")
tts.save(audio_file)
return_code = subprocess.call(["afplay", audio_file])

      

I'm on a Mac using the built-in "smooth" to play mp3, but there are other ways for example. Playing mp3 song in python

+1


source


my pip install gtts is only installed in python 2.

When trying to import from gtts gTTS using python 3, Traceback File error "", line 1, in ImportError: no module named 'gtts'

I also tried installing pip3 gtts but it came up with a lot of errors.

I have been struggling with this for several days. Appreciate a lot of help.

thank you in advance

0


source


Instead of using a module, you can use the Google Text-to-Speech API. You can easily use this url to create a wav file and get it via a simple HTTP request:

http://www.translate.google.com/translate_tts?tl=en&q=Hello%20World

-five


source







All Articles