使用不需要互联网的 Python 进行逼真的文本到语音转换? [英] Realistic text to speech with Python that doesn't require internet?

查看:119
本文介绍了使用不需要互联网的 Python 进行逼真的文本到语音转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个人工智能程序(没什么特别大的或特别的),我希望它有声音(谁不想?).我已经研究过 espeak、festival、gTTS,它们很好且可用,但不够现实让我感到自豪,如果这是有道理的.我一直在寻找更现实的东西.像这样

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 工作正常.我喜欢它.这是现实的,但它需要互联网.. 问题是,我希望我的应用程序尽可能独立.我讨厌依赖互联网访问.

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.

还有其他选择吗?

PS:我目前运行的是 Linux,所以您的操作系统可能有不同的解决方案.

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

推荐答案

尝试使用 pyttsx3 2.5,根据 文档:

Try to use pyttsx3 2.5, according the documentation:

gTTS 在 python3 中完美运行,但它需要互联网连接才能工作,因为它依赖于 google 来获取音频数据.但 Pyttsx 完全脱机并且工作正常,并且具有多个 tts 引擎支持.

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.

适用于 Python 2 和 3

Works for Python 2 and 3

安装:

pip install pyttsx3

使用应该很简单:

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

编辑 1 - 改变声音

要获得不那么机械化的声音,您可以尝试如下更改声音:

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

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

获取可用的声音

voices = engine.getProperty('voices')

您可以按照此问题中的说明尝试不同的可用语音:用python中的PYTTSX模块改变声音.

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

编辑 2 - 选择语音引擎

该库支持以下引擎:

  • sapi5 - Windows 上的 SAPI5
  • nsss - Mac OS X 上的 NSSpeechSynthesizer
  • espeak - 在其他所有平台上使用 eSpeak

如果 espeak 不是很自然,您可以在 Windows 上尝试 sapi5,如果您在 Mac OS X 上,可以尝试 nsss.

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

您可以在init方法中指定引擎,例如:

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

pyttsx3.init(driverName='sapi5') 

更多信息在这里:http://pyttsx3.readthedocs.io/en/latest/引擎.html

这篇关于使用不需要互联网的 Python 进行逼真的文本到语音转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆