Ask coding questions

← Back to all posts
Play sound in a repl with Python
RojerGS (21)

Hello everyone,

In light of the new challenge I was going to create something with Python (and pygame) and it would involve playing sounds, but turns out I cannot use the pygame.mixer module. Is it because I am a n00b?
Either way, is there any (relatively simple) way of playing audio in a Python repl?


Answered by 21natzil (1199) [earned 5 cycles]
View Answer
21natzil (1199)

Sorry, but does not support sound at the moment. Sorry for the inconvenience. This feature is planned and will be added in time.

RojerGS (21)

@21natzil Ok, then there is something I am missing; this music box has sound when I play it! But you said that does not support sound, so what is the distinction here?

21natzil (1199)

@RojerGS When creating a website on, you're only restricted by your browser. When working with Python / Pygame repls, sound is not supported, sorry for the confusion.

MarkusStepanovs (7)

I needed an alert tone for a project and found a very ugly solution:

print ('\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a')

But hey, it works!

alan_oregano (1)

@finlaycameron06 It takes advantage of the "\a" bell escape sequence which makes a sound in the python terminal

TanayGupta1 (0)

@MarkusStepanovs It doesn't work for me. Like it doesn't play the sound. Did they change it so it doensn't work anymore cuz it has ben 7 months since u said this.

TanayGupta1 (0)

@MarkusStepanovs It doesnt work for some reason. How do I make it work?

atharva12345 (3)

please insert the audio system because I loved so much and don't wanna quit this by just 1 excuse please add it as soon as you can.

Hidere0225 (1)

cool. hope it turns out good bro

26pwong (4)

@MarkusStepanovs Instead of printing it repeatedly, you can use a loop.
This is what I made:

import time

def beep():
print ("\a")

for i in range(10):

It works, but it prints a new line every time it plays the sound. Anyone know a better solution?

alan_oregano (1)


import time

def beep(interval = 0.1, frequency = 10):
    for i in range(frequency):
        print ("\a", end = "\r")


This sets the end argument of the print statement to a carriage return escape sequence.
Moving it back to the start of the line instead of a new one by default.

You could also add parameters to the function to control the interval and frequency of the bell/alert tone.

chough (0)

It seems that they have built an explorer feature to solve this! More info here.