[英]Not able to use gTTS module in python
I tried using gTTS module in python for text to speech.我尝试在 python 中使用 gTTS 模块进行文本到语音转换。 However, when I run the code, I am not able to hear anything.但是,当我运行代码时,我听不到任何声音。 I referred to https://pypi.org/project/gTTS/ for the installation and documentation.我参考了https://pypi.org/project/gTTS/的安装和文档。
(I am using Ubuntu) (我使用的是 Ubuntu)
My code:我的代码:
from gtts import gTTS
tts = gTTS('hello')
tts.save('hello.mp3')
I am not getting any errors.我没有收到任何错误。 However, I am not able to hear anything.但是,我什么也听不到。
gTTS only converts your text to speech and saves it. gTTS 只会将您的文本转换为语音并保存。 You have to use another module like playsound or use an audio player to play your audio file.您必须使用其他模块,例如 playsound 或使用音频播放器来播放您的音频文件。 For example:例如:
from gtts import gTTS
import playsound
tts = gTTS(text='hello', lang='en')
tts.save("hello.mp3")
playsound.playsound("hello.mp3")
gTTS only converts your text to speech and saves it with the help of "tts" API. gTTS 仅将您的文本转换为语音并在“tts”API 的帮助下进行保存。 You have to use another module like playsound to directly play your audio file.您必须使用另一个模块(如 playsound)来直接播放您的音频文件。 For example:例如:
from gtts import gTTS
import playsound
import os
tts = gTTS(text='hello', lang='en')
tts.save("hello.mp3")
playsound.playsound("hello.mp3")
os.remove("hello.mp3")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.