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))
相关推荐
李少兄11 小时前
Windows 11 环境下 BAT 脚本无法执行的排查与修复指南
windows
糖糖单片机设计11 小时前
基于 STM32 的配网变压器涌流抑制器设计与实现
人工智能·stm32·嵌入式硬件·51单片机·语音识别
解道Jdon11 小时前
FigCraft把Figma用Rust从零重写了一遍
ide·windows·git·svn·eclipse·github·visual studio
揽秀亭长13 小时前
如何从视频中提取完整文案?常见方法及技术流程整理
人工智能·音视频·语音识别
zh731413 小时前
Docker Desktop on Windows 挂载问题根因分析
windows·docker·容器
Surpass-HC13 小时前
WSL2 windows-ubuntu
linux·windows·ubuntu
遇印记14 小时前
网络安全,数据链路层,物理层
运维·服务器·网络·windows·学习
shxjnpl14 小时前
小米 CocktailASR 带来的启示:当语音识别开始区分“谁在说话”,ASR 技术正在发生什么变化?
人工智能·语音识别
mx_jun14 小时前
Wireshark 蓝牙 HCI 日志分析常用操作速查
windows·microsoft·hci·bt
艾iYYY15 小时前
思考: C++ 万能引用与完美转发
c++·windows·microsoft