ElevenLabs 語音旁白生成 是做什麼的?
使用 ElevenLabs API 為 Remotion 影片產生專業的 AI 語音旁白。
前置需求
- 在
.env.local檔案中設定ELEVENLABS_API_KEY
快速開始
# 從文字產生語音旁白
node .claude/skills/elevenlabs-remotion-skill/generate.js --text "您的文字" --output public/audio/voiceover.mp3
# 使用旁白風格(更自然)
node .claude/skills/elevenlabs-remotion-skill/generate.js --text "您的文字" --character narrator --output voiceover.mp3
# 使用請求拼接產生場景
node .claude/skills/elevenlabs-remotion-skill/generate.js --scenes remotion/scenes.json --output-dir public/audio/project/
# 重新產生單一場景
node .claude/skills/elevenlabs-remotion-skill/generate.js --scenes scenes.json --scene scene2 --new-text "更新的文字"
# 列出可用的語音與角色預設
node .claude/skills/elevenlabs-remotion-skill/generate.js --list-voices
node .claude/skills/elevenlabs-remotion-skill/generate.js --list-characters
角色預設
使用角色預設可以產生更自然的語音旁白,而非逐字朗讀螢幕文字:
| 角色 | 說明 | 最佳用途 |
|---|---|---|
literal | 完全按照文字朗讀 | 螢幕文字、引言 |
narrator | 專業說書人,流暢且引人入勝 | 解說、紀錄片 |
salesperson | 充滿熱情、具說服力、活力充沛 | 行銷、廣告 |
expert | 權威、自信、專業 | 法律內容、教學 |
conversational | 輕鬆、親切、自然 | 社群媒體、休閒內容 |
dramatic | 強烈、情緒化、有衝擊力 | 開場鉤子、問題陳述 |
calm | 平穩、安撫、溫和 | 建立信任、結語 |
# 全域使用旁白風格
node .claude/skills/elevenlabs-remotion-skill/generate.js --scenes scenes.json --character narrator --output-dir public/audio/
# 或在 scenes.json 中為每個場景獨立設定
{
"scenes": [
{ "id": "scene1", "text": "問題陳述", "character": "dramatic" },
{ "id": "scene2", "text": "解決方案", "character": "calm" }
]
}
基於場景的產生(含請求拼接)
利用 ElevenLabs 的請求拼接功能,產生多個場景並保持一致的語調:
scenes.json 格式
{
"name": "product-demo",
"voice": "George",
"character": "narrator",
"scenes": [
{
"id": "scene1",
"text": "Generic text-to-speech sounds robotic. Your brand deserves better.",
"duration": 4.5,
"character": "dramatic"
},
{
"id": "scene2",
"text": "With voice cloning, you can use your own voice for unlimited content.",
"duration": 5.5
},
{
"id": "scene3",
"text": "Record a short sample. Clone it. Create professional voiceovers in minutes.",
"duration": 6,
"delay": 0.3
}
]
}
產生所有場景
node .claude/skills/elevenlabs-remotion-skill/generate.js \
--scenes remotion/product-demo-scenes.json \
--output-dir public/audio/product-demo/
此命令會建立:
product-demo-scene1.mp3到sceneN.mp3product-demo-combined.mp3(所有場景拼接)product-demo-info.json(包含持續時間的中繼資料)
單一場景重新產生
如果某個場景開始得太早、時機錯誤或需要不同的文字:
# 使用新文字重新產生 scene2
node .claude/skills/elevenlabs-remotion-skill/generate.js \
--scenes remotion/scenes.json \
--scene scene2 \
--new-text "更新的場景 2 文字" \
--output-dir public/audio/project/
# 使用不同角色重新產生 scene3
node .claude/skills/elevenlabs-remotion-skill/generate.js \
--scenes remotion/scenes.json \
--scene scene3 \
--character salesperson \
--output-dir public/audio/project/
# 僅重新產生(相同文字與角色)
node .claude/skills/elevenlabs-remotion-skill/generate.js \
--scenes remotion/scenes.json \
--scene scene1 \
--output-dir public/audio/project/
# 將縮圖嵌入 MP4 影片
node .claude/skills/elevenlabs-remotion-skill/generate.js \
--embed-thumbnail public/videos/my-video.mp4 \
--thumbnail public/videos/my-thumbnail.png \
--output public/videos/my-video-with-thumb.mp4
工具會自動:
- 使用前面場景的請求拼接,以維持一致的語調
- 更新 info.json 檔案中的新中繼資料
- 若提供
--new-text,則更新 scenes.json
縮圖嵌入
將縮圖圖片嵌入 MP4 影片,讓 Twitter、YouTube 及影片播放器等平台顯示自訂縮圖,而非第一影格。
將縮圖嵌入影片
# 基本用法 - 輸出為 video-thumb.mp4
node .claude/skills/elevenlabs-remotion-skill/generate.js \
--embed-thumbnail public/videos/promo.mp4 \
--thumbnail public/videos/thumbnail.png
# 自訂輸出路徑
node .claude/skills/elevenlabs-remotion-skill/generate.js \
--embed-thumbnail public/videos/promo.mp4 \
--thumbnail public/videos/thumbnail.png \
--output public/videos/promo-final.mp4
與 Remotion 搭配的工作流程
# 1. 渲染影片
npx remotion render MyVideo public/videos/my-video.mp4
# 2. 渲染縮圖(使用 Still 合成)
npx remotion still MyVideoThumbnail public/videos/my-thumbnail.png
# 3. 嵌入縮圖
node .claude/skills/elevenlabs-remotion-skill/generate.js \
--embed-thumbnail public/videos/my-video.mp4 \
--thumbnail public/videos/my-thumbnail.png \
--output public/videos/my-video-final.mp4
支援格式
- 影片:MP4 (H.264/H.265)
- 縮圖:PNG、JPG、JPEG
嵌入功能使用 ffmpeg 的 -disposition:v:1 attached_pic 旗標,將縮圖設為附加圖片,多數影片播放器與平台皆支援此格式。
時間驗證
本技能會在生成後自動使用 ffprobe 進行時間驗證:
檢查項目
| 檢查項目 | 閾值 | 說明 |
|---|---|---|
| 長度差異 | >15% | 當實際長度與預期長度差異過大時發出警告 |
| 前端靜音 | >200ms | 音訊開始得太晚(旁白延遲) |
| 尾端靜音 | >500ms | 結尾有不必要的靜音 |
| 說話速度 | 2-4.5 wps | 最佳約每秒 3 個單字 |
驗證現有音訊
# 驗證專案中的所有場景
node .claude/skills/elevenlabs-remotion-skill/generate.js --validate public/audio/product-demo/
輸出範例:
🔍 Validating product-demo (6 scenes)
❌ scene1: 3.00s (expected: 4.5s)
❌ Audio 1.50s shorter than expected
👍 8 words @ 3.1 words/sec
⚠️ scene2: 6.35s (expected: 5.5s)
⚠️ Leading silence: 235ms (may start late)
🐢 10 words @ 1.8 words/sec
✅ scene4: 4.36s (expected: 4s)
👍 9 words @ 2.3 words/sec
📊 Total duration: 30.80s (expected: 30.00s)
更新後的 info.json
驗證後,info.json 會包含實際測量數據:
{
"scenes": [
{
"id": "scene1",
"duration": 4.5,
"actualDuration": 3.0,
"leadingSilence": 0.05,
"wordsPerSecond": 3.1
}
]
}
在 Remotion 合成中,請使用 actualDuration 以確保精確同步。
選項
| 選項 | 說明 | 預設值 |
|---|---|---|
--text, -t | 要轉換為語音的文字 | 必要參數(或 --file/--scenes) |
--file, -f | 從檔案讀取文字 | - |
--output, -o | 輸出檔案路徑 | output.mp3 |
--output-dir | 場景的輸出目錄 | public/audio |
--voice, -v | 語音名稱或 ID | George |
--model, -m | 模型 ID | eleven_multilingual_v2 |
--character, -c | 角色預設 | literal |
--scenes | 包含場景的 JSON 檔案 | - |
--scene | 重新產生單一場景 ID | - |
--new-text | 場景重新產生的新文字 | - |
--validate | 驗證現有音訊目錄 | - |
--skip-validation | 跳過自動驗證 | false |
--embed-thumbnail | 要嵌入縮圖的影片檔案 | - |
--thumbnail | 縮圖圖片檔案 (PNG/JPG) | - |
--stability | 語音穩定性 (0-1) | 依角色而異 |
--similarity | 語音相似度 (0-1) | 依角色而異 |
--style | 風格誇張程度 (0-1) | 依角色而異 |
--no-combined | 跳過產生合併檔案 | false |
推薦語音
| 語音 | 風格 | 最佳用途 |
|---|---|---|
George | 溫暖迷人的英式腔調 | 旁白、解說 |
Antoni | 專業、溫暖 | 法律內容、教學 |
Arnold | 權威、深沉 | 企業、嚴肅主題 |
Josh | 友善、對話感 | 行銷、休閒內容 |
與 Remotion 整合
產生場景語音旁白後,在您的合成中使用它們:
import { Audio, Sequence, staticFile } from "remotion";
// 使用個別場景音訊檔案以達到精確同步
const SCENE_DURATIONS = {
scene1: 4.5, // 取自 info.json
scene2: 5.5,
scene3: 8.0,
};
export const VideoWithVoiceover: React.FC = () => {
const { fps } = useVideoConfig();
const scene1Frames = Math.round(SCENE_DURATIONS.scene1 * fps);
const scene2Frames = Math.round(SCENE_DURATIONS.scene2 * fps);
return (
<>
<Sequence from={0} durationInFrames={scene1Frames}>
<Audio src={staticFile("audio/project/project-scene1.mp3")} />
<Scene1Visual />
</Sequence>
<Sequence from={scene1Frames} durationInFrames={scene2Frames}>
<Audio src={staticFile("audio/project/project-scene2.mp3")} />
<Scene2Visual />
</Sequence>
</>
);
};
最佳實踐技巧
- 使用角色預設:不要逐字朗讀螢幕文字,改用
narrator或expert來達到自然的語調 - 標點符號很重要:使用句號表示停頓,逗號表示短暫中斷
- 數字:寫出數字(例如「五百」,而非「500」)以達到自然的語音效果
- 縮寫:寫出完整單字(例如「二十四小時」,而非「24h」)
- 逐場景處理:不同場景可以使用不同角色(戲劇化開場、冷靜的 CTA)
- 微調:使用
--scene重新產生個別場景,無需全部重做 - 請求拼接:使所有場景的語音保持一致
工作流程範例
# 1. 使用您的腳本建立 scenes.json
# 2. 使用旁白風格產生所有場景
node .claude/skills/elevenlabs-remotion-skill/generate.js \
--scenes remotion/my-video-scenes.json \
--character narrator \
--output-dir public/audio/my-video/
# 3. 在 Remotion 中預覽,發現 scene2 開始得太早
# 4. 僅重新產生 scene2,並使用更新後的文字
node .claude/skills/elevenlabs-remotion-skill/generate.js \
--scenes remotion/my-video-scenes.json \
--scene scene2 \
--new-text "略長一些的文字,以符合視覺時長" \
--output-dir public/audio/my-video/
# 5. 根據 info.json 中的新時長更新影片合成
# 6. 重複直到時機完美為止