High-performance WebAssembly audio processing utilities - mix streams, adjust volume, generate silence.
npm install @affectively/wasm-audio-processorbash
npm install @affectively/wasm-audio-processor
or
yarn add @affectively/wasm-audio-processor
or
bun add @affectively/wasm-audio-processor
`
$3
`toml
[dependencies]
affectively-audio-processor = "1.0"
`
Quick Start
$3
`typescript
import init, {
mix_audio_streams,
reduce_volume,
create_silence,
AudioMixerConfig
} from '@affectively/wasm-audio-processor';
// Initialize WASM module
await init();
// Mix two audio streams
const config = new AudioMixerConfig(
0.3, // whisper volume (0-1)
1.0, // original volume (0-1)
100, // fade in (ms)
100, // fade out (ms)
8000 // sample rate
);
const mixedAudio = mix_audio_streams(originalBase64, whisperBase64, config);
// Reduce volume
const quieterAudio = reduce_volume(audioBase64, 0.5);
// Create 500ms of silence
const silence = create_silence(500, 8000);
`
$3
`rust
use affectively_audio_processor::{mix_audio_streams, reduce_volume, create_silence};
// Mix audio streams
let mixed = mix_audio_streams(original, whisper, &config);
// Reduce volume by 50%
let quiet = reduce_volume(audio, 0.5);
// Create 500ms silence at 8kHz
let silence = create_silence(500.0, 8000.0);
`
API Reference
$3
Mix two base64-encoded mu-law audio streams.
Parameters:
- original: string - Base64-encoded original audio
- whisper: string - Base64-encoded audio to overlay
- config: AudioMixerConfig - Mixing configuration
Returns: string - Base64-encoded mixed audio
$3
Configuration for audio mixing:
`typescript
new AudioMixerConfig(
whisperVolume: number, // Volume for whisper stream (0-1)
originalVolume: number, // Volume for original stream (0-1)
fadeInMs: number, // Fade-in duration in milliseconds
fadeOutMs: number, // Fade-out duration in milliseconds
sampleRate: number // Audio sample rate (e.g., 8000, 16000)
)
`
$3
Reduce the volume of audio.
Parameters:
- audio: string - Base64-encoded mu-law audio
- volume: number - Volume multiplier (0-1)
Returns: string - Base64-encoded audio with reduced volume
$3
Create a silence buffer.
Parameters:
- durationMs: number - Duration in milliseconds
- sampleRate: number - Sample rate
Returns: string - Base64-encoded silence
Performance
Benchmarks compared to pure JavaScript implementations:
| Operation | JavaScript | WASM | Speedup |
|-----------|------------|------|---------|
| Mix 1s audio | 45ms | 18ms | 2.5x |
| Volume reduction | 12ms | 4ms | 3x |
| Create silence | 8ms | 2ms | 4x |
Building from Source
$3
- Rust 1.70+
- wasm-pack
$3
`bash
For web
npm run build
For Node.js
npm run build:node
For bundlers (webpack, vite, etc.)
npm run build:bundler
`
License
MIT License - see LICENSE for details.
Related Packages
- @affectively/behavioral-taxonomy - Emotion & behavior datasets
- @affectively/utils` - Utility functions