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))
相关推荐
陈小于7 小时前
windows(x86-x64)下编译JCEF
windows
aningxiaoxixi8 小时前
TTS 之 PYTHON库 pyttsx3
开发语言·python·语音识别
网络研究院8 小时前
Firefox 146 为 Windows 用户引入了加密本地备份功能
前端·windows·firefox
FL16238631298 小时前
打开事件查看器提示MMC无法创建管理单元的解决思路
windows
꧁坚持很酷꧂9 小时前
Windows安装Qt Creator5.15.2(图文详解)
开发语言·windows·qt
Heart_to_Yang10 小时前
Telnet 调试屏幕输出信息卡死问题解决
网络·windows·经验分享
杼蛘11 小时前
XXL-Job工具使用操作记录
linux·windows·python·jdk·kettle·xxl-job
qq_2515335912 小时前
查找 Python 中对象使用的内存量
开发语言·windows·python
JH灰色12 小时前
【大模型】-LangChain--Agent
windows·microsoft·langchain
世转神风-12 小时前
windows-ps1-脚本-删除文件
windows