当前位置:   article > 正文

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

faster-whisper 微调

环境配置

pip install faster-whisper transformers
  • 1

准备tiny模型

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

  • 原始中文语音模型:
https://huggingface.co/openai/whisper-tiny
  • 1
  • 微调后的中文语音模型:
git clone https://huggingface.co/xmzhu/whisper-tiny-zh
  • 1
  • 补下一个:tokenizer.json
https://huggingface.co/openai/whisper-tiny/resolve/main/tokenizer.json?download=true
  • 1

模型转换

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

代码

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))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/263686?site
推荐阅读
相关标签
  

闽ICP备14008679号