【发布时间】:2016-07-19 07:49:44
【问题描述】:
Windows 10-64 位
我正在尝试使用一些文本转语音工具从 .txt 文档的行中读取文本,如下所示:
pyttsx 也是这样:
import pyttsx
engine = pyttsx.init()
engine.say('my voice')
engine.runAndWait()
我收到了这个错误:
Traceback (most recent call last):
File "...", line 1, in <module>
import pyttsx
File "/.../pyttsx/__init__.py", line 18, in <module>
from engine import Engine
ImportError: No module named 'engine'
现在是 gTTS,可以作为 gtts_token 使用,那么如何使用呢?因为这种方式模块无法识别:
import gtts
blabla = ("my voice")
tts = gtts.gTTS(text=blabla, lang='en')
tts.save("C:/rec.mp3")
或:
from gtts import gTTS
blabla = ("my voice")
tts = gTTS(text=blabla, lang='en')
tts.save("C:/rec.mp3")
错误:
import gtts
ImportError: No module named 'gtts'
我也想尝试使用 espeak 但不知道如何安装它,它可以通过 pip install 获得还是我必须以其他方式安装它才能尝试:
import subprocess
text = '"my voice"'
subprocess.call('espeak '+text, shell=True)
或:
import os
os.system("espeak 'my voice'")
所以我正在尝试找到一些解决方案,但我尝试的所有方法在这里都不起作用......
【问题讨论】:
-
查看pip: dealing with multiple Python versions? 并确保将
gtts安装到您正在使用的同一版本的python。 -
pyttsx 似乎不是为 python 3 设计的,请参阅 pyttsx: No module named 'engine' 但那里的答案并没有让它对我有用。
-
安装
espeak只需转到sourceforge site 的下载部分,一旦安装,您提供的代码应该可以工作,但我不确定,因为我使用的是mac。祝你好运! -
'嗨,谢谢,pyttsx 没有任何帮助。在您的帮助下 gtts 工作,从 txt 文件
blabla = (line[0])获取文本,但首先创建 mp3 文件,然后如果我想听,我必须调用这个 mp3,所以这很好,但在我的情况下,我想避免任何音频文件,只需阅读从文本文件。是否有可能以某种方式使用谷歌语音来阅读我的文本文件?我还没有尝试过 espeak ......好吧,如果我只能使用 gTTS 现在我在此处详细描述的 mp3 文件有问题,因为现在这是另一个问题stackoverflow.com/questions/36347786/how-to-play-mp3-from-gtts
标签: python-3.x text-to-speech google-text-to-speech espeak pyttsx