gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 23:56:28 25 4
gpt4 key购买 nike

我知道像 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 或其他库的简单方法?

我提供了一个字符串- "My name is XYZ" 并且它在 Colab 笔记本中被说出来。 (这发生在我提供的链接中,但非常复杂)。

附言我希望尽可能自动播放音频,就像 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.

关于python - 如何在 Google Colab 中进行文本到语音的转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57563060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com