Documentation Index
Fetch the complete documentation index at: https://docs.sf-voice.sh/llms.txt
Use this file to discover all available pages before exploring further.
本指南将带你使用 TypeScript SDK,从 API 密钥到获得第一个搜索结果。
pnpm add @sf-voice/media@latest
1. 创建客户端
import { SfVoiceMedia } from "@sf-voice/media";
const client = new SfVoiceMedia({
baseUrl: "https://api.sf-voice.com",
apiKey: process.env.SF_VOICE_API_KEY!,
});
2. 摄取一个资产
使用来自你自己系统的 asset_id。使用 asset_class 将应一起搜索的资产分组,
例如某个客户的全部媒体。
const ingest = await client.ingest({
source: "url",
asset_id: "video_123",
asset_class: "customer_acme",
url: "https://example.com/recording.mp4",
media_type: "video",
types: ["video", "audio", "transcript"],
metadata: {
title: "product demo",
customer_id: "acme",
},
});
响应中包含用于索引的 task_id。
{
"asset_id": "video_123",
"task_id": "task_abc123",
"status": "pending"
}
3. 等待索引
const task = await client.pollTask(ingest.task_id, {
intervalMs: 2_000,
timeoutMs: 120_000,
});
if (task.status === "failed") {
throw new Error(task.error ?? "ingest task failed");
}
4. 搜索
在相同的 asset_class 内进行搜索,以确保结果仅限于目标客户或分组。
const search = await client.search({
query: "where does the customer mention pricing?",
asset_class: "customer_acme",
types: ["transcript"],
threshold: 0.7,
limit: 10,
});
console.log(search.results);
完整示例
import { SfVoiceMedia, SfVoiceMediaError } from "@sf-voice/media";
const client = new SfVoiceMedia({
baseUrl: "https://api.sf-voice.com",
apiKey: process.env.SF_VOICE_API_KEY!,
});
try {
const ingest = await client.ingest({
source: "url",
asset_id: "video_123",
asset_class: "customer_acme",
url: "https://example.com/recording.mp4",
media_type: "video",
types: ["video", "audio", "transcript"],
});
const task = await client.pollTask(ingest.task_id);
if (task.status === "failed") {
throw new Error(task.error ?? "ingest task failed");
}
const search = await client.search({
query: "pricing",
asset_class: "customer_acme",
types: ["transcript"],
});
console.log(search.results);
} catch (error) {
if (error instanceof SfVoiceMediaError) {
console.error(error.code, error.status, error.message);
}
throw error;
}
下一步
工作原理
了解摄取、索引、任务轮询和范围搜索是如何协同工作的。
TypeScript SDK
查看 SDK 暴露的所有输入与输出结构。