Play sound in a repl with Python
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?
Thanks!
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!
@MarkusStepanovs how does it work?
@finlaycameron06 It takes advantage of the "\a" bell escape sequence which makes a sound in the repl.it python terminal
https://en.wikipedia.org/wiki/Bell_character
@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.
@MarkusStepanovs It doesnt work for some reason. How do I make it work?
works just fine for me!!
@MarkusStepanovs
please insert the audio system because I loved repl.it so much and don't wanna quit this by just 1 excuse please add it as soon as you can.
Thanks.
cool. hope it turns out good bro
@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):
beep()
time.sleep(0.1)
It works, but it prints a new line every time it plays the sound. Anyone know a better solution?
import time def beep(interval = 0.1, frequency = 10): for i in range(frequency): print ("\a", end = "\r") time.sleep(interval) beep()
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.
pl
Sorry, but repl.it does not support sound at the moment. Sorry for the inconvenience. This feature is planned and will be added in time.
@21natzil Ok, then there is something I am missing; this music box has sound when I play it! But you said that repl.it does not support sound, so what is the distinction here?
@RojerGS When creating a website on repl.it, you're only restricted by your browser. When working with Python / Pygame repls, sound is not supported, sorry for the confusion.
@21natzil 2years and still nothing done?