繁体   English   中英

如何在 Google colab 中循环播放音频

[英]How to play Audio in loop in Google colab

我试图在 google colab 中循环运行音频,但它没有给我任何 output

  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)

Output 我想要的是它应该听起来你好 aniket 你好 sachin 请帮忙

您只需要使用“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)##

您可以在自动播放上使用猴子补丁音频来完成它:

Audio.autoplay_attr = lambda x: 'autoplay="autoplay" loop="loop"'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM