
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
科大讯飞语音识别 SDK,支持浏览器中实时语音听写功能。基于科大讯飞开放平台 WebAPI 开发,提供了简单易用的接口和 React 组件。
npm install xfyun-sdk
# 或者
yarn add xfyun-sdk
import { XfyunASR } from 'xfyun-sdk';
// 创建识别器实例
const recognizer = new XfyunASR({
appId: 'your_app_id',
apiKey: 'your_api_key',
apiSecret: 'your_api_secret',
language: 'zh_cn',
accent: 'mandarin',
vadEos: 3000
}, {
onRecognitionResult: (text) => {
console.log('识别结果:', text);
},
onError: (error) => {
console.error('错误:', error);
}
});
// 开始识别
await recognizer.start();
// 停止识别
recognizer.stop();
import { SpeechRecognizer } from 'xfyun-sdk';
function App() {
return (
<SpeechRecognizer
appId="your_app_id"
apiKey="your_api_key"
apiSecret="your_api_secret"
onResult={(text) => console.log('识别结果:', text)}
onError={(error) => console.error('错误:', error)}
/>
);
}
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| appId | string | 是 | - | 科大讯飞开放平台应用 ID |
| apiKey | string | 是 | - | 科大讯飞开放平台 API Key |
| apiSecret | string | 是 | - | 科大讯飞开放平台 API Secret |
| language | 'zh_cn' | 'en_us' | 否 | 'zh_cn' | 识别语言 |
| domain | 'iat' | 'medical' | 'assistant' | 否 | 'iat' | 识别领域 |
| accent | 'mandarin' | 'cantonese' | 否 | 'mandarin' | 方言 |
| vadEos | number | 否 | 3000 | 静默检测时间(毫秒) |
| maxAudioSize | number | 否 | 1024 * 1024 | 最大音频大小(字节) |
| autoStart | boolean | 否 | false | 是否自动开始识别 |
| hotWords | string[] | 否 | - | 热词列表 |
| audioFormat | string | 否 | 'audio/L16;rate=16000' | 音频格式 |
| 方法名 | 说明 | 参数 | 返回值 |
|---|---|---|---|
| start | 开始识别 | - | Promise |
| stop | 停止识别 | - | void |
| getResult | 获取识别结果 | - | string |
| getState | 获取当前状态 | - | RecognizerState |
| clearResult | 清除识别结果 | - | void |
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| start | 开始识别时触发 | - |
| stop | 停止识别时触发 | - |
| result | 识别结果时触发 | text: string |
| error | 发生错误时触发 | error: XfyunError |
| process | 处理中时触发 | volume: number |
| stateChange | 状态改变时触发 | state: RecognizerState |
| 属性 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| appId | string | 是 | - | 科大讯飞开放平台应用 ID |
| apiKey | string | 是 | - | 科大讯飞开放平台 API Key |
| apiSecret | string | 是 | - | 科大讯飞开放平台 API Secret |
| onStart | () => void | 否 | - | 开始识别回调 |
| onStop | () => void | 否 | - | 停止识别回调 |
| onResult | (text: string) => void | 否 | - | 识别结果回调 |
| onError | (error: XfyunError) => void | 否 | - | 错误回调 |
| onProcess | (volume: number) => void | 否 | - | 处理中回调 |
| onStateChange | (state: RecognizerState) => void | 否 | - | 状态改变回调 |
问题描述: 语音识别过程正常,但没有返回识别结果或结果始终为空。
可能原因:
解决方案:
vadEos 参数值(例如5000ms),避免过早结束识别问题描述: 出现"认证失败"或"签名错误"相关的错误信息。
可能原因:
解决方案:
问题描述: 在某些浏览器中无法正常工作。
可能原因:
解决方案:
start()方法前确保已获得用户授权问题描述: WebSocket无法连接或频繁断开。
可能原因:
解决方案:
问题描述: 使用SDK时CPU占用高或出现卡顿。
可能原因:
解决方案:
stop()方法释放资源查看 examples 目录获取更多示例:
查看 CHANGELOG.md 了解详细更新内容。
MIT License - 查看 LICENSE 文件了解详情。
欢迎提交 Issue 和 Pull Request!
查看 CONTRIBUTING.md 了解如何参与贡献。
FAQs
科大讯飞语音识别 SDK,支持浏览器中实时语音听写功能
We found that xfyun-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.