當此技能被啟用時,請務必在第一次回覆時以 :speaker: 表情符號開頭。
影片音訊設計
影片音訊設計是將旁白、音效與背景音樂分層疊加到程式化影片作品中的實務技術。優良的音訊能將投影片式的影片轉化為精緻的成品——旁白引導觀眾,音樂設定情緒基調,而音效則點綴關鍵時刻。此技能涵蓋使用 ElevenLabs 及其他 TTS 提供者生成語音、使用 FFmpeg 建立合成音效、尋找免版稅背景音樂、實作音量閃避以確保語音清晰,以及在 Remotion 組合中將所有音軌以 frame 精確的時序混合。
何時使用此技能
當使用者有下列需求時,觸發此技能:
- 想要為程式化影片加入旁白或語音
- 需要使用 ElevenLabs、OpenAI TTS 或 Edge TTS 生成語音
- 詢問關於語音選擇、語音設定或語音複製的問題
- 想要加入背景音樂,或需要免版稅音樂來源
- 詢問如何程式化創建音效
- 想要實作音量閃避(在語音播放時降低音樂音量)
- 需要在 Remotion 中混合多個音軌
- 詢問關於音訊時序、音量等級或基於 frame 的音訊同步
以下情況不要觸發此技能:
- 影片腳本或分鏡規劃——請使用 video-scriptwriting 技能
- Remotion 元件架構或渲染——請使用 remotion-video 技能
- 在 DAW(Ableton、Logic、Pro Tools)中進行專業音訊製作
- 音樂創作或 MIDI 程式設計
關鍵原則
-
分層音訊架構 - 每個影片都有三個音軌:旁白在最上層(最大聲),音效在中間(強調音量),背景音樂在底層(最小聲)。
-
旁白驅動時序 - 先產生旁白,測量其持續時間,再設定場景時序以配合旁白長度。切勿將旁白硬塞進任意場景長度中。
-
語音播放時降低音樂音量 - 旁白播放時,背景音樂必須降低 50-60%。使用平滑的斜線(10-15 frames)以避免突兀的跳變。
-
音效作為強調,而非干擾 - 保持音效短促(0.5 秒以下)、音量適中,並與畫面上的動作相關。
-
在上下文中測試音訊 - 務必預覽包含所有音軌的完整混音。聆聽是否有模糊的語音、音量突增或無聲段落。
核心概念
三層音訊架構
| 層級 | 角色 | 基礎音量 | 旁白播放時 |
|---|---|---|---|
| 旁白 | 傳遞資訊、驅動節奏 | 0.8-1.0 | 不適用(最上層) |
| 音效 | 強調轉場與動作 | 0.3-0.5 | 0.3-0.5(不變) |
| 背景音樂 | 設定情緒基調、填補空白 | 0.3-0.5 | 0.15-0.25(音量降低) |
ElevenLabs API 模型
ElevenLabs 透過 REST API 提供神經網路 TTS。核心流程如下:
- 選擇一個語音(預製或複製)——每個語音都有一個
voice_id - 將文字與語音設定發送至
/v1/text-to-speech/{voice_id} - 接收原始音訊位元組(預設為 mp3)
- 寫入檔案並測量持續時間,以用於場景時序
語音設定:
| 設定 | 範圍 | 低 | 高 | 建議 |
|---|---|---|---|---|
| stability | 0-1 | 更具表現力、多變 | 更一致、單調 | 0.4-0.6 |
| similarity_boost | 0-1 | 更具創造力 | 更接近原始語音 | 0.6-0.8 |
| style | 0-1 | 中性表達 | 誇張風格 | 0.3-0.6 |
音量閃避概念
音量閃避會在旁白開始時降低背景音樂的音量,並在旁白結束時恢復音量。在 Remotion 中,使用 interpolate():
音樂音量: 0.4 ---\ /--- 0.4
\ /
0.15 \__________/
旁白開始 → 結束
斜線應佔用 10-15 frames(在 30fps 下約為 0.3-0.5 秒)。
Remotion 中基於 frame 的音訊同步
useCurrentFrame()傳回目前 frame 編號interpolate()將 frame 範圍對映到值範圍(例如音量)<Sequence from={frame}>將音訊放置於特定 frame<Audio volume={fn}>接受靜態數值或逐 frame 的函數
將秒數轉換為 frame:frames = seconds * fps。
常見任務
1. 設定 ElevenLabs API 金鑰並生成旁白
import fs from 'fs';
const ELEVENLABS_API_URL = 'https://api.elevenlabs.io/v1';
async function generateNarration(
text: string,
voiceId: string,
outputPath: string
): Promise<void> {
const response = await fetch(
`${ELEVENLABS_API_URL}/text-to-speech/${voiceId}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'xi-api-key': process.env.ELEVEN_LABS_API_KEY!,
},
body: JSON.stringify({
text,
model_id: 'eleven_multilingual_v2',
voice_settings: {
stability: 0.5,
similarity_boost: 0.75,
style: 0.5,
use_speaker_boost: true,
},
}),
}
);
if (!response.ok) {
const error = await response.text();
throw new Error(`ElevenLabs API error ${response.status}: ${error}`);
}
const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync(outputPath, buffer);
}
2. 選擇並設定語音設定
語音選擇問題:性別、年齡範圍、口音、能量程度、溫暖度。
interface VoiceSettings {
stability: number;
similarity_boost: number;
style: number;
use_speaker_boost: boolean;
}
const presets: Record<string, VoiceSettings> = {
explainer: { stability: 0.6, similarity_boost: 0.75, style: 0.4, use_speaker_boost: true },
promo: { stability: 0.3, similarity_boost: 0.7, style: 0.7, use_speaker_boost: true },
tutorial: { stability: 0.7, similarity_boost: 0.8, style: 0.2, use_speaker_boost: false },
};
3. 根據腳本為每個場景生成旁白
import { execSync } from 'child_process';
import path from 'path';
interface Scene { id: string; narrationText: string; }
interface SceneWithAudio extends Scene {
audioPath: string;
durationMs: number;
durationFrames: number;
}
function getAudioDurationMs(filePath: string): number {
const output = execSync(
`ffprobe -v error -show_entries format=duration -of csv=p=0 "${filePath}"`
).toString().trim();
return Math.round(parseFloat(output) * 1000);
}
async function generateSceneNarrations(
scenes: Scene[], voiceId: string, outputDir: string, fps: number
): Promise<SceneWithAudio[]> {
const results: SceneWithAudio[] = [];
for (const scene of scenes) {
const audioPath = path.join(outputDir, `${scene.id}.mp3`);
await generateNarration(scene.narrationText, voiceId, audioPath);
const durationMs = getAudioDurationMs(audioPath);
results.push({
...scene, audioPath, durationMs,
durationFrames: Math.ceil((durationMs / 1000) * fps),
});
}
return results;
}
4. 尋找背景音樂
免版稅音樂來源:
- Pixabay Audio:https://pixabay.com/music/(免費,無需標註出處)
- Freesound:https://freesound.org/(CC0/CC-BY)
- YouTube 音效庫:從 YouTube Studio 下載
- 本地檔案:放在
public/audio/以用於 Remotion 的staticFile()
5. 使用 FFmpeg 生成音效
# 點擊聲 - 短促正弦波
ffmpeg -f lavfi -i "sine=frequency=800:duration=0.05" \
-af "afade=t=out:st=0.02:d=0.03" click.wav
# 鍵盤打字聲 - 過濾的噪音突波
ffmpeg -f lavfi -i "anoisesrc=d=0.08:c=white:a=0.3" \
-af "highpass=f=2000,lowpass=f=8000,afade=t=out:st=0.04:d=0.04" type.wav
# 咻聲 - 頻率掃掠
ffmpeg -f lavfi -i "sine=frequency=200:duration=0.4" \
-af "vibrato=f=8:d=0.5,afade=t=in:d=0.1,afade=t=out:st=0.2:d=0.2,lowpass=f=1000" \
whoosh.wav
# 叮噹聲 - 鈴聲合成
ffmpeg -f lavfi -i "sine=frequency=1200:duration=0.6" \
-af "afade=t=out:st=0.1:d=0.5,aecho=0.8:0.88:40:0.4" ding.wav
# 啵聲 - 脈衝
ffmpeg -f lavfi -i "sine=frequency=400:duration=0.08" \
-af "afade=t=out:st=0.02:d=0.06,lowpass=f=600" pop.wav
# 轉場呼嘯聲
ffmpeg -f lavfi -i "sine=frequency=300:duration=0.3" \
-af "vibrato=f=12:d=0.8,afade=t=in:d=0.05,afade=t=out:st=0.15:d=0.15,bandpass=f=500:w=400" \
swoosh.wav
6. 在 Remotion 中實作音量閃避
import React from 'react';
import { Audio, useCurrentFrame, interpolate, Sequence } from 'remotion';
const AudioMixer: React.FC<{
narrationSrc: string;
musicSrc: string;
narrationStart: number;
narrationDuration: number;
}> = ({ narrationSrc, musicSrc, narrationStart, narrationDuration }) => {
const frame = useCurrentFrame();
const duckRampFrames = 10;
const musicVolume = interpolate(
frame,
[
narrationStart - duckRampFrames,
narrationStart,
narrationStart + narrationDuration,
narrationStart + narrationDuration + duckRampFrames,
],
[0.4, 0.15, 0.15, 0.4],
{ extrapolateLeft: 'clamp', extrapolateRight: 'clamp' }
);
return (
<>
<Audio src={musicSrc} volume={musicVolume} />
<Sequence from={narrationStart} durationInFrames={narrationDuration}>
<Audio src={narrationSrc} volume={0.9} />
</Sequence>
</>
);
};
export default AudioMixer;
7. 在 Remotion 組合中混合 3 個音軌
import React from 'react';
import { Audio, Sequence, useCurrentFrame, interpolate } from 'remotion';
interface NarrationSegment { src: string; startFrame: number; durationFrames: number; }
interface SfxEvent { src: string; frame: number; }
const FullAudioMix: React.FC<{
narrations: NarrationSegment[];
sfxEvents: SfxEvent[];
musicSrc: string;
}> = ({ narrations, sfxEvents, musicSrc }) => {
const frame = useCurrentFrame();
const duckRamp = 10;
let musicVolume = 0.4;
for (const seg of narrations) {
const duck = interpolate(
frame,
[seg.startFrame - duckRamp, seg.startFrame,
seg.startFrame + seg.durationFrames, seg.startFrame + seg.durationFrames + duckRamp],
[1, 0.375, 0.375, 1],
{ extrapolateLeft: 'clamp', extrapolateRight: 'clamp' }
);
musicVolume = musicVolume * duck;
}
return (
<>
<Audio src={musicSrc} volume={musicVolume} loop />
{sfxEvents.map((sfx, i) => (
<Sequence key={i} from={sfx.frame} durationInFrames={30}>
<Audio src={sfx.src} volume={0.4} />
</Sequence>
))}
{narrations.map((seg, i) => (
<Sequence key={i} from={seg.startFrame} durationInFrames={seg.durationFrames}>
<Audio src={seg.src} volume={0.9} />
</Sequence>
))}
</>
);
};
export default FullAudioMix;
8. 使用其他 TTS 提供者
OpenAI TTS - 品質好、API 簡單、六個內建語音:
import OpenAI from 'openai';
import fs from 'fs';
const openai = new OpenAI();
async function generateWithOpenAI(
text: string,
outputPath: string,
voice: 'alloy' | 'echo' | 'fable' | 'onyx' | 'nova' | 'shimmer' = 'alloy'
): Promise<void> {
const mp3 = await openai.audio.speech.create({
model: 'tts-1-hd',
voice,
input: text,
});
const buffer = Buffer.from(await mp3.arrayBuffer());
fs.writeFileSync(outputPath, buffer);
}
Edge TTS - 免費、語音眾多,使用 Microsoft Edge 的 TTS 服務:
pip install edge-tts
edge-tts --voice en-US-AriaNeural --text "Hello world" --write-media output.mp3
edge-tts --list-voices
反模式 / 常見錯誤
| 錯誤 | 原因 | 替代做法 |
|---|---|---|
| 旁白播放時音樂音量相同 | 語音變得無法聽清 | 實作音量閃避 - 語音播放時將音樂降低 50-60% |
| 硬編碼 ElevenLabs API 金鑰 | 金鑰會洩漏到版本控制中 | 使用環境變數:process.env.ELEVEN_LABS_API_KEY |
| 使用 TTS 後未測量持續時間 | 場景時序錯誤,旁白被截斷 | 生成後使用 ffprobe 測量音訊持續時間 |
| 音效比旁白大聲 | 干擾內容 | 音效設定為 0.3-0.5,旁白為 0.8-1.0 |
| 音樂開頭/結尾沒有淡入淡出 | 突然的開始/停止像 bug | 在開頭加入 0.5-1 秒淡入,結尾加入淡出 |
| 使用低品質 TTS 模型 | 機械化語音影響品質 | 使用 eleven_multilingual_v2 或 tts-1-hd |
| 忽略音訊檔案格式 | 某些格式會加入靜音填充 | 旁白使用 MP3,音效使用 WAV |
注意事項
-
ElevenLabs 速率限制與字元配額 - 免費方案有每月字元限制。積極快取生成的音訊,僅在文字變更時重新生成。使用文字的雜湊值作為快取鍵。
-
MP3 編碼器填充會加入靜音 - MP3 檔案通常在開頭有 20-50ms 的靜音。使用
ffmpeg -af silenceremove=1:0:-50dB修剪,或在 frame 時序中補償偏移。 -
Remotion 音訊音量是元件級別,而非全域 - 兩個
<Audio>組件音量都為 1.0 時可能會削波。保持同時播放音軌的總音量低於 1.0。 -
FFmpeg 音效在不同系統上聽起來不同 - 務必指定
-ar 44100 -sample_fmt s16以確保跨機器輸出一致。 -
跨場景的語音一致性 - ElevenLabs 對相同設定與不同文字可能產生不同語氣。對多場景旁白,使用 stability >= 0.5。
參考資料
關於特定音訊子領域的詳細模式,請參閱 references/ 資料夾中的相關檔案:
references/elevenlabs-api.md- 進階 ElevenLabs API 模式,包括語音複製、串流 TTS、Websocket API、發音字典與配額管理references/audio-mixing-patterns.md- 進階混音模式,包括多段音量閃避、場景間交叉淡入淡出、音量自動化曲線以及最終混音母帶處理references/sfx-generation.md- 全面的 FFmpeg 音效生成,包括複雜合成、多生成器分層以及建立可重複使用的音效庫
僅在目前任務需要時才載入參考檔案——它們很長且會耗費上下文。
配套檢查
首次啟用時...