【问题标题】:How to play Audio in loop in Google colab如何在 Google colab 中循环播放音频
【发布时间】:2025-12-12 05:05:02
【问题描述】:

我正在尝试在 google colab 中循环运行音频,但它没有给 mi 任何输出

  from gtts import gTTS
  from IPython.display import Audio

  for voice in ["Aniket","sachin"]: 
     tts = gTTS("Hello {}".format(voice)) 
     tts.save('1.wav')
     sound_file = '1.wav'
     Audio(sound_file, autoplay=True)

输出我想要的是它应该听起来 hello aniket hello sachin 请帮助

【问题讨论】:

    标签: python google-colaboratory text-to-speech google-text-to-speech


    【解决方案1】:

    你只需要使用“IPython.display.display”方法如下:

      from gtts import gTTS
      from IPython.display import Audio
      from IPython.display import display
      for voice in ["Aniket","sachin"]: 
          tts = gTTS("Hello {}".format(voice)) 
          tts.save('1.wav')
          sound_file = '1.wav'
          wn = Audio(sound_file, autoplay=True) ##
          display(wn)##
    

    【讨论】: