Last active
March 11, 2024 15:56
-
-
Save katspaugh/998f3697a6ce83671926c2f3868d9b7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import WaveSurfer from 'wavesurfer.js' | |
import WebAudioPlayer from 'wavesurfer.js/dist/webaudio.js' | |
const media = new WebAudioPlayer() | |
media.src = '/examples/audio/audio.wav' | |
function playSegment(fromTime, toTime) { | |
media.currentTime = fromTime | |
media.play() | |
media.stopAt(toTime) | |
} | |
media.addEventListener('loadedmetadata', () => { | |
const wavesurfer = WaveSurfer.create({ | |
container: document.body, | |
waveColor: 'rgb(200, 0, 200)', | |
progressColor: 'rgb(100, 0, 100)', | |
media, | |
peaks: media.getChannelData(), | |
}) | |
}) | |
document.querySelector('#play').onclick = () => { | |
playSegment(5, 8) | |
} | |
/* | |
<html> | |
<button id="play">Play 3 seconds</button> | |
</html> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment