> 技术文档 > 如何下载、安装whisper、faster_whisper?_whisper模型下载

如何下载、安装whisper、faster_whisper?_whisper模型下载

1、模型种类

whisper:有很多模型:tiny、base、small、medium、large等

faster_whisper:模型种类与whisper类似

2、模型安装

特别注意:whisper和faster_whisper中的模型,有两种获得方式。

①在网址:https://github.com/openai/whisper上有提示:pip install -U openai-whisper,下载结果为  .pt文件。在网址:https://github.com/SYSTRAN/faster-whisper上有提示:pip install faster-whisper,下载结果为.pt文件

②在网址:https://huggingface.co/,进行搜索 whisper,根据提示,可以下载 large-v3和large-v3-turbo,下载结果为文件,与①不同(特别注意)

3.模型运行

①按照①方法下载的模型:运行代码参考网址:https://github.com/openai/whisperhttps://github.com/openai/whisper ,示例如下:

import whisper

model = whisper.load_model(\"turbo\")

# load audio and pad/trim it to fit 30 seconds
audio = whisper.load_audio(\"audio.mp3\")
audio = whisper.pad_or_trim(audio)

# make log-Mel spectrogram and move to the same device as the model
mel = whisper.log_mel_spectrogram(audio, n_mels=model.dims.n_mels).to(model.device)

# detect the spoken language
_, probs = model.detect_language(mel)
print(f\"Detected language: {max(probs, key=probs.get)}\")

# decode the audio
options = whisper.DecodingOptions()
result = whisper.decode(model, mel, options)

# print the recognized text
print(result.text)

以上代码,要求# load audio and pad/trim it to fit 30 seconds,提示:whisper模型要求一句话进行识别,如果音频时间太短,可能识别结果不准确,具体请自行尝试。

②按照①方法下载的模型:运行代码参考网址:https://github.com/SYSTRAN/faster-whisperhttps://github.com/SYSTRAN/faster-whisper ,示例如下:

from faster_whisper import WhisperModel

model_size = \"large-v3\"

# Run on GPU with FP16
model = WhisperModel(model_size, device=\"cuda\", compute_type=\"float16\")

# 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(\"audio.mp3\", beam_size=5)

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

以上代码,model=WhisperModel(...),可以指定cuda编号,以便合理利用资源。

③按照②方法下载的模型,可以参考vllm网址:https://github.com/vllm-project/vllmhttps://github.com/vllm-project/vllm

vllm框架中的whisper模型和faster_whisper模型一定是来自huggingface。

关于vllm安装踩坑问题,以后发布。