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

末鹿安然 提交于 2019-12-18 11:09:58

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/48438686/realistic-text-to-speech-with-python-that-doesnt-require-internet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!