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))
相关推荐
DexterLien2 分钟前
EC2 Windows 对 EBS 根卷进行缩容
windows·aws·ec2
朝阳58113 分钟前
M3U8 下载助手油猴脚本 - 完全使用指南
前端·javascript·windows
无风听海31 分钟前
.NET10之C# Target-typed new expression深入解析
windows·c#·.net
别抢我的锅包肉35 分钟前
【python-Pyspark】环境搭建及案例(Windows)
windows
long_songs39 分钟前
Python编程第02课:Windows/Mac/Linux环境安装配置详解
windows·python·macos
百事牛科技1 小时前
高效办公技巧:如何取消PPT以“只读方式”打开?
windows·powerpoint
BIBI20491 小时前
VirtualBox 7.x 安装 Ubuntu 24 及增强功能配置、克隆虚拟机教程
linux·windows·ubuntu·环境搭建·安装教程·最佳实践·virtualbox
Master_H_ice11 小时前
Claude Code安装试用记录(Windows)
windows·claude code
芳草萋萋鹦鹉洲哦13 小时前
【windows】nginx如何注册为开机自启的服务(WinSW实现)
运维·windows·nginx
好名字更能让你们记住我13 小时前
vmware虚拟机安装Windows10镜像【超详细图文版】!!!
windows·系统安装·vmware·虚拟机·图文教程