This repository has been archived on 2025-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
Files

84 lines
4.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# tiangai100-sensevoice-funasr & tiangai100-whisper
## 天数智芯 天垓100 语音识别
该模型测试框架在天垓100加速卡上适配 sensevoice 和 whisper 大类下的模型,将语音信号转换为文本。
SenseVoice 是由 FunAudioLLM 开发的一款开源音频处理模型,是阿里巴巴通义实验室推出的语音技术框架的核心模型之一,为高效、准确的多语言语音识别和音频分析工具。
该 sensevoice 测试框架支持 Sensevoice-Small 和 Sensevoice-Large 模型。
whisper 模型是 OpenAI 发布的一个通用语音识别模型,具有多语言支持、多任务学习等特点,采用编码器 - 解码器的 Transformer 结构。
该whisper测试框架支持tiny、base、small、medium、large、large-v2、large-v3等。
## sensevoice 模型测试服务原理
通过 AutoModel funasr 库提供的一个自动模型加载工具)加载 SenseVoice 模型,然后用 model.generate(...) 调用模型进行语音识别,其中 generate 是模型封装好的接口,内部实现了完整的语音识别流程。
## whisper 模型测试服务原理
pipeline 为 Hugging Face transformers 库提供的高层 API 用于快速构建特定任务的处理管道。pipeline 内部封装了语音预处理(如特征提取)、模型推理、结果后处理(如文本解码)等步骤,简化了语音识别的调用流程。代码中调用 pipeline 自动完成从音频数据到文本的转换。
## 如何使用 sensevoice 和 whisper 测试框架
代码实现了一个接收音频数据并返回识别文本的语音识别 HTTP 服务,并基于 corex:3.2.1 基础镜像,将该 HTTP 服务重新打包成 docker 镜像,通过 k8s 集群sut容器去请求这个 HTTP 服务。
## sensevoice 和 whisper 语音识别模型测试服务请求示例
```python
import requests
# 服务健康检查
response = requests.get(f"{sut_url}/health")
print(response.status_code, response.text)
# 服务地址根据实际部署情况修改IP和端口,端口为80
url = f"{sut_url}/recognition"
#url = "http://localhost:80/recognition"
# 读取音频文件需是服务支持的格式如wav等
with open("audio.wav", "rb") as f:
audio_data = f.read()
# 请求参数(可选,指定语言,如中文为'zh'
params = {
"language": "zh" # 支持的语言代码需参考whisper模型的支持列表
}
# 发送POST请求
response = requests.post(
url,
data=audio_data, # 音频数据放在请求体中
params=params # 参数放在URL查询字符串中
)
# 请求体data 参数)需要传入二进制音频数据
# 语言参数language是可选的默认值为 en英语
# 支持的语言代码可参考 whisper 模型的官方文档(如中文是 zh日语是 ja 等)
# 确保音频文件格式被模型支持whisper 通常支持 wav、mp3 等常见格式)
# 解析响应结果
if response.status_code == 200:
result = response.json()
print("识别状态:", result["RecognitionStatus"])
print("识别结果:", result["DisplayText"])
else:
print("请求失败,状态码:", response.status_code)
```
成功时返回 JSON 格式的响应
```json
{
"RecognitionStatus": "Success",
"DisplayText": "识别到的文本内容"
}
```
## 天垓100 SenseVoiceSmall 模型测试结果
测试方式为在 天垓100 加速卡和 Nvidia A100 上对同一段音频约10s进行语音识别任务获取运行时间
| 模型类型 | 模型名称 | 天垓100运行时间/s | Nvidia A100运行时间/s |
|------------|----------------|-------------------|-----------------------|
| sensevoice | SenseVoiceSmall | 0.2 | 0.06 |
## 天垓100 whisper-tiny 模型测试结果
测试方式为在 天垓100 加速卡和 CPU 上对同一段长音频约9120s进行语音识别任务获取运行时间1-cer指标
| 模型类型 | 模型名称 | 天垓 A100对比CPU加速比 | 天垓 A100 1-cer | CPU 1-cer |
|----------|-------------|------------------------|-----------------|-----------|
| whisper | whisper-tiny | 3.24x | 0.792 | 0.794 |