@nextcas/voice
v1.0.2
Published
@nextcas/sdk的语音拓展
Downloads
9
Readme
注意:录音需要 Https,或者本地 localhost 才可以调用
手动录音
instance( token: string, actorId: string ): Record
token: 授权 token actorId: 智能体ID
start():Promise<void>
开始录音(需要页面交互触发)
stopToText(model?:Model):Promise<string>
model: 语言模型见最下方表格
demo
import { Record } from "@nextcas/voice";
const record = new Record(token.data, "641811add41a3f2f91247af5");
record.start().then(() => {
recording = true;
});
record
.stopToText(model?:Model)
.then((text) => {
console.log(text);
})
.finally(() => {
recording = false;
});
ASR 集成
instance( token: string, options: AsrOptions ): Asr
token: 授权 token
AsrOptions
AsrOptions{
actorId: string;
model?: Model;
}
actorId 智能体ID model: 语言模型见最下方表格
start():<void>
开启ASR(需要页面交互触发)
stop():void
关闭ASR
Events
| model | 语言 | event值|
| :------------- | ---------------: |---------------: |
| ready | 初始化完成 | _
|
| sentenceBegin | 监测到新的句子开始 | _
|
| sentenceChange | 识别中(可以查看识别过程中的句子变化) | string
|
| sentenceEnd | 当前句子识别结束 |string
|
| error | 错误 |error,string
|
AsrOptions{
actorId: string;
model?: Model;
}
Asr(token:string, options: AsrOptions)
demo
const record = new Asr(token, { actorId: "actor_100990" });
let recording = false;
let inited = false;
record.on("ready", () => {
inited = true;
// ready 后再开始识别
});
record.on("error", (err) => {
console.log(err);
});
record.on("sentenceBegin", () => {
console.log("一句话识别开始");
speacking = true;
});
record.on("sentenceChange", (text: string) => {
console.log("一句话识别中", text);
sentenceRes = text;
});
record.on("sentenceEnd", (text: string) => {
console.log("一句话识别结束", text);
speacking = false;
});
function start() {
if (inited) {
record.start();
}
}
function stop() {
record.stop();
}
Model
| model | 语言 | | :------------- | ---------------: | | 中文通用 | '16k_zh' | | 中英粤 | '16k_zh-PY' | | 中文繁体(台湾) | '16k_zh-TW' | | 中文教育 | '16k_zh_edu' | | 中文医疗 | '16k_zh_medical' | | 中文法庭 | '16k_zh_court' | | 中文多地方言 | '16k_zh_dialect' | | 中文粤语 | '16k_yue' | | 英文通用 | '16k_en' | | 英文游戏 | '16k_en_game' | | 英文教育 | '16k_en_edu' | | 韩语 | '16k_ko' | | 日语 | '16k_ja' | | 泰语 | '16k_th' | | 印度尼西亚语 | '16k_id' | | 越南语 | '16k_vi' | | 马来语 | '16k_ms' | | 菲律宾语 | '16k_fil' | | 葡萄牙语 | '16k_pt' | | 土耳其语 | '16k_tr' | | 阿拉伯语 | '16k_ar' | | 西班牙语 | '16k_es' | | 印地语 | '16k_hi' |