Audio 音频配置
多音轨音频系统配置
Audio 音频配置
Audio 字段用于配置全局音频资源,支持多音轨混音。
字段定义
interface AudioConfig {
tracks?: AudioTrack[]; // 多音轨支持
bgm?: BgmConfig; // 背景音乐(向后兼容)
}
interface AudioTrack {
id: string; // 音轨 ID
type: AudioTrackType; // 音轨类型
name?: string; // 可读名称
src: string | { $ref: string }; // 音频地址或资源引用
volume?: number; // 音量 0-1
muted?: boolean; // 是否静音
loop?: boolean; // 是否循环
startTime?: number; // 开始时间偏移(秒)
fadeIn?: number; // 淡入时长(秒)
fadeOut?: number; // 淡出时长(秒)
playbackRate?: number; // 播放速度,默认 1.0
solo?: boolean; // 独奏模式
}
type AudioTrackType = 'bgm' | 'voice' | 'sfx' | 'custom';音轨类型
| 类型 | 说明 | 默认音量 |
|---|---|---|
bgm | 背景音乐 | 0.4 |
voice | 人声/旁白 | 1.0 |
sfx | 音效 | 0.7 |
custom | 自定义 | 0.8 |
示例
单音轨(向后兼容)
{
"audio": {
"bgm": {
"src": "https://example.com/bgm.mp3",
"volume": 0.6,
"loop": true,
"fadeIn": 2,
"fadeOut": 1
}
}
}多音轨混音
{
"audio": {
"tracks": [
{
"id": "bgm-track",
"type": "bgm",
"name": "背景音乐",
"src": "https://example.com/bgm.mp3",
"volume": 0.4,
"loop": true,
"fadeIn": 1
},
{
"id": "voice-track",
"type": "voice",
"name": "旁白",
"src": "https://example.com/narration.mp3",
"volume": 1.0
},
{
"id": "sfx-track",
"type": "sfx",
"name": "音效",
"src": "https://example.com/sfx.mp3",
"volume": 0.7,
"startTime": 5
}
]
}
}音量建议
| 场景 | BGM | Voice | SFX |
|---|---|---|---|
| 有旁白 | 0.3-0.4 | 1.0 | 0.6-0.8 |
| 纯音乐 | 0.6-0.8 | - | 0.7 |
| 强调音效 | 0.2-0.3 | 1.0 | 1.0 |
淡入淡出
- fadeIn:音频开始时逐渐增大音量,避免突然出现
- fadeOut:音频结束时逐渐降低音量,避免突然中断
- 推荐时长:1-2 秒
独奏模式
当设置 solo: true 时,只有标记为独奏的音轨会播放,其他音轨自动静音。
{
"audio": {
"tracks": [
{ "id": "bgm", "type": "bgm", "src": "...", "volume": 0.4 },
{ "id": "voice", "type": "voice", "src": "...", "solo": true }
]
}
}最佳实践
- 音量平衡:确保人声清晰,BGM 不要盖过旁白
- 使用资源引用:通过
$ref引用 assets 中的音频资源 - 淡入淡出:始终使用淡入淡出,提升用户体验
- 音频格式:推荐使用 MP3 或 AAC 格式
- 循环设置:BGM 通常设为循环,人声和音效不循环
- 时间偏移:使用 startTime 控制音效触发时机