讯飞语音听写(流式版)WebAPI的React/Node.js SDK
npm install xf-voicebash
npm install xf-voice
`
使用示例
$3
`javascript
const XfVoiceDictation = require('xf-voice');
const recorder = new XfVoiceDictation({
APPID: '你的APPID',
APIKey: '你的APIKey',
APISecret: '你的APISecret',
onTextChange: (text) => {
console.log('识别结果:', text);
}
});
// 开始录音
recorder.start();
// 停止录音
setTimeout(() => {
recorder.stop();
}, 5000);
`
$3
`jsx
import React, { useState, useEffect } from 'react';
import XfVoiceDictation from 'xf-voice';
function VoiceRecorder() {
const [text, setText] = useState('');
useEffect(() => {
const recorder = new XfVoiceDictation({
APPID: '你的APPID',
APIKey: '你的APIKey',
APISecret: '你的APISecret',
onTextChange: (result) => {
setText(result);
}
});
return () => {
recorder.stop();
};
}, []);
return (
识别结果: {text}
);
}
export default VoiceRecorder;
`
API
$3
new XfVoiceDictation(options)
参数:
- options.APPID: 必填,讯飞开放平台APPID
- options.APIKey: 必填,讯飞开放平台APIKey
- options.APISecret: 必填,讯飞开放平台APISecret
- options.onTextChange: 识别结果回调函数
- options.onWillStatusChange: 状态变更回调函数
- options.language: 语言,默认'zh_cn'
- options.accent: 方言,默认'mandarin'
$3
- start(): 开始录音
- stop(): 停止录音
- setParams({language, accent})`: 设置识别参数