Audio Elements
Complete reference for audio elements with the Zvid, including background music, sound effects.
Overview
Audio elements allow you to add background music, sound effects, voiceovers, and other audio content to your videos. They support precise timing control, volume management, speed adjustment.
AudioItem Interface
interface AudioItem {
src: string;
audioBegin?: number;
audioEnd?: number;
audioDuration?: number;
volume?: number;
speed?: number;
enter?: number;
exit?: number;
type?: string;
}
Properties
Required Properties
| Property | Type | Description |
|---|---|---|
src | string | Audio file path or URL |
Audio Timing Properties
| Property | Type | Default | Description |
|---|---|---|---|
audioBegin | number | 0 | Start position in audio file (seconds) |
audioEnd | number | Source duration | End position in audio file (seconds) |
audioDuration | number | Source duration | Total duration of audio file |
Project Timeline Properties
| Property | Type | Default | Description |
|---|---|---|---|
enter | number | 0 | Start time in project timeline (seconds) |
exit | number | project.duration | End time in project timeline (seconds) |
Audio Control Properties
| Property | Type | Default | Description |
|---|---|---|---|
volume | number | 1 | Audio volume (0-1, can exceed 1 for amplification) |
speed | number | 1 | Playback speed multiplier |
Metadata Properties
| Property | Type | Default | Description |
|---|---|---|---|
type | string | "AUDIO" | Element type identifier |
Basic Examples
Background Music
{
src: "https://cdn.pixabay.com/audio/2025/03/19/audio_56ae1dae5f.mp3",
volume: 0.3,
enter: 0,
exit: 10
}
Sound Effect
{
src: "https://cdn.pixabay.com/audio/2025/01/13/audio_c2af364af2.mp3",
volume: 0.8,
enter: 2,
exit: 4,
}
Advanced Examples
Audio Segment Selection
{
src: "https://cdn.pixabay.com/audio/2025/04/21/audio_ed6f0ed574.mp3",
audioBegin: 10, // Start at 1 minute
audioEnd: 20, // End at 2 minutes
volume: 0.5,
enter: 0,
exit: 10, // Use 1-minute segment in 1-minute video
}
Speed-Modified Audio
{
src: "https://cdn.pixabay.com/audio/2025/05/20/audio_ec1f11ca43.mp3",
speed: 1.2, // 20% faster (higher pitch)
volume: 0.8,
enter: 0,
exit: 10, // Original 30s audio plays in 25s
}
Audio Timing Explained
Source Audio Timing
audioBegin: Start point in the source audio fileaudioEnd: End point in the source audio fileaudioDuration: Total length of the source audio file
// Play seconds 30-90 from a 3-minute audio file
{
audioBegin: 30,
audioEnd: 90,
audioDuration: 180
}
Project Timeline Timing
enter: When audio starts in project timelineexit: When audio ends in project timeline
// Audio plays from 5s to 25s in the project
{
enter: 5,
exit: 25
}
Timing Coordination
// Use 20 seconds of audio (from 10s-30s in source)
// playing from 5s-25s in project timeline
{
src: "audio.mp3",
audioBegin: 10,
audioEnd: 30,
audioDuration: 60,
enter: 5,
exit: 25
}
Volume and Mixing
Volume Levels
{
volume: 0, // Muted
volume: 0.1, // Very quiet (10%)
volume: 0.3, // Background music level
volume: 0.5, // Medium volume
volume: 0.8, // Prominent audio
volume: 1.0, // Full volume
volume: 1.5 // Amplified (may cause distortion)
}
Speed and Pitch Control
Speed Effects
// Slow motion audio (lower pitch)
{
src: "speech.mp3",
speed: 0.8, // 80% speed
volume: 0.8
},
// Fast audio (higher pitch)
{
src: "music.mp3",
speed: 1.25, // 125% speed
volume: 0.5
},
// Chipmunk effect
{
src: "voice.mp3",
speed: 1.8, // 180% speed
volume: 0.7
}
Supported Audio Formats
All FFMPEG Audio formats are supported, For Example:
Input Formats
- MP3 - Most common, good compression
- WAV - Uncompressed, high quality
- AAC - Modern compression, good quality
- OGG - Open source format
- M4A - Apple format, good quality
Quality Recommendations
- Music: 128-320 kbps MP3 or AAC
- Speech: 64-128 kbps MP3
- Sound Effects: 128-192 kbps MP3
- High Quality: WAV or high-bitrate AAC
Best Practices
Audio Design
- Volume Balance: Keep background music 20-40% of speech volume
- Dynamic Range: Use different volume levels for different content types
Performance Optimization
- File Size: Compress audio appropriately for use case
- Format Selection: Use MP3 for most cases, WAV for high quality needs
- Segment Selection: Use
audioBegin/audioEndto avoid loading entire files
Technical Guidelines
- Sample Rate: 44.1kHz is standard for most content
- Bit Depth: 16-bit is sufficient for most applications
- Mono vs Stereo: Use mono for speech, stereo for music
- Normalization: Normalize audio levels before use
Common Patterns
Background Music
{
src: "background-music.mp3",
volume: 0.3,
enter: 0,
exit: 60, // Full video duration
}
Sound Effects Library
// Transition sound
{
src: "transition.mp3",
volume: 0.5,
enter: 10,
exit: 11,
},
// Success sound
{
src: "success.mp3",
volume: 0.7,
enter: 25,
exit: 27,
},
// Alert sound
{
src: "alert.mp3",
volume: 0.8,
enter: 40,
exit: 42,
}
Narration with Music
// Background music (ducked during speech)
{
src: "music1.mp3",
volume: 0.4,
enter: 0,
exit: 5, // Full volume intro
},
{
src: "music2.mp3",
audioBegin: 5,
volume: 0.15, // Reduced during speech
enter: 5,
exit: 55,
},
{
src: "music3.mp3",
audioBegin: 55,
volume: 0.4, // Full volume outro
enter: 55,
exit: 60,
},
// Narration
{
src: "narration.mp3",
volume: 0.9,
enter: 5,
exit: 55,
}
Related Pages
- Video Elements - Video audio management
- Animation Effects - Synchronizing audio with animations
- Transitions - Audio transitions between clips
Next Steps
- Animation Effects - Learn about element animations
- Transitions - Master video transition effects