Whisper——部署fast-whisper中文语音识别模型

环境配置

bash 复制代码
pip install faster-whisper transformers

准备tiny模型

需要其他版本的可以自己下载:https://huggingface.co/openai

  • 原始中文语音模型:
bash 复制代码
https://huggingface.co/openai/whisper-tiny
  • 微调后的中文语音模型:
bash 复制代码
git clone https://huggingface.co/xmzhu/whisper-tiny-zh
  • 补下一个:tokenizer.json
bash 复制代码
https://huggingface.co/openai/whisper-tiny/resolve/main/tokenizer.json?download=true

模型转换

  • float16
bash 复制代码
ct2-transformers-converter --model whisper-tiny-zh/ --output_dir whisper-tiny-zh-ct2 --copy_files tokenizer.json preprocessor_config.json --quantization float16
  • int8
bash 复制代码
ct2-transformers-converter --model whisper-tiny-zh/ --output_dir whisper-tiny-zh-ct2-int8 --copy_files tokenizer.json preprocessor_config.json --quantization int8

代码

bash 复制代码
from faster_whisper import WhisperModel

# model_size = "whisper-tiny-zh-ct2"
# model_size = "whisper-tiny-zh-ct2-int8"

# Run on GPU with FP16
# model = WhisperModel(model_size, device="cuda", compute_type="float16")
model = WhisperModel(model_size, device="cpu", compute_type="int8")

# or run on GPU with INT8
# model = WhisperModel(model_size, device="cuda", compute_type="int8_float16")
# or run on CPU with INT8
# model = WhisperModel(model_size, device="cpu", compute_type="int8")

segments, info = model.transcribe("output_file.wav", beam_size=5, language='zh')

print("Detected language '%s' with probability %f" % (info.language, info.language_probability))

for segment in segments:
    print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
相关推荐
hongjunwu21 小时前
Java集合的遍历方式(全解析)
java·开发语言·windows
Bruce_Liuxiaowei1 天前
.htaccess 文件上传漏洞绕过总结
windows·安全·网络安全·php·apache
青山师1 天前
Docker部署whisper转写模型
docker·容器·whisper
跟我聊天我会闯红灯1 天前
如何开发一个运行在windows系统服务器上的服务
运维·服务器·windows
要记得喝水1 天前
汇编中常用寄存器介绍
开发语言·汇编·windows·c#·.net
TToolss2 天前
Windows中安装rustup-init.exe以及cargo build报错443
windows
我怎么又饿了呀2 天前
Windows&Linux系统 安装 CUDA 和 cuDNN
linux·运维·windows
阿昭L2 天前
windows线程基础
windows
一起去改变世界2 天前
卸载或重装软件提示缺少msi的解决方法(软件卸载功能修复)
windows·bug·美女
LZQqqqqo2 天前
WinForm 对话框的 Show 与 ShowDialog:阻塞与非阻塞的抉择
服务器·windows·microsoft·winform