A standalone Tauri v1 example that turns a local audio file into a GPU-driven visual performance and recording source.
Unlike Example 13, which analyses a live microphone, this project has a real media timeline. The audio playhead drives transport, seeking, loop regions, playback rate, spectral analysis, WebGL animation, and recorded output.
HTMLAudioElement for multiple filescreateMediaElementSource()Local audio file
↓
HTMLAudioElement
↓
MediaElementAudioSourceNode
↓
AnalyserNode ───────────────→ output volume → speakers
│
├─ FFT byte array ───→ WebGL spectrum texture
├─ waveform array ───→ WebGL waveform texture
├─ frequency bands ──→ GLSL uniforms
└─ audio stream ─────→ MediaRecorder
↑
WebGL canvas.captureStream() ─────┘
The analyser is connected to a MediaStreamAudioDestinationNode, allowing the canvas video and the original analysed audio to be recorded together.
23-tauri-v1-audio-file-fft-visualizer/
├── package.json
├── README.md
├── src/
│ ├── index.html interface, transport, meters, and canvas
│ ├── styles.css responsive control panel and stage
│ └── app.js audio graph, analysis, WebGL, recording, and export
└── src-tauri/
├── Cargo.toml
├── build.rs
├── tauri.conf.json
├── icons/
└── src/main.rs
npm install
npm run dev
Then:
A given HTMLAudioElement can only be connected to one MediaElementAudioSourceNode. This example keeps the element and node alive, replacing only the element’s source URL when another file is loaded.
u_time receives audio.currentTime, not only wall-clock time. Pausing freezes timeline-driven motion, seeking jumps the visual timeline, and changing playback speed changes the animation rate with the audio.
The analyser feeds the output and recording branches. Speaker volume is applied after analysis, so muting the speakers does not eliminate the FFT or recorded audio. Use Sensitivity to change visual response.
MediaRecorder support is determined at runtime. A WebView may support WebM but not MP4, or may expose recording differently across macOS, Windows, and Linux.
Try another audio format. File-extension support does not guarantee that the operating system WebView has the required codec. WAV and MP3 are useful first tests.
Press Play once so the user gesture can resume the Web Audio context. Also confirm that Sensitivity is above 1.0 and the file contains audible signal.
Start playback once before recording so the Web Audio graph exists. The recorder can capture an idle canvas before the audio graph has been created, but no audio track will exist yet.
The button activates only after MediaRecorder has fully stopped and assembled the final Blob.
Some compressed files seek only to codec key or packet boundaries. WAV generally provides the most exact transport response.
This example intentionally focuses on local file analysis. It does not decode audio in Rust, calculate an offline waveform overview, or perform multitrack mixing. Those would be separate examples or future expansions.