python系列&deep_study系列:Whisper——部署fast-whisper中文语音识别模型




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

whisper:https://github.com/openai/whisper/tree/main
参考文章:Whisper OpenAI开源语音识别模型

环境配置

pip install faster-whisper transformers

准备tiny模型

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

原始中文语音模型:
https://huggingface.co/openai/whisper-tiny

微调后的中文语音模型:

git clone https://huggingface.co/xmzhu/whisper-tiny-zh

补下一个:tokenizer.json
https://huggingface.co/openai/whisper-tiny/resolve/main/tokenizer.json?download=true

模型转换

float16:

ct2-transformers-converter --model whisper-tiny-zh/ --output_dir whisper-tiny-zh-ct2 --copy_files tokenizer.json preprocessor_config.json --quantization float16

int8:

ct2-transformers-converter --model whisper-tiny-zh/ --output_dir whisper-tiny-zh-ct2-int8 --copy_files tokenizer.json preprocessor_config.json --quantization int8

代码

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))







Irving.Gao

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坦笑&&life

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值