Remotion 語音旁白與字幕
為 Remotion 專案加入真實的旁白。代理會撰寫或取得旁白腳本,逐場景產生語音,並將音訊與逐字字幕整合至組合中。語音與語音複製來自 Miragea 語音引擎(https://miragea.ai/v1);請勿替換為其他 TTS。
輸出(預設資料夾 public/voiceover/,可使用 staticFile() 載入):
| 檔案 | 說明 |
|---|---|
<scene>-NN.wav | 每個台詞對應一個音訊片段 |
voiceover.wav(加上 --mp3 時也有 .mp3) | 拼接後的旁白音軌 |
voiceover.json | 時間軸:fps、durationInFrames、場景與台詞的 startMs、startFrame、durationInFrames、src |
captions.json | 用於 @remotion/captions 的 Caption[](text、startMs、endMs、timestampMs、confidence) |
captions.srt、captions.vtt | 字幕檔案,包含平衡的提示(無單字孤兒) |
0. 前置條件
- 必須在環境中設定
MIRAGEA_API_KEY(金鑰取得:https://miragea.ai/workspace/api)。請勿在對話中索取金鑰或列印它。安裝說明:「安裝 https://miragea.ai/skills/miragea-audio/install.md」。 - 執行一次
python scripts/remotion_voiceover.py check。它會列出模型與唯一有效的情緒標籤。 - 同一任務有兩種引擎可供選擇,擇一使用:
- Python(隨附,無需安裝):
python scripts/remotion_voiceover.py generate script.md - Node CLI:
npx -y github:RTY2345RR/remotion-voiceover generate script.md(相同的腳本格式;新增 HyperFramesaudio_request.json)。隨附的指令碼可使用python scripts/remotion_voiceover.py npx generate script.md呼叫它。
- Python(隨附,無需安裝):
1. 簡報(僅詢問缺少的資訊)
- 腳本,或撰寫腳本的來源(產品頁面、README、大綱)。保持台詞簡短且口語化;每行一個句子。
- 語音:演員 ID,或公開的參考片段網址加上片段中確切的語音(最佳複製效果)。片段網址必須可直接擷取(請勿使用 Hugging Face 的解析連結)。
- 場景結構(如果組合已包含
<Sequence>元件);將場景標題與它們對應。
2. 撰寫 script.md
---
voices:
narrator: https://example.com/me.wav | 片段中確切的語音。
guest: ACTOR_ID
voice: narrator
fps: 30
---
# Hook
你的 Remotion 影片終於有了真實的語音旁白。
# Launch [voice: guest]
[emotion: excited] 版本 [[2.0|two point oh]] 今日出貨。
[pause: 600ms]
渲染一次後,字幕就會落在正確的影格上。
# 標題= 一個場景(其 slug 為場景 ID)。[voice: name]、[emotion: tag]、[speed: 1.1]、[pause: 600ms]可作用於一行或一個標題。[[字幕文字|口語文字]]會在使用者介面中顯示2.0,而語音則說出「two point oh」。請以這種方式拼寫數字、版本和網址。- 先執行
plan進行乾執行(不呼叫 API),並與使用者確認較長的腳本。
3. 產生
python scripts/remotion_voiceover.py generate script.md(自動偵測 Remotion 的 public/ 資料夾;可使用 --out 覆蓋,--fps、--scene-gap 600、--gap 250、--max-chars 32、--mp3)。
- 所有台詞會一次提交並收集;複製的台詞可能需要幾分鐘。
- 如果報告任務仍在執行,請重新執行相同的指令。相同的請求會重新連接到相同的任務,已完成的台詞會重複使用,僅已編輯的台詞會重新語音化。
--take 2會強制重新錄製。
4. 整合至組合中
import {AbsoluteFill, Audio, Sequence, staticFile, useCurrentFrame, useVideoConfig} from 'remotion';
import {createTikTokStyleCaptions, Caption} from '@remotion/captions';
import timeline from '../public/voiceover/voiceover.json';
import captions from '../public/voiceover/captions.json';
export const Narrated: React.FC = () => {
const frame = useCurrentFrame();
const {fps} = useVideoConfig();
const {pages} = createTikTokStyleCaptions({captions: captions as Caption[], combineTokensWithinMilliseconds: 1200});
const ms = (frame / fps) * 1000;
const page = pages.find((p) => ms >= p.startMs && ms < p.startMs + p.durationMs);
return (
<AbsoluteFill>
{timeline.lines.map((l) => (
<Sequence key={l.id} from={l.startFrame} durationInFrames={l.durationInFrames}>
<Audio src={staticFile(l.src)} />
</Sequence>
))}
{page && <AbsoluteFill style={{justifyContent: 'flex-end', alignItems: 'center', paddingBottom: 160}}>
<div style={{fontSize: 64, fontWeight: 800, color: 'white', textShadow: '0 4px 12px #000'}}>{page.text}</div>
</AbsoluteFill>}
</AbsoluteFill>
);
};
- 從時間軸設定組合長度:在
Root.tsx中使用durationInFrames={timeline.durationInFrames},或在calculateMetadata中讀取voiceover.json。 - 場景
<Sequence>元件可使用timeline.scenes[i].startFrame/durationInFrames,使視覺效果跟隨旁白。 - 如果缺少字幕支援,請安裝:
npx remotion add @remotion/captions。 - 也可以使用單一
<Audio src={staticFile(timeline.audio)} />來取代逐個片段的音訊。
5. 交付
報告檔案、總長度(秒與影格),以及下一步(使用 npx remotion render 渲染)。僅使用使用者有權限的語音或複製內容。
範例
examples/ 目錄存放真實執行範例:script.md(女旁白與男結尾,皆為複製)、voiceover.mp3、captions.srt、captions.json 與 voiceover.json。