3

I ma trying to run the Audio in loop in google colab but it is not giving mi any 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 what I want is it should sound hello aniket hello sachin Pleas help

2 Answers2

4

You only need to use "IPython.display.display" method as follows :

  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)##
MrPs
  • 41
  • 4
0

you can monkey patch audio to do it piggybacking on the autoplay:

a = Audio(...)
a.autoplay_attr = lambda: 'autoplay="autoplay" loop="loop"'
o17t H1H' S'k
  • 2,541
  • 5
  • 31
  • 52