Is it possible to make a "text for voice" with Pyqt?

2

I'm learning to mess with Pyqt. I'm putting together 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 "transform" a text into a voice.

I was able 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 (text to speech)?

    
asked by anonymous 27.10.2016 / 20:08

1 answer

4

I believe that PyQt4 does not support this, and pyqt5 may only come in support in the future (apparently QtSpeech is very recent), so using PyQt is not an option, however I found this: link (it's a bit outdate 2012), but it's cross-platform and support Python2 and this link

pyttsx

Drivers required per environment:

  • nsss - NSSpeechSynthesizer in Mac OS X 10.5 and higher

    Details: link

  • sapi5 - SAPI5 on Windows

    Download at link

  • espeak - eSpeak in distros linux

    Install on Debian and Ubuntu:

    sudo apt-get install espeak
    

    To install manually: link

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 the releases of github link and maybe in pip only version 1.1 appears, but in the doc already informs about the version 1.2, in the case it would just install this link manually

The 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 the 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 pyttsx.voice.Voice class, which has the following properties:

  • .age returns age in years as integer
  • .gender returns a String that contains the voice genre being female , male or neutral
  • .id is the voice identifier to use in pyttsx.engine.Engine.setPropertyValue()
  • .languages returns a list of strings that shows the languages supported by the voice
  • .name returns a String containing a "human" name to help assimilate language, gender, etc.

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

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

Windows also seems to already have some including the ones in Portuguese:

  

What I liked about Espeek is that it has support for Windows and MacOSX, I just do not know if lib is compatible.

gTTS

gTTS (Google Text to Speech) is an interface that transforms text into audio and saves it to an .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

In Portuguese:

from gtts import gTTS

tts = gTTS(text='Olá', lang='pt-br')

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

Supported Languages: link

    
27.10.2016 / 20:36