-
Notifications
You must be signed in to change notification settings - Fork 63
Waveform research for audio files #62
Comments
There are three strategies we can use to show audio waveforms on the front end: 1. Generate the waveform entirely on the frontend.To do this, we would use the Web Audio API and its ability to analyze the audio data after it has been downloaded to the user's device. The libraries we can use for this are Pros
Cons
2. Generate the waveform data on the backend and draw it on the frontendThis approach would require us to download the audio files, analyze them to create a Pros
Cons
3. Generate waveform images in a process similar to the way we create image thumbnails, and use the images on the frontend.We could use the approach similar to #2, but instead of creating the json/dat files, create an image. Pros
Cons
I would suggest setting up the backend for generating waveform data in Generating waveforms on the frontend: Technical detailsOn the frontend, audio can be displayed using Data file formatThe data we need to draw the waveform is generated in form of an array of numbers that show how high the lines should go. For a sample with 1 channel, sample rate of 44100, 256 samples_per_pixel, 8 bits and length of 33472, the Drawing the waveformsBoth Other alternatives reviewedThere is Vue-based library Vue-audio-visual generating waveforms using Web Audio API. However, it does not allow customizing the audio controls to our requirements, or using the waveform for playing/pausing the audio. I have added a page with audio waveforms generated using |
Approach 1 cannot be used as the WebAudio API does not allow reading contents of the audio if the request is made to a cross-origin resource. Approach 3 is not server-friendly because keeping a library of waveform images for every audio file in the catalog is not feasible. Also images will neither be interactive (required for seeking) nor XY scalable (required for good UI). References for implementations towards approach 2:
|
If there's consensus that Approach 2 is the way to move forward amongst the @WordPress/openverse-developers, we can close this. I personally think it's the best balance between performance and visual quality |
Closing this issue as the Approach 2 is being implemented in the linked PRs. |
Will re-open if someone is opposed to Approach 2 then 😄 |
For each audio track, we will want to display a waveform preview. This is both aesthetically pleasing but also informative to users. Individuals looking for audio can get a lot of information from the waveform. Some examples:
Most waveform previews require an entire track to be downloaded and analysed client-side. We should look into solutions that support server-side-rendering or can take metadata in some type of simple text format. I'm not sure how much spectral data it even takes to render an audio waveform; if the data required is too large, we might not want to include it as an api field, but do something similar to the image thumbnail cache instead.
prior art
I found a developer discussing some different approaches they took for performance in a gist
The text was updated successfully, but these errors were encountered: