How to add audio to replit

Question:
How do you add audio into replit

Repl link:
https://replit.com/@PrestonCurtis1/Timer#main.py

code snippet

from playsound import playsound
playsound(“/audio/timer.mp3”)
this is what i did

I’m not great at Python, but a quick Google search led me to this: https://pencilprogrammer.com/play-mp3-song-using-python/

# use vlc to play audio
import vlc
# use sleep to wait until audio finishes playing
import time

# get the audio
audio = vlc.MediaPlayer("timer.mp3")
# start playing the audio
audio.play()
# wait until the audio finishes playing
time.sleep(12)
# stop playing the audio
audio.stop()
1 Like

Here’s a tutorial for playing audio Replit:
https://docs.replit.com/programming-ide/playing-audio-replit

4 Likes

I will try that THX.

i will look at that.

I tryed your code piece and this is what happened

Any other Suggestions from anyone

I’ve been wondering this too. I tried to make a jukebox app, but it sends my CPU usage to red instantly and plays nothing. On other repls I have seen the audio work.
https://replit.com/@EpicPhelan/Jukebox-1#main.py

Can you give an example to a repl that does play sound? I couldn’t find any

Play sound is quite difficult to use since you need to import other things and install more things on the shell. I recommend searching on the replit docs about how to add audio in a relp. There is a python and node repl! This might be the solution.

I’ve never been sucsessful adding audio in repls. It is a very difficult job, I honestly think that it doesn’t work!

The replit docs has 2 ways, one for js and one for python. And both are currently broken

I think the error is that Repl doesn’t understand that you have an audio file in your repl and doesn’t play it.

I thinl it’s the libaries which are not correct.

I think its either something w/ the modules/libraries or repl not realizing there is an audio file.

Yeah! Those libaries aren’t reliable enough

Hi. This Repl works. https://replit.com/@SandeepGandham/Audio-Player

You will have to fork it first. When you first run the Repl it will ask you to confirm that you are happy for audio to be played.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.