Is it possible to make a "text to speech" with Pyqt?

I'm learning how to mess with Pyqt. I am setting up a simple application where there will be a voice notification when a new request is available.

I would like my application written in Pyqt4 to be able to" transform " a text into speech.

I managed to do this with HTML5 and Javascript, but now I would like to know if there is any way to do something like Pyqt.

Is there any functionality in Pyqt or that can be used together with Pyqt to do Text to Speech ?

Author: Wallace Maxters, 2016-10-27

1 answers

I believe that PyQt4 does not have support for this, and pyqt5 may only come to support in more 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 (it's a little outdated 2012), but it's cross-platform and Python2 support and this https://github.com/pndurette/gTTS

Pyttsx

Drivers required by Environment:

Then you can install it via PIP:

pip install pyttsx

See an example:

import pyttsx

engine = pyttsx.init()
engine.say('Hello World!')
engine.runAndWait()

Links:

In github releases https://github.com/RapidWareTech/pyttsx/releases and maybe in pip only version 1.1 will appear, but in the doc already informs about Version 1.2, in case it would only install this https://github.com/RapidWareTech/pyttsx/tree/master/pyttsx manually

The lib 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 you 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 voice genre and can be female, male or neutral
  • .id is the voice identifier to use in pyttsx.engine.Engine.setPropertyValue()
  • .languages returns a list string that shows the languages supported by the voice
  • .name returns a String containing a "human" name to help assimilate language, gender and language. , etc

In this case you can use voice.languages to get the Portuguese language ID and thus set it.

If there is no language in Portuguese in the list it is because the driver does not support or does not have the language installed, in the case of linux o e eSpeak already comes with several languages:

Windows also seems to already have some including the em English:

What I liked about espeek is that it has support for Windows and MacOSX, I just don't know if the lib is compatible


GTTS

GTTS (Google Text To Speech) is an interface that turns text into audio and saves to a .mp3

To install run PIP:

pip install gTTS

Usage:

from gtts import gTTS

tts = gTTS(text='Hello', lang='en')

tts.save("hello.mp3") #Salva o arquivo

Em English:

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

 4
Author: Guilherme Nascimento, 2016-10-28 17:20:15