Ask coding questions

← Back to all posts
How do you get a audio file to play in the index.html?
Dominicl645 (428)

i am collaborating with another user and i am wondering how you would get a audio file to play in the index.html.
where would i have to go and what would i code to get the audio to play?

Dominicl645 (428)

anyone know how to do this? pls help me


Try this code:

from replit import audio
play('your file')

So now, all you have to do is click on the 3 dots, and get your file. And it makes a new file. Just take the name of the file and put it in the play:

That should work

Dominicl645 (428)

so this python code will work in HTML? @RYANTADIPARTHI


@dominicl645 uhh, no. If you are doing this in HTML, do it this way:

<audio controls>
<source src="Your file name">

And for the file name, do the same thing, for the HTML, just click on three dots, and all.

RedPandaCode (25)

To get an audio file you simply need to use an <audio> tag. In side the tag you can give it a "src" attribute with the url of the audio!

<audio src="url">
RedPandaCode (25)

You can also add a "controls" attribute after "src"

<audio src="url" controls>
Dominicl645 (428)

how would i use that code on a mp3 file already uploaded into the replit? @RedPandaCode

RedPandaCode (25)

@dominicl645 Hmmm... I haven't done that before. Perhaps in "src" you may need to use the file name in repl rather than the URL

<audio src="filename.mp3" controls>
RedPandaCode (25)

@dominicl645 This is what an audio should look like. See if it helps.

(Also make sure that your volume is turned up)

RedPandaCode (25)

If this does not appear your code may be wrong somehow.
(This was made using the "controls" attribute)

RedPandaCode (25)

Since you uploaded the file into repl, if nothing else works, try swapping the "src" attribute for an "href" attribute

<audio href="filename" controls>