Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realistic text to speech with Python that doesn't require internet? [closed]

Tags:

I'm trying to create an artificially intelligent program (nothing really big or special) and I wanted it to have a voice (who wouldn't?). I've looked into espeak, festival, gTTS and they're nice and usable, but not realistic enough for me to really be proud of, if that makes sense. I've been looking for something more realistic. Like this

from gtts import gTTS  tts = gTTS(text='what to say', lang='en') tts.save('/path/to/file.mp3') 

gTTS works fine. I love it. It's realistic, but it requires Internet.. The issue is, I want my application to be as independent as possible. And I hate depending on Internet access.

Are there any other options?

PS: I'm currently running Linux, so your OS might have a different solution.

like image 272
Edgecase Avatar asked Jan 25 '18 08:01

Edgecase


People also ask

Does gTTS work offline?

Speech Recognition (Speech-to-Text aka STT) Speaking Email uses the Google TTS engine feature known as "Google Voice Typing" for dictation and commands. It works using the offline engine, so you need to download the offline voice (even if you are always online - as we have found the offline engine to be more accurate).

Is pyttsx3 offline?

pyttsx3 is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline, and is compatible with both Python 2 and 3.

Which is better pyttsx3 or gTTS?

gTTS which works perfectly in python3 but it needs internet connection to work since it relies on google to get the audio data. But Pyttsx is completely offline and works seemlesly and has multiple tts-engine support.


1 Answers

Try to use pyttsx3 2.5, according the documentation:

gTTS which works perfectly in python3 but it needs internet connection to work since it relies on google to get the audio data.But Pyttsx is completely offline and works seemlesly and has multiple tts-engine support.

Works for Python 2 and 3

To install it:

pip install pyttsx3 

Using it should be as simple as:

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

Edit 1 - Changing the voice

To get a less robotic voice you can try to change the voice as follows:

engine.setProperty('voice', voice.id) 

To get the available voices

voices = engine.getProperty('voices') 

You can try the different available voices as explained in this question: Changing the voice with PYTTSX module in python.

Edit 2 - Selecting speech engine

The library supports the following engines:

  • sapi5 - SAPI5 on Windows
  • nsss - NSSpeechSynthesizer on Mac OS X
  • espeak - eSpeak on every other platform

If espeak is not very natural you can try sapi5 if you are on Windows or nsss if you are on Mac OS X.

You can specify the engine in the init method, e.g.:

pyttsx3.init(driverName='sapi5')  

More info here: http://pyttsx3.readthedocs.io/en/latest/engine.html

like image 57
Isma Avatar answered Oct 04 '22 15:10

Isma