Skip to content

Commit 405be5a

Browse files
committed
Docs: webaudio shim example + update readme
1 parent 00adf23 commit 405be5a

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,21 @@ Have a question about integrating wavesurfer.js on your website? Feel free to as
132132

133133
### FAQ
134134

135-
* **Q**: Does wavesurfer support large files?
136-
* **A**: Since wavesurfer decodes audio entirely in the browser using Web Audio, large clips may fail to decode due to memory constraints. We recommend using pre-decoded peaks for large files (see [this example](https://wavesurfer.xyz/examples/?predecoded.js)). You can use a tool like [bbc/audiowaveform](https://github.com/bbc/audiowaveform) to generate peaks.
137-
138-
---
139-
140-
* **Q**: What about streaming audio?
141-
* **A**: Streaming isn't supported because wavesurfer needs to download the entire audio file to decode and render it.
142-
143-
---
144-
145-
* **Q**: There is a mismatch between my audio and the waveform. How do I fix it?
146-
* **A**: If you're using a VBR (variable bit rate) audio file, there might be a mismatch between the audio and the waveform. This can be fixed by converting your file to CBR (constant bit rate). See [this issue](https://github.com/katspaugh/wavesurfer.js/issues/2890#issuecomment-1601067822) for details.
147-
135+
<details>
136+
<summary>Does wavesurfer support large files?</summary>
137+
Since wavesurfer decodes audio entirely in the browser using Web Audio, large clips may fail to decode due to memory constraints. We recommend using pre-decoded peaks for large files (see <a href="https://wavesurfer.xyz/examples/?predecoded.js">this example</a>). You can use a tool like <a href="https://github.com/bbc/audiowaveform">bbc/audiowaveform</a> to generate peaks.
138+
</details>
139+
140+
<details>
141+
<summary>What about streaming audio?</summary>
142+
Streaming audio is supported only with <a href="https://wavesurfer.xyz/examples/?predecoded.js">pre-decoded peaks and duration</a>.
143+
</details>>
144+
145+
<details>
146+
<summary>There is a mismatch between my audio and the waveform. How do I fix it?</summary>
147+
If you're using a VBR (variable bit rate) audio file, there might be a mismatch between the audio and the waveform. This can be fixed by converting your file to CBR (constant bit rate).
148+
<p>Alternatively, you can use the <a href="https://wavesurfer.xyz/examples/?webaudio-shim.js">Web Audio shim</a> which is more accurate.</p>
149+
</details>
148150

149151
## Development
150152

examples/predecoded.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const wavesurfer = WaveSurfer.create({
2727
0.02300390601158142, 0.007677287794649601, 0.015354577451944351, 0.007677287794649601, 0.007677288725972176,
2828
],
2929
],
30+
duration: 22,
3031
})
3132

3233
wavesurfer.on('interaction', () => {

examples/webaudio-shim.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import WaveSurfer from 'https://unpkg.com/wavesurfer.js@7/dist/wavesurfer.esm.js'
2+
import WebAudio from 'https://unpkg.com/wavesurfer.js@7/dist/webaudio.js'
3+
4+
const media = new WebAudio()
5+
media.src = '/examples/audio/audio.wav'
6+
7+
const wavesurfer = WaveSurfer.create({
8+
container: document.body,
9+
waveColor: 'rgb(200, 0, 200)',
10+
progressColor: 'rgb(100, 0, 100)',
11+
media,
12+
})

0 commit comments

Comments
 (0)