API DOCUMENT
纯梦录音识别 API
通过纯梦官网统一处理录音文件识别,调用方只需要传纯梦 API Key 和音频地址。
请求地址
POST https://puream.cn/api/ai/recording-asr
计费:按识别出的音频时长计算。提交时预冻结费用,成功后按实际时长结算,失败自动退还冻结金额。
请求参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
apiKey | string | 是 | 纯梦官网 API Key,也可放在 Authorization Bearer 中 |
url | string | 是 | 公网可访问的录音文件地址 |
referenceText | string | 否 | 兼容旧版插件变量,当前接口不改写识别参数 |
maxSubtitleLength | number | 否 | 字幕切分的理想字数,默认 10 |
返回参数
| 字段 | 类型 | 说明 |
|---|---|---|
success | boolean | 是否识别成功 |
fullText | string | 完整识别文本 |
sentenceTexts | string[] | 按字幕规则切分后的文本 |
timelines | { start: number; end: number }[] | 字幕时间轴,单位毫秒 |
all_timelines | { start: number; end: number }[] | 完整音频时间轴,单位毫秒 |
wordTimelines | { text: string; start: number; end: number }[] | 单字时间轴,单位毫秒 |
requestId | string | 本次请求 ID |
errorMsg | string | 失败原因 |
请求示例
curl -X POST "https://puream.cn/api/ai/recording-asr" \
-H "Content-Type: application/json" \
-d '{
"apiKey": "你的纯梦APIKey",
"url": "https://example.com/audio.wav",
"maxSubtitleLength": 10
}'插件代码
入参和出参变量保持不变,统一调用纯梦官网接口。
import { Args } from '@/runtime';
export interface Input {
apiKey: string;
url: string;
referenceText?: string;
maxSubtitleLength?: number;
}
export interface TimeItem { start: number; end: number; }
export interface WordTimeItem {
text: string;
start: number;
end: number;
}
export interface Output {
success: boolean;
fullText: string;
sentenceTexts: string[];
timelines: TimeItem[];
all_timelines: TimeItem[];
wordTimelines: WordTimeItem[];
requestId: string;
errorMsg?: string;
}
function emptyOutput(errorMsg: string): Output {
return {
success: false,
fullText: '',
sentenceTexts: [],
timelines: [],
all_timelines: [],
wordTimelines: [],
requestId: '',
errorMsg
};
}
export async function handler({ input, logger }: Args<Input>): Promise<Output> {
try {
if (!input.apiKey || !input.url) throw new Error('缺少 apiKey 或 url');
const res = await fetch('https://puream.cn/api/ai/recording-asr', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
apiKey: input.apiKey,
url: input.url,
referenceText: input.referenceText,
maxSubtitleLength: input.maxSubtitleLength
})
});
const data = await res.json();
return {
success: Boolean(data.success),
fullText: data.fullText || '',
sentenceTexts: Array.isArray(data.sentenceTexts) ? data.sentenceTexts : [],
timelines: Array.isArray(data.timelines) ? data.timelines : [],
all_timelines: Array.isArray(data.all_timelines) ? data.all_timelines : [],
wordTimelines: Array.isArray(data.wordTimelines) ? data.wordTimelines : [],
requestId: data.requestId || '',
errorMsg: data.errorMsg || (res.ok ? undefined : '纯梦 API 请求失败')
};
} catch (err) {
const message = (err as Error).message || '请求失败';
logger.error(message);
return emptyOutput(message);
}
}