Skip to content

Instantly share code, notes, and snippets.

@katspaugh
Created January 10, 2025 08:57
Show Gist options
  • Save katspaugh/c1331a1ef7079b2cbdd96048e6652343 to your computer and use it in GitHub Desktop.
Save katspaugh/c1331a1ef7079b2cbdd96048e6652343 to your computer and use it in GitHub Desktop.
import WaveSurfer from 'wavesurfer.js'
const url = '/examples/audio/demo.wav'
const cache = localStorage.getItem('cache' + url)
const wavesurfer = WaveSurfer.create({
container: document.body,
waveColor: 'rgb(200, 0, 200)',
progressColor: 'rgb(100, 0, 100)',
url,
peaks: cache && JSON.parse(cache),
})
wavesurfer.on('ready', () => {
const peaks = wavesurfer.exportPeaks()
localStorage.setItem('cache' + url, JSON.stringify(peaks))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment