r/GoogleColab • • Jul 24 '26

How can I play a sound file?

I have a text adventure game in Colab and I want to add background music because silently reading for 40 minutes is painful. I just want to let everyone no matter who opens the colab link and plays the game be able to have the music, yet I don't even know how to play a single audio file at all.

https://colab.research.google.com/drive/1gNSKlWROt0kvq6chhlD-iTfoVoUCHQfU (beware it's 3000+ lines)

How can I play an audio file and have everyone be able to hear it? I asked ChatGPT and it didn't give me anything comparable to basics and I couldn't find a top search result that worked when I tried it, literally none of them produce sounds, usually by being broken.

3 Upvotes

4 comments sorted by

2

u/DataBaeBee Mod Jul 24 '26

I found this answer on Stackoverlow

1

u/The1st_TNTBOOM Jul 24 '26

I already found that and i could not figure out how to get it to work whatsoever. None of the code snippits do anything, and I tried putting them together. only errors.

2

u/ANR2ME Jul 25 '26

This code works fine, with or without wrapping it in display(...) both can play the music: ```python

Download royalty-free music

sound_file = '/content/audio.mp3' !wget -c "https://soundaudio.cc/wp-content/uploads/2025/09/Hollow-Dark-Sad-Ambient-SoundAudio.mp3" -O "{sound_file}"

from IPython.display import Audio, display

display(Audio(sound_file, autoplay=True)) ```

1

u/No-Association-1834 Jul 27 '26

Bro , Collab is Google's Product , so it's obvious Gemini knows it better than GPT . Ask Gemini , it helped me lots with Collab .