Skip to content

twischen-dot/xunfei-asr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

讯飞语音识别 Python SDK

Python Version License

基于科大讯飞语音识别 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 .

配置

方式1: 环境变量

export XUNFEI_APP_ID="your_app_id"
export XUNFEI_API_KEY="your_api_key"
export XUNFEI_API_SECRET="your_api_secret"

方式2: 配置文件

# 复制配置文件模板
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.txt

Python API

from 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

API 密钥获取

  1. 访问 科大讯飞开放平台
  2. 注册账号并登录
  3. 创建应用
  4. 获取 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

更新日志

v0.1.0 (2026-01-01)

  • 初始版本
  • 支持单文件识别
  • 支持批量处理
  • 命令行工具

About

科大讯飞语音识别 Python SDK - iFlytek Speech Recognition Python SDK

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages