Ask coding questions

← Back to all posts
How do I play sounds from files?
brogen (42)

I want to try to play a sound but I don't know how.

Commentshotnewtop
GABELACANLALE (18)

Very good question.

from replit import audio
audio.playfile('myfile.mp3')
brogen (42)

This question will remain unsolved. ;(

brogen (42)

My teacher looked and there's no way to do it.

Bookie0 (4983)

use repl.it audio here are the docs.
I made a game with repl.it audio, check it out here. Look at the code especially in music.py to learn more. Good Luck! :)

TalinSharma (53)

Hi,
Great Question! The code is below! If this helped, mark it as correct!

For MP3 & WAV. Files:

from playsound import playsound

playsound('myfile.wav')

Tell me if you need code for a different file format!

brogen (42)

@TalinSharma OK thanks. I couldn't get it. 😆

brogen (42)

@TalinSharma
one more thing how would I play them after imported and variables assigned?

brogen (42)

@TalinSharma
How can I play the sounds?

TalinSharma (53)

Just import at the top and put the second line of code after the variables. Like this:

from playsound import playsound
#YOUR CODE HERE
playsound('myfile.wav')

Hope it helped!

brogen (42)

@TalinSharma
What code would I use to play it? Like a print command? Or maybe a run command?

TalinSharma (53)

From the module playsound you import playsound... Then you just put in playsound() and in the parenthesis the file's name! @brogen

brogen (42)

@TalinSharma
Still won't play try running it.

SixBeeps (3504)

@TalinSharma The playsound package does not work on Repl.it.

@brogen Use the Repl.it Audio Library

TalinSharma (53)

Oh. Sorry I didn't know! @SixBeeps

brogen (42)

@SixBeeps I'm just giving up. I can't find anything to help.

realTronsi (840)

@TalinSharma hi, please do not ask for cycles, thanks!

TalinSharma (53)

I just asked for marking it correct but sure... @realTronsi

SixBeeps (3504)

@TalinSharma Technically is asking for cycles

TalinSharma (53)

I know but like 90% of people do it... Sorry! @SixBeeps

CodingCactus (3190)

@TalinSharma well tell all of those 90% of people to stop when you see it, or at least report thanks! : )