Skip to content

API 文档 ​

xfyun-sdk 提供了完整的科大讯飞语音服务 API,包括语音识别、语音合成、翻译等功能。

核心模块 ​

模块说明文档链接
🎤 SpeechRecognizer语音识别 (ASR) - 实时语音转文字查看文档
🔊 SpeechSynthesizer语音合成 (TTS) - 文本转语音查看文档
🌐 Translator翻译 - 语音翻译和文本翻译查看文档

辅助模块 ​

模块说明文档链接
📦 TypesTypeScript 类型定义查看文档
🔧 Utils工具函数查看文档
📝 Logger日志工具查看文档

快速开始 ​

typescript
import { SpeechRecognizer, SpeechSynthesizer, Translator } from 'xfyun-sdk';

// 语音识别
const recognizer = new SpeechRecognizer({
  appId: 'your-app-id',
  apiKey: 'your-api-key',
  apiSecret: 'your-api-secret',
});

// 语音合成
const synthesizer = new SpeechSynthesizer({
  appId: 'your-app-id',
  apiKey: 'your-api-key',
  apiSecret: 'your-api-secret',
});

// 翻译
const translator = new Translator({
  appId: 'your-app-id',
  apiKey: 'your-api-key',
  apiSecret: 'your-api-secret',
  from: 'cn',
  to: 'en',
});

错误处理 ​

所有模块都使用统一的错误分类系统,详见 错误处理 部分。

配置选项 ​

每个模块都支持以下通用配置选项:

参数类型必填说明
appIdstring✅讯飞应用 ID
apiKeystring✅讯飞 API Key
apiSecretstring✅讯飞 API Secret
logLevelstring❌日志级别:debug / info / warn / error

MIT Licensed