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

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

我想在 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 Pleas help

最佳答案

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

关于python - 如何在 Google colab 中循环播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65960537/

相关文章:

python - 在 Python 中丢弃具有最大容量的 FIFO 队列?

python - Django:模拟模型上的字段

python - 如何修复 numpy TypeError : unsupported operand type(s) for -: 'str' and 'str'

python - Google colab 中的时态数据存储在哪里?

ffmpeg - 如何在 google colab 中安装包 ffmpeg

c# - 使用其他语音时的文本到语音 SAPI5 AccessViolationException

c# - 如何在 C# 中更改语音合成器的语音或速度

python - 使用python将pyspark数据框中的多列合并为一列

python - 如何在 plotly 时间序列图表中添加和定义多条线?

python - 权限被拒绝 : 403 Request had insufficient authentication scopes