I believe that Pyqt4 does not have support for this, and pyqt5 may only come in more support in the future (apparently Qtspeech is quite recent), so using Pyqt is not an option, however I found this: https://pypi.python.org/pypi/pyttsx (is a little outdate 2012), but he is cross-Platform and support Python2 and this https://github.com/pndurette/gTTS
pyttsx
Drivers required by environment:
Then you can install it via PIP:
pip install pyttsx
Take an example:
import pyttsx
engine = pyttsx.init()
engine.say('Hello World!')
engine.runAndWait()
Links:
In the releases of github https://github.com/RapidWareTech/pyttsx/releases and maybe Pip only shows version 1.1, but doc already informs about version 1.2, in case it would just install this https://github.com/RapidWareTech/pyttsx/tree/master/pyttsx manually
lib by itself does not have the languages installed, who has to have installed is the driver used, in the case of Espeak I think it already comes with Portuguese, to configure the language in lib one can use something like, the for
is to get all the voices:
engine = pyttsx.init()
voices = engine.getProperty('voices')
for voice in voices:
engine.setProperty('voice', voice.id) # troca a voz
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
Then you will select the voice you want, note that voices = engine.getProperty('voices')
returns the class class pyttsx.voice.Voice
, which has the following properties:
.age
returns the age in years as integer
.gender
returns a String
that contains the genre of voice that may be female
, male
or neutral
.id
is the voice identifier to be used in pyttsx.engine.Engine.setPropertyValue()
.languages
returns a list
of strings that shows speech-supported languages
.name
returns a String
containing a "human" name to help assimilate language, gender, etc
In case you can use voice.languages
to obtain the ID of the Portuguese language and so set it.
If there is no Portuguese language in the list it is because the driver does not support or has not installed the language, in the case of linux and Espeak already comes with several languages:
Windows also seems to already have some including those in English:
What I like about espeek is that it has support for Windows and Macosx, I just don’t know if lib is compatible
gTTS
gTTS (Google Text to Speech) is an interface that transforms text into audio and saves into a . mp3
To install run the PIP:
pip install gTTS
Use:
from gtts import gTTS
tts = gTTS(text='Hello', lang='en')
tts.save("hello.mp3") #Salva o arquivo
In Portuguese:
from gtts import gTTS
tts = gTTS(text='Olá', lang='pt-br')
tts.save("ola.mp3") #Salva o arquivo
Supported languages: https://github.com/pndurette/gTTS#lang_list