在 Python 3 下运行的文本转语音 (TTS) 模块 [英] Text-to-speech (TTS) module that works under Python 3

查看:60
本文介绍了在 Python 3 下运行的文本转语音 (TTS) 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过 PyTTS(已弃用)和 PyTTSx(最推荐的)和两个 Google TTS 解决方案(gTTS 和另一个名为 Hung Truong 的人的解决方案),但它们都没有在 Python 3.4 下工作.似乎它们还没有被移植到 3.x.

I have tried PyTTS (deprecated) and PyTTSx (the most recommended) and two Google TTS solutions (gTTS and another one by some guy named Hung Truong) but none of them worked under Python 3.4. It seems they haven't been ported to 3.x.

我在 StackOverflow 和 Google 上搜索过这里,但所有建议的 TTS 解决方案都不适用于 Python 3.我使用的是 Windows 7.

I searched here on StackOverflow and Google, but all the proposed TTS solutions don't work under Python 3. I'm on Windows 7.

推荐答案

Reddit 上的一位用户 找到了解决方案.

A user on Reddit found a solution.

原来 gTTS 在 Python 3.x 下工作,是我导入的模块错误.

Turns out that gTTS works under Python 3.x, it was me that was importing the module wrong.

我正在使用:

import gtts
blabla = ("Spoken text")
tts = gTTS(text=blabla, lang='en')
tts.save("C:/test.mp3")

导致以下错误:

NameError: name 'gTTS' is not defined

当正确的方法是:

from gtts import gTTS
blabla = ("Spoken text")
tts = gTTS(text=blabla, lang='en')
tts.save("C:/test.mp3")

这篇关于在 Python 3 下运行的文本转语音 (TTS) 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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