play-web-audio

Play sounds using the web audio API

Usage no npm install needed!

<script type="module">
  import playWebAudio from 'https://cdn.skypack.dev/play-web-audio';
</script>

README

Play Web Audio

Install

yarn add play-web-audio

Usage

import { playAudio, loadAudioUrls } from 'play-web-audio'

let squakk
const soundUrls = ['./sounds/squakk.mp3']

loadAudioUrls(this.soundUrls, bufferList => {
  squakk = bufferList[0]
})

playAudio(squakk) // plays the audio file
/*
    N.B. on many device autoplay is not allowed, then this must be initiated by a user interaction, like a mouse click or finger tap.

*/

Example

Demonstration of using the Web Audio API using React. See folder example. Try this on iPhone/Safari (iOS), playback is instant! Now compare it with the implementation using the <audio> HTML tag... long delay on iPhone.

Ergo: use the Web Audio API instead.

https://play-it.now.sh

Credits