关于 fal-audio
fal-audio 是 fal.ai 语音转文本与文本转语音模型的参考技能,面向需要调用这些模型的开发者。内容涵盖端点选择、参数说明,以及转录、翻译、字幕和语音克隆示例。
主要功能
- 01语音转文本模型与端点指南
- 02文本转语音模型与端点指南
- 03转录和翻译参数说明
- 04带时间戳的分段输出
- 05语音克隆示例
适用场景
- 01将音频或视频转录为文本
- 02生成带时间戳的字幕
- 03将语音翻译成英语
- 04根据文本生成语音或克隆音色
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ josiahsiegel/ claude-plugin-marketplace --skill fal-audio安装后在 Claude Code 中输入/fal-audio确认已加载。
详细介绍
快速参考
| STT 模型 | 端点 | 速度 | 准确度 |
|---|---|---|---|
| Whisper | fal-ai/whisper | 中等 | 最高 |
| Whisper Turbo | fal-ai/whisper-turbo | 快 | 高 |
| Whisper Large v3 | fal-ai/whisper-large-v3 | 慢 | 最高 |
| TTS 模型 | 端点 | 语音克隆 | 质量 |
|---|---|---|---|
| F5-TTS | fal-ai/f5-tts | 支持 | 高 |
| ElevenLabs | fal-ai/elevenlabs/tts | 通过 API | 最高 |
| Kokoro | fal-ai/kokoro/american-english | 不支持 | 良好 |
| XTTS | fal-ai/xtts | 支持 | 良好 |
| Whisper 任务 | 使用场景 |
|---|---|
transcribe | 同一种语言的文本 |
translate | 非英语 → 英语 |
| Whisper 参数 | 值 |
|---|---|
chunk_level | 时间戳使用 "segment" |
language | ISO 代码(例如 "en") |
何时使用此技能
用于音频处理:
- 将音频/视频转录为文本
- 生成带时间戳的字幕
- 将语音翻译成英语
- 根据参考音频克隆声音
- 根据文本生成自然语音
相关技能:
- 对于带音频的视频:请参阅
fal-text-to-video - 对于 API 集成:请参阅
fal-api-reference - 对于模型对比:请参阅
fal-model-guide
fal.ai 音频模型
fal.ai 上语音转文本(STT)和文本转语音(TTS)模型的完整参考。
语音转文本模型
Whisper(OpenAI)
端点: fal-ai/whisper
最适合: 准确转录和翻译
这款业界标准的语音识别模型支持 99 种以上语言。
import { fal } from "@fal-ai/client";
const result = await fal.subscribe("fal-ai/whisper", {
input: {
audio_url: "https://example.com/speech.mp3",
task: "transcribe",
language: "en",
chunk_level: "segment"
}
});
console.log(result.text);
console.log(result.chunks); // With timestamps
import fal_client
result = fal_client.subscribe(
"fal-ai/whisper",
arguments={
"audio_url": "https://example.com/speech.mp3",
"task": "transcribe",
"language": "en",
"chunk_level": "segment"
}
)
print(result["text"])
for chunk in result["chunks"]:
print(f"[{chunk['timestamp'][0]:.2f}-{chunk['timestamp'][1]:.2f}] {chunk['text']}")
Whisper 参数:
| 参数 | 类型 | 值 | 描述 |
|---|---|---|---|
audio_url | string | - | 音频文件 URL |
task | string | "transcribe", "translate" | 转录或翻译成英语 |
language | string | ISO 代码 | 源语言(可选,自动检测) |
chunk_level | string | "segment" | 返回时间戳 |
version | string | "3" | Whisper 版本 |
响应结构:
interface WhisperOutput {
text: string; // Full transcription
chunks?: Array<{
text: string;
timestamp: [number, number]; // [start, end] in seconds
}>;
}
Whisper Turbo
端点: fal-ai/whisper-turbo
最适合: 快速转录
const result = await fal.subscribe("fal-ai/whisper-turbo", {
input: {
audio_url: "https://example.com/podcast.mp3",
task: "transcribe"
}
});
Whisper Large v3
端点: fal-ai/whisper-large-v3
最适合: 最高准确度
const result = await fal.subscribe("fal-ai/whisper-large-v3", {
input: {
audio_url: "https://example.com/meeting.mp3",
task: "transcribe",
language: "en"
}
});
Whisper 使用示例
带时间戳的转录:
const result = await fal.subscribe("fal-ai/whisper", {
input: {
audio_url: audioUrl,
task: "transcribe",
chunk_level: "segment"
}
});
// Format as SRT subtitles
result.chunks.forEach((chunk, i) => {
const start = formatTime(chunk.timestamp[0]);
const end = formatTime(chunk.timestamp[1]);
console.log(`${i + 1}\n${start} --> ${end}\n${chunk.text}\n`);
});
function formatTime(seconds: number): string {
const h = Math.floor(seconds / 3600);
const m = Math.floor((seconds % 3600) / 60);
const s = Math.floor(seconds % 60);
const ms = Math.floor((seconds % 1) * 1000);
return `${h.toString().padStart(2, '0')}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')},${ms.toString().padStart(3, '0')}`;
}
翻译(非英语到英语):
const result = await fal.subscribe("fal-ai/whisper", {
input: {
audio_url: "https://example.com/french-speech.mp3",
task: "translate", // Translates to English
language: "fr"
}
});
console.log(result.text); // English translation
多语言检测:
// Whisper auto-detects language if not specified
const result = await fal.subscribe("fal-ai/whisper", {
input: {
audio_url: "https://example.com/unknown-language.mp3",
task: "transcribe"
// language omitted - auto-detect
}
});
文本转语音模型
F5-TTS
端点: fal-ai/f5-tts
最适合: 根据参考音频克隆声音
const result = await fal.subscribe("fal-ai/f5-tts", {
input: {
gen_text: "Hello! Welcome to our product demonstration. We're excited to show you what we've built.",
ref_audio_url: "https://example.com/voice-sample.wav",
ref_text: "This is a sample of my voice for cloning purposes.",
model_type: "F5-TTS"
}
});
console.log(result.audio_url);
result = fal_client.subscribe(
"fal-ai/f5-tts",
arguments={
"gen_text": "Hello! Welcome to our product.",
"ref_audio_url": "https://example.com/voice-sample.wav",
"ref_text": "This is a sample of my voice."
}
)
print(result["audio_url"])
F5-TTS 参数:
| 参数 | 类型 | 描述 |
|---|---|---|
gen_text | string | 要合成的文本 |
ref_audio_url | string | 参考语音音频 URL |
ref_text | string | 参考音频的转录文本 |
model_type | string | "F5-TTS" 或 "E2-TTS" |
remove_silence | boolean | 移除输出中的静音 |
ElevenLabs TTS
端点: fal-ai/elevenlabs/tts
最适合: 高级语音质量
const result = await fal.subscribe("fal-ai/elevenlabs/tts", {
input: {
text: "Welcome to fal.ai! Let me tell you about our amazing AI models.",
voice_id: "21m00Tcm4TlvDq8ikWAM", // ElevenLabs voice ID
model_id: "eleven_multilingual_v2"
}
});
console.log(result.audio.url);
ElevenLabs 参数:
| 参数 | 类型 | 描述 |
|---|---|---|
text | string | 要合成的文本 |
voice_id | string | ElevenLabs 语音 ID |
model_id | string | TTS 模型版本 |
stability | number | 语音稳定性(0-1) |
similarity_boost | number | 语音相似度(0-1) |
ElevenLabs 语音 ID(示例):
21m00Tcm4TlvDq8ikWAM- Rachel(女声)AZnzlk1XvdvUeBnXmlld- Domi(女声)EXAVITQu4vr4xnSDxMaL- Bella(女声)ErXwobaYiN019PkySvjV- Antoni(男声)VR6AewLTigWG4xSOukaG- Arnold(男声)
Kokoro TTS
端点: fal-ai/kokoro/american-english
最适合: 多语言、自然流畅的语音
const result = await fal.subscribe("fal-ai/kokoro/american-english", {
input: {
text: "This is a test of the Kokoro text-to-speech system.",
voice: "af_bella" // Voice style
}
});
console.log(result.audio.url);
Kokoro 变体:
fal-ai/kokoro/american-english- 美式英语fal-ai/kokoro/british-english- 英式英语fal-ai/kokoro/japanese- 日语fal-ai/kokoro/mandarin- 中文普通话
Kokoro 参数:
| 参数 | 类型 | 描述 |
|---|---|---|
text | 字符串 | 要合成的文本 |
voice | 字符串 | 语音风格标识符 |
speed | 数字 | 语速倍数 |
XTTS(Coqui)
端点: fal-ai/xtts
最适合: 开源语音克隆
const result = await fal.subscribe("fal-ai/xtts", {
input: {
text: "Hello, this is a cloned voice speaking.",
audio_url: "https://example.com/voice-reference.wav",
language: "en"
}
});
XTTS 参数:
| 参数 | 类型 | 描述 |
|---|---|---|
text | 字符串 | 要合成的文本 |
audio_url | 字符串 | 用于克隆的参考音频 |
language | 字符串 | 目标语言 |
模型对比
语音转文本
| 模型 | 速度 | 准确度 | 语言 | 最适合 |
|---|---|---|---|---|
| Whisper | 中等 | 最高 | 99+ | 对准确度要求高 |
| Whisper Turbo | 快 | 高 | 99+ | 需要速度 |
| Whisper Large v3 | 慢 | 最高 | 99+ | 追求最高质量 |
文本转语音
| 模型 | 质量 | 语音克隆 | 语言 | 最适合 |
|---|---|---|---|---|
| F5-TTS | 高 | 是 | 多种 | 语音克隆 |
| ElevenLabs | 最高 | 通过 API | 多种 | 高端品质 |
| Kokoro | 良好 | 否 | 多种 | 多语言 |
| XTTS | 良好 | 是 | 16 | 开源 |
工作流示例
转录和翻译流程
async function processAudio(audioUrl: string, targetLanguage: string = 'en') {
// 1. Transcribe
const transcription = await fal.subscribe("fal-ai/whisper", {
input: {
audio_url: audioUrl,
task: "transcribe",
chunk_level: "segment"
}
});
// 2. If not English, translate
let translation = null;
if (targetLanguage === 'en') {
translation = await fal.subscribe("fal-ai/whisper", {
input: {
audio_url: audioUrl,
task: "translate"
}
});
}
return {
original: transcription.text,
translated: translation?.text,
chunks: transcription.chunks
};
}
语音克隆流程
async function cloneVoiceAndSpeak(
referenceAudioUrl: string,
referenceText: string,
textToSpeak: string
) {
// Use F5-TTS for voice cloning
const result = await fal.subscribe("fal-ai/f5-tts", {
input: {
gen_text: textToSpeak,
ref_audio_url: referenceAudioUrl,
ref_text: referenceText,
remove_silence: true
}
});
return result.audio_url;
}
字幕生成
async function generateSubtitles(videoUrl: string): Promise<string> {
// Extract audio and transcribe
const result = await fal.subscribe("fal-ai/whisper", {
input: {
audio_url: videoUrl, // Works with video URLs too
task: "transcribe",
chunk_level: "segment"
}
});
// Generate SRT format
let srt = '';
result.chunks.forEach((chunk, i) => {
srt += `${i + 1}\n`;
srt += `${formatSrtTime(chunk.timestamp[0])} --> ${formatSrtTime(chunk.timestamp[1])}\n`;
srt += `${chunk.text}\n\n`;
});
return srt;
}
function formatSrtTime(seconds: number): string {
const date = new Date(seconds * 1000);
return date.toISOString().substr(11, 12).replace('.', ',');
}
有声读物生成
async function generateAudioBook(chapters: string[], voiceId: string) {
const audioUrls = [];
for (const chapter of chapters) {
// Split into manageable chunks
const chunks = splitText(chapter, 5000);
for (const chunk of chunks) {
const result = await fal.subscribe("fal-ai/elevenlabs/tts", {
input: {
text: chunk,
voice_id: voiceId,
model_id: "eleven_multilingual_v2"
}
});
audioUrls.push(result.audio.url);
}
}
return audioUrls;
}
function splitText(text: string, maxLength: number): string[] {
const chunks = [];
let current = '';
text.split('. ').forEach(sentence => {
if ((current + sentence).length < maxLength) {
current += sentence + '. ';
} else {
chunks.push(current.trim());
current = sentence + '. ';
}
});
if (current) chunks.push(current.trim());
return chunks;
}
参数参考
语音转文本输入
interface STTInput {
audio_url: string;
task?: "transcribe" | "translate";
language?: string; // ISO 639-1 code
chunk_level?: "segment";
version?: string;
}
文本转语音输入
interface TTSInput {
// Common
text?: string;
gen_text?: string;
// Voice cloning
ref_audio_url?: string;
ref_text?: string;
audio_url?: string; // XTTS
// Voice selection
voice_id?: string; // ElevenLabs
voice?: string; // Kokoro
model_type?: string; // F5-TTS
// Control
speed?: number;
stability?: number;
similarity_boost?: number;
language?: string;
remove_silence?: boolean;
}
最佳实践
语音转文本
- 音频质量: 音频越清晰,转录效果越好
- 指定语言: 已知语言时,请提供语言提示
- 使用时间戳: 请求
chunk_level: "segment"以生成字幕 - 处理长音频: Whisper 会自动处理长文件
- 翻译: 将非英语内容翻译成英语时,使用
task: "translate"
文本转语音
- 参考音频质量: 进行语音克隆时,请使用 10-30 秒的清晰样本
- 参考转录文本: 准确的转录文本有助于提高克隆质量
- 文本长度: 将特别长的文本拆分成多个片段
- 标点符号: 使用恰当的标点符号可改善韵律
- 情绪提示: 使用标点符号(!、?)表达情绪
常见支持的语言
| 语言 | 代码 | STT | TTS |
|---|---|---|---|
| 英语 | en | 是 | 是 |
| 西班牙语 | es | 是 | 是 |
| 法语 | fr | 是 | 是 |
| 德语 | de | 是 | 是 |
| 意大利语 | it | 是 | 是 |
| 葡萄牙语 | pt | 是 | 是 |
| 日语 | ja | 是 | 是 |
| 中文 | zh | 是 | 是 |
| 韩语 | ko | 是 | 是 |
| 俄语 | ru | 是 | 有限支持 |
文件格式支持
输入格式(STT)
| 格式 | 扩展名 | 支持 |
|---|---|---|
| MP3 | .mp3 | 是 |
| WAV | .wav | 是 |
| M4A | .m4a | 是 |
| FLAC | .flac | 是 |
| OGG | .ogg | 是 |
| WebM | .webm | 是 |
| 视频 | .mp4 | 是(提取音频) |
输出格式(TTS)
| 模型 | 输出格式 |
|---|---|
| F5-TTS | WAV |
| ElevenLabs | MP3 |
| Kokoro | WAV |
| XTTS | WAV |
错误处理
try {
const result = await fal.subscribe("fal-ai/whisper", {
input: { audio_url: audioUrl, task: "transcribe" }
});
} catch (error) {
if (error.status === 400) {
console.error("Invalid audio file or URL");
} else if (error.status === 413) {
console.error("Audio file too large");
} else {
console.error("Transcription failed:", error.message);
}
}
评论
支持 Markdown