whisper是openai开源的一款语音识别的模型,包含有英语和多国语言的模型,根据实际情况来看,其支持的90多种语言的准确率着实表现惊艳,英文甚至可以做到3%左右的误词率,官方图表显示中文的误词率大约是14%,但是实际使用的情况来看,误词率也是相当低,几乎也在3%左右。
整个whisper系列一共有5个级别的模型,按参数量进行排序,分别是微型tiny,基本base,小型small,中型medium,大型large。
github上有一个whisper.cpp可以通过c++跨平台部署,支持了mac/ios/android/linux/windows/raspberry pi等平台。
这里主要是将如何使用源码在windows平台msvc上进行编译。实际使用mingw应该一样或者更加简单。
首先通过github将源码下载下来:
git clone https://github.com/ggerganov/whisper.cpp
然后通过models/download-ggml-model.cmd
进行权重文件下载。
models/download-ggml-model.cmd base
参数base
可以替换为base.en
,tiny
,tiny.en
,small
,small.en
,medium
,medium.en
,large
带en
后缀的表示是英语模型,不带en
后缀的是多国语言模型。
然后使用cmake-gui进行项目配置,源码目录设置为源代码的地址c:/gitrepos/whisper.cpp-master
,在文件夹下创建一个build文件夹作为输出地址:如c:/gitrepos/whisper.cpp-master/build
。点击confiure后,如果有安装cuda环境,可以勾选whisper_cublas
在推理的时候更快,如果没有的话也可以不勾。点击confiure后确认没有红色内容后点击generate
和open project
。
在打开vs后需要修改一项内容,在whisper
项目右击,属性,在c++
->command line
里面的addtional options里面添加/utf-8
, 否者whisper.cpp
里面有一些未ascii字符会导致编译whisper.dll
的时候出错。注意debug与release都要添加。
或者如果只编译cpu版本,不启用cublas
的话,也可以在cmakelist.txt文件上添加add_compile_options(/utf-8)
,pr 721:
project(whisper.cpp version 1.4.2)
if ("${cmake_cxx_compiler_id}" strequal "msvc")
add_compile_options(/utf-8)
endif ()
# add path to modules
list(append cmake_module_path "${cmake_current_source_dir}/cmake/")
但是启用cublas的话,只能通过右键属性更改,否则/utf-8
这个编译参数也会带到nvcc编译器的编译过程中,但是nvcc并不支持这个参数,issue 840.
修改完成后通过build->batch build...
将all_build的debug和release打钩后点击build即可。不出意外编译成功应该是输出类似以下内容:
========== build: 11 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
然后可以在build/bin/release(debug)中看到main.exe文件,通过命令行执行这个文件就可以,注意携带参数。
c:\gitrepos\whisper.cpp-master\build\bin\release> .\main.exe -m ..\..\..\models\ggml-tiny.bin -f ..\..\..\samples\jfk.wav
whisper_init_from_file_no_state: loading model from '..\..\..\models\ggml-tiny.bin'
whisper_model_load: loading model
whisper_model_load: n_vocab = 51865
whisper_model_load: n_audio_ctx = 1500
whisper_model_load: n_audio_state = 384
whisper_model_load: n_audio_head = 6
whisper_model_load: n_audio_layer = 4
whisper_model_load: n_text_ctx = 448
whisper_model_load: n_text_state = 384
whisper_model_load: n_text_head = 6
whisper_model_load: n_text_layer = 4
whisper_model_load: n_mels = 80
whisper_model_load: ftype = 1
whisper_model_load: qntvr = 0
whisper_model_load: type = 1
whisper_model_load: mem required = 201.00 mb (+ 3.00 mb per decoder)
whisper_model_load: adding 1608 extra tokens
whisper_model_load: model ctx = 73.62 mb
whisper_model_load: model size = 73.54 mb
whisper_init_state: kv self size = 2.62 mb
whisper_init_state: kv cross size = 8.79 mb
system_info: n_threads = 4 / 16 | avx = 1 | avx2 = 1 | avx512 = 0 | fma = 1 | neon = 0 | arm_fma = 0 | f16c = 1 | fp16_va = 0 | wasm_simd = 0 | blas = 1 | sse3 = 1 | vsx = 0 | coreml = 0 |
main: processing '..\..\..\samples\jfk.wav' (176000 samples, 11.0 sec), 4 threads, 1 processors, lang = en, task = transcribe, timestamps = 1 ...
[00:00:00.000 --> 00:00:10.500] and so my fellow americans ask not what your country can do for you ask what you can do for your country.
whisper_print_timings: load time = 926.39 ms
whisper_print_timings: fallbacks = 0 p / 0 h
whisper_print_timings: mel time = 153.92 ms
whisper_print_timings: sample time = 17.06 ms / 25 runs ( 0.68 ms per run)
whisper_print_timings: encode time = 225.90 ms / 1 runs ( 225.90 ms per run)
whisper_print_timings: decode time = 70.32 ms / 25 runs ( 2.81 ms per run)
whisper_print_timings: total time = 1413.72 ms
在对比了cpu与gpu版本发现,gpu的时间更长,主要是gpu版本在加载模型的load time更长了,实际的推理时间约500ms相比gpu的800ms要短一些的。
发表评论