Ask coding questions

← Back to all posts
Need some help with playing audio on repl.it [python]
Bookie0 (4977)

Hi all,

I need some help with playing an mp3 download on repl.it in python. I tried using the new audio feature (here if you want), and copied this code:

but when I type loop, it gives this error:

Traceback (most recent call last):
  File "main.py", line 33, in <module>
    main()
  File "main.py", line 29, in main
    source.set_loop(True, source.loops_remaining + 1)
TypeError: set_loop() takes 2 positional arguments but 3 were given

So yea any help greatly appreciated, or if you have another method different than this one that could help, please tell me.
btw I'm trying to get the audio.mp3 to play, you'll see it in the files section.

also you might need to have explorer mode turned on for it to work.

Thank you so much! :)

EDIT: Think I got it working, thanks to help from aa and cc
Try running the repl to see if it works for you! :)

Commentshotnewtop
MocaCDeveloper (523)

maybe try:

source.loops_remaining += 1
source.set_loop(True, source.loops_remaining)
Bookie0 (4977)

Hi @MocaCDeveloper

thanks for your response, do you mean like this?

I tried it, and it gave me this errorL

thanks!

MocaCDeveloper (523)

@Bookie0
Hm. Report it as a bug then. That's strange.

Bookie0 (4977)

yea, I'll probably do that, thanks anyways! :)@MocaCDeveloper

MocaCDeveloper (523)

@Bookie0
Anytime. Doing the += should work..that's really odd

hello4691 (31)

I heard that audio wasn't available to repl yet. I don't know if this is true or not.

Bookie0 (4977)

hi, yes its available, check the link on my post! ;) @hello4691

RYANTADIPARTHI (3231)

Bookie0, if you want to play music, then you just have to connect the file to HTML, and then write this code in -- <audio controls><source src=""</audio>. In the source, you can put your file. Hope this helps. If it did, please mark my answer! Thanks!

Bookie0 (4977)

@RYANTADIPARTHI hi, i only want it for python, and I solved it now with some help of others. Thanks anyways! ;)

RYANTADIPARTHI (3231)

@Bookie0 np. But if this helped, please marked my answer. it's your choice though. Thanks anyways! And you're welcome!

Bookie0 (4977)

@RYANTADIPARTHI lol it didnt really help me..

BD103 (92)

You must be an explorer to first do this ;)

BD103 (92)

Ok. The code that replit uses is bugged, I'm pretty sure it's not the library. Maybe check out the docs for the replit module and try creating a program from scratch. @Bookie0

Bookie0 (4977)

yea, but anyways I figured out a way to work now (I think) @BD103

BD103 (92)

NICE

oops still have caps lock from playing oblivion lol :)

@Bookie0

Bookie0 (4977)

@AllAwesome497 would you be able to help? thanks!

Coder100 (12434)

Yes, it is a repl.it bug (citation needed). Whatever the case is, they changed the function signature (citation needed), and thus breaking it. You can look in github to hopefully find out why (citation needed).

Anyways, be patient and ping aa :)

Bookie0 (4977)

@Coder100 Hum ok, I guess i'll to ping aa and ask him if he knows.

Bookie0 (4977)

lool btw he said its not a bug.. @Coder100

Coder100 (12434)

wait what did he say then @Bookie0

Bookie0 (4977)

still not very sure lol, check the help and reviews on the repl.it discord @Coder100

fuzzyastrocat (1461)

Notice in their tutorial they do something slightly different. Try

loops += 1

instead of

source.loops_remaining += 1

Then, instead of

source.set_loop(True, source.loops_remaining)

do

source.set_loop(source.loops_remaining + 1)
Bookie0 (4977)

hi, @fuzzyastrocat

yea I know the code is different, this is because I tried to do what @MocaCDeveloper suggested, but it still didn't work. What you propose also didn't work, it gave the error that I put in the description of my post

thanks!

fuzzyastrocat (1461)

@Bookie0 Really? Are you sure you did exactly what I said on the last one (source.set_loop(source.loops_remaining + 1), ie omitting the True)?

Bookie0 (4977)

@fuzzyastrocat

yup, like this right?

Anyways, Coder100 said it's a bug [citation needed], but thanks anyway! :)

fuzzyastrocat (1461)

@Bookie0 Hmm, weird. I don't get the error when I do it that way (also why is there no closing paren).

I doubt that, I think it's just that the docs are out-of-date. It works fine for me when I do what I suggested above.

Bookie0 (4977)

@fuzzyastrocat ah yes for the parenthesis.

also you say it works fine for you; do you manage to hear the audio mp3? (its La danse macabre of Camille Saint-saens btw)?

fuzzyastrocat (1461)

@Bookie0 At some point I was able to get the audio to play. I stupidly deleted the repl thinking I knew how to solve it, but now I can't replicate it :P

Bookie0 (4977)

@fuzzyastrocat oh, oof. Do you know what you did to make it work? YOu could also try going to the CLI to restore the repl?

JBYT27 (1150)

Though I do lots of Python, I haven't tried audio-playing yet -_-|| Looks like pretty advanced code? Also, idk what is the problem... EDIT: sry for bothering you EDIT: nvm?

Bookie0 (4977)

Hi,

I think I stated the problem pretty clearly in the descript, but anyways the problem is when I run the code it says there is a positional argument. you can check the docs I linked for more info...

@JBYT27

JBYT27 (1150)

@Bookie0 oh, got it. hrmmm... tbh, idk what to do. But maybe try doing... hrmmm... Honestly, I don't know what to do, sry. But maybe try asking others. Sry again. EDIT: This has nothing to do with your question, but maybe try clearing the page? It gets very messy

Bookie0 (4977)

its ok, someone else will hopefull help lol

also wdym by clearing the page? like what page? You mean the console?

@JBYT27

DynamicSquid (4532)

Bookie... I think the tutorial file is too large, I won't load for me... I had to download it as a zip file to view it lol. I can work on the ANSI colour codes section and put it to a new file on the repl

Bookie0 (4977)

@DynamicSquid

Humm lol the tutorial file works fine for me, maybe try reloading page several times? I just waited about 20 seconds, then seems to load. But if it still doesn't work, here are some ANSI codes btw that I've used before, you could find them useful! :)

/*
	printf("\n");
    printf("\x1B[31mTexting\033[0m\t\t"); 
    printf("\x1B[32mTexting\033[0m\t\t"); 
    printf("\x1B[33mTexting\033[0m\t\t"); 
    printf("\x1B[34mTexting\033[0m\t\t");
    printf("\x1B[35mTexting\033[0m\n");

    printf("\x1B[36mTexting\033[0m\t\t");
    printf("\x1B[36mTexting\033[0m\t\t");
    printf("\x1B[36mTexting\033[0m\t\t");
    printf("\x1B[37mTexting\033[0m\t\t");
    printf("\x1B[93mTexting\033[0m\n");

    printf("\033[3;42;30mTexting\033[0m\t\t");
    printf("\033[3;43;30mTexting\033[0m\t\t");
    printf("\033[3;44;30mTexting\033[0m\t\t");
    printf("\033[3;104;30mTexting\033[0m\t\t");
    printf("\033[3;100;30mTexting\033[0m\n");

    printf("\033[3;47;35mTexting\033[0m\t\t");
    printf("\033[2;47;35mTexting\033[0m\t\t");
    printf("\033[1;47;35mTexting\033[0m\t\t");
    printf("\t\t");
    printf("\n");

*/

I'll work when I can on some small useful programs! :)

Bookie0 (4977)

@DynamicSquid also, I used the ansi colors in my previous comment here (btw I know the repl is a bit broken not really working that well, but you can get an idea of the colors can work! :)