如何在 Google Colab 中进行文本到语音的转换?

How to do text to speech conversion in Google Colab?

我知道 Google Text to Speech 这样的库。但是,这在 Colab 中不起作用。我最近在 Colab https://colab.research.google.com/github/tugstugi/pytorch-dc-tts/blob/master/notebooks/EnglishTTS.ipynb#scrollTo=jLU2p4Gq_12d 中遇到了一个复杂的笔记本,我们可以在其中将文本转换为语音。但是,在 Google Colab 中是否有使用 Google Text to Speech 或其他库的简单方法?

这样我提供了一个 String- "My name is XYZ" 并且它在 Colab 笔记本中被说出来了。 (这发生在我提供的 link 中,但相当复杂)。

P.S。我希望尽可能自动播放音频,就像 GTTS 那样。在这个笔记本中,我们需要点击播放按钮来输出语音。

我终于解决了这个问题。一种简单的方法是结合使用 Google Text to Speech 和 IPython 的 Audio 方法。以下代码片段只需几行即可完成这项工作!您还可以查看我在此处创建的 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.