Search code examples
pythongoogle-colaboratory

Playing sound in Google Colab


Hi so i have code which gives the answer in form of speech. I am using this code:

audio.save("audio.wav") 
sound_file = '/content/audio.wav'
Audio(sound_file, autoplay=True)

Now the code plays file all well but if I play in a separate cell. But if I put this code in between my code, it doesn't work. Any ideas?


Solution

  • Wrap it in display():

    from IPython.display import Audio, display
    
    display(Audio(sound_file, autoplay=True))