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))
相关推荐
dongdonglele52119 小时前
ros2环境安装
windows
muinomarts20 小时前
【Windows挂载夸克网盘到本地 AList+Raidrive】
windows
Sharewinfo_BJ21 小时前
PowerBI 2026年1月功能更新|效率升级,体验再优化
windows·microsoft·powerbi
yaoxin52112321 小时前
314. Java Stream API - 使用 Collectors.partitioningBy() 分区元素
java·windows
云小逸1 天前
【windows核心编程】Windows GDI编程深度解析:从消息循环到双缓冲动画的完整实现
windows
奋斗羊羊1 天前
rocketmq 及依赖环境编译安装过程记录(windows)
windows·rocketmq
做萤石二次开发的哈哈1 天前
萤石云广播:智能语音广播,一键文字下发
人工智能·语音识别
Leinwin1 天前
VibeVoice-ASR:突破60分钟长音频处理瓶颈,语音识别进入端到端时代
人工智能·音视频·语音识别
鲨辣椒100861 天前
Linux软件编程基石——基础指令使用
linux·windows·microsoft
云小逸1 天前
【Nmap 源码学习】深度解析:main.cc 入口函数详解
网络·windows·学习·nmap