基于科大讯飞语音识别 API 的 Python SDK,提供简单易用的命令行工具和 Python 库。
- ✅ 单文件语音识别
- ✅ 批量文件处理
- ✅ 命令行工具
- ✅ Python API
- ✅ 进度条显示
- ✅ 多种配置方式(环境变量/配置文件)
# 克隆仓库
git clone https://github.com/yourusername/xunfei-asr.git
cd xunfei-asr
# 安装依赖
pip install -r requirements.txt
# 安装包
pip install -e .export XUNFEI_APP_ID="your_app_id"
export XUNFEI_API_KEY="your_api_key"
export XUNFEI_API_SECRET="your_api_secret"# 复制配置文件模板
cp config.example.yaml config.yaml
# 编辑 config.yaml 填入你的 API 密钥# 识别单个文件
xunfei-asr recognize audio.wav
# 使用配置文件
xunfei-asr recognize audio.wav --config config.yaml
# 批量处理
xunfei-asr batch input_dir/ output.txtfrom xunfei_asr import XunfeiASR
# 从环境变量加载
client = XunfeiASR.from_env()
# 从配置文件加载
client = XunfeiASR.from_config("config.yaml")
# 直接传入参数
client = XunfeiASR(
app_id="your_app_id",
api_key="your_api_key",
api_secret="your_api_secret"
)
# 识别音频文件
result = client.recognize_file("audio.wav")
print(result)查看 examples/ 目录获取更多示例:
basic_usage.py- 基础使用示例batch_process.py- 批量处理示例
- 格式: WAV
- 采样率: 16000 Hz
- 声道: 单声道 (Mono)
- 编码: PCM
如果你的音频不符合要求,可以使用 ffmpeg 转换:
ffmpeg -i input.mp3 -ar 16000 -ac 1 output.wav- 访问 科大讯飞开放平台
- 注册账号并登录
- 创建应用
- 获取 APPID、APIKey、APISecret
免费额度: 500次/天
xunfei-asr/
├── xunfei_asr/ # 主包
│ ├── __init__.py
│ ├── client.py # API 客户端
│ ├── config.py # 配置管理
│ └── cli.py # 命令行接口
├── examples/ # 示例代码
├── tests/ # 测试代码
├── docs/ # 文档
├── requirements.txt # 依赖
├── setup.py # 安装配置
└── README.md # 说明文档
# 安装开发依赖
pip install -r requirements.txt
# 运行测试
pytest tests/
# 安装为可编辑模式
pip install -e .MIT License
欢迎提交 Issue 和 Pull Request!
Your Name
- 初始版本
- 支持单文件识别
- 支持批量处理
- 命令行工具