Ask coding questions

← Back to all posts
Playing audio in Python
noway15 (97)

Exactly what it sounds like. I know that I need audio from replit, but after that I'm kinda confused on what to do.

Comments
hotnewtop
FloCal35 (667)

Both Coder100 and OldWizard209 (I won't ping them) answered you question but keep in mind that

Replit audio in python does not work for people viewing your projects


Because they are so new, spotlight pages can't play audio yet. So if you want to post it on the Apps page or if you want to share it with someone, instead of hearing the wonderful audio file, they will see an anoying error that stops the program

Coder100 (18071)

yeah, its in the docs, which are a bit hard to access:
https://docs.replit.com/tutorials/12-audio

OldWizard209 (1498)

Its all in the Docs.

First import replit and make sure to upload the sound file as .mp3 or .wav . Type this code:

from replit import audio
import time

audio.play_file("download.mp3")
time.sleep(10)

The time.sleep in the end is there because once the file is executed, repl abruptly stops. So it is there so that the audio can run.