如何在googlecolab中进行文本到语音转换?

2024-10-04 01:24:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道像谷歌文字语音转换这样的图书馆。然而,这在Colab中并不适用。我最近在Colab https://colab.research.google.com/github/tugstugi/pytorch-dc-tts/blob/master/notebooks/EnglishTTS.ipynb#scrollTo=jLU2p4Gq_12d里看到了一个复杂的笔记本,我们可以在里面把文本转换成语音。但是,有没有一种简单的方法可以在googlecolab中使用Google文本语音转换或其他库?在

这样我就提供了一个字符串-"My name is XYZ",它在Colab笔记本中被读出。(这发生在我提供的链接中,但相当复杂)。在

另外,如果可能的话,我希望音频可以自动播放,就像GTTS那样。在本笔记本中,我们需要单击播放按钮进行语音输出。在


Tags: https文本githubcom图书馆google笔记本语音
1条回答
网友
1楼 · 发布于 2024-10-04 01:24:11

我终于解决了。一个简单的方法是将Google文本语音转换与IPython的音频方法结合使用。下面的代码片段只需几行就可以完成这项工作!你也可以看看我在这里创建的Colab笔记本https://colab.research.google.com/drive/1wMg9ZV2WH2ugAC-6iZLUkEH3V6XxI3H-演示了这一点。在

from gtts import gTTS #Import Google Text to Speech
from IPython.display import Audio #Import Audio method from IPython's Display Class
tts = gTTS('hello joyjit') #Provide the string to convert to speech
tts.save('1.wav') #save the string converted to speech as a .wav file
sound_file = '1.wav'
Audio(sound_file, autoplay=True) 

#Autoplay = True will play the sound automatically
#If you would not like to play the sound automatically, simply pass Autoplay = False.

相关问题 更多 >