【问题标题】:How to do text to speech conversion in Google Colab?如何在 Google Colab 中进行文本到语音的转换?
【发布时间】:2019-12-25 01:06:54
【问题描述】:

我知道 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 一样自动播放音频。在这个笔记本中,我们需要点击语音输出的播放按钮。

【问题讨论】:

    标签: python google-cloud-platform text-to-speech google-colaboratory gtts


    【解决方案1】:

    我终于解决了这个问题。一种简单的方法是将 Google Text to Speech 与 IPython 的 Audio 方法结合使用。以下代码 sn -p 可以在几行内为您完成这项工作!您还可以查看我在这里创建的 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.
    

    【讨论】:

    • 但这是两件不同的事情,您的第一个链接是自定义训练语音,而不是谷歌 tts
    • @user3548161-我不确定您的意思-此问题(和答案)根据用户在 Colab 中提供的自定义文本解决自定义语音。为此,它通过导入相关方法来生成用户给定自定义文本的音频(语音)文件,从而使用 gtts。希望这能解决您的问题。
    猜你喜欢
    • 2011-01-17
    • 1970-01-01
    • 2016-09-07
    • 2011-05-15
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    • 2014-07-02
    • 1970-01-01
    相关资源
    最近更新 更多