0

It might be a bit confusing. What I would like to achieve is to have my application work with just one .html file. Ofc, JS scripts and CSS I can easily put in there, no problem.

The only thing that holds be back is the one tiny sound file, that I'm currently streaming from the internet. However it won't work, when there's no internet connection.

const notificationSound = new Audio("https://notificationsounds.com/storage/sounds/file-sounds-1142-inflicted.mp3");
(...)
if(soundOn){ notificationSound.play();}

I would like to include the raw data of the sound file in the .html file and then play it back. Is there a way to make it work?

Gaben
  • 345
  • 1
  • 12
  • first define raw audio file. There is no such thing as a raw audio file, just uncompressed audio files. Or do you mean a system audio sound? – tacoshy Nov 11 '20 at 22:08
  • What I meant was the uncompressed audio file. I imagine the whole process will include me converting .mp3 file into .wav file and putting the data inside some javascript object. Not sure if it's even possible, nor I know the way to do it. – Gaben Nov 11 '20 at 22:26

1 Answers1

1

You can convert the mp3 to base64 and then play it using the audio tag.

You can check out the codepen I prepared with your audio.

    <audio
    controls
    src="data:audio/mp3;base64,//uvxAAAAAAA....">
    </audio>

You can also refer to the original documentation and this SO answer as well.

bentz123
  • 1,081
  • 7
  • 16