
Whisper 是 OpenAI 研发的自动语音识别(ASR)系统,它具备强大的多语言识别能力,能处理多种不同口音和背景噪音下的语音内容,将其准确地转换为文本。其支持的语言众多,包括但不限于英语、中文、法语、德语等,广泛应用于会议记录、音频字幕制作、语音内容整理等场景。
Whisper 可以在多种操作系统上运行,如 Windows、macOS 和 Linux。

Whisper 提供了不同大小和精度的模型,模型越大,识别精度通常越高,但运行所需的计算资源也越多。常见的模型有:
tiny:体积小,运行速度快,但识别精度相对较低,适合对速度要求较高且对精度要求不是特别苛刻的场景。
base:在速度和精度之间取得了较好的平衡,是一个比较常用的选择。
small:精度比 base 更高,但运行速度会稍慢一些。
medium:识别精度进一步提升,不过需要更多的计算资源。(如果不懂,常规选这个就行)
large:精度最高,但对硬件要求也最高,运行速度相对较慢。
whisper官网地址
https://github.com/openai/whisper
OpenAI Whisper C++版本实现,提供了Win上可用的exe文件
https://github.com/ggml-org/whisper.cpp
Windows 版本的 whisper.cpp,提供了Win上可视化页面WhisperDesktop
https://github.com/Const-me/Whisper
我先选择下载whisper.cpp,下载后,文件中有一个文件whisper-cli.exe,我在命令行可以执行该程序,给予相关参数,实现我们的功能
./whisper-cli.exe -m ggml-medium.bin -f 1767594398074.mp3 -l zh -osrt -otxt -nt --prompt "请用简体中文输出"
-m ggml-medium.bin 指定模型
-f 1767594398074.mp3 指定源文件
-l zh 指定语言为汉语
-osrt -otxt 生成 .srt 字幕文件(带时间戳),-otxt 生成 .txt 文本文件(通常也带时间戳)
-nt 输出的 .txt 文件将只包含纯文本,无时间戳
--prompt "请用简体中文输出" 推理输出为简体中文
上面需要的MP3文件,大家可以使用在线文字转语音来生成,这个网上很多(TTSMaker:https://ttsmaker.cn/ )
模型文件ggml-medium.bin,大家自行选择下载,地址:https://github.com/ggml-org/whisper.cpp/tree/master/models ,如无法打开,自行在线搜索即可。
可用模型文件下载地址:https://huggingface.co/ggerganov/whisper.cpp/tree/main ,相关模型大小如下
| Model | Disk | SHA |
|---|---|---|
| tiny | 75 MiB | bd577a113a864445d4c299885e0cb97d4ba92b5f |
| tiny.en | 75 MiB | c78c86eb1a8faa21b369bcd33207cc90d64ae9df |
| base | 142 MiB | 465707469ff3a37a2b9b8d8f89f2f99de7299dac |
| base.en | 142 MiB | 137c40403d78fd54d454da0f9bd998f78703390c |
| small | 466 MiB | 55356645c2b361a969dfd0ef2c5a50d530afd8d5 |
| small.en | 466 MiB | db8a495a91d927739e50b3fc1cc4c6b8f6c2d022 |
| small.en-tdrz | 465 MiB | b6c6e7e89af1a35c08e6de56b66ca6a02a2fdfa1 |
| medium | 1.5 GiB | fd9727b6e1217c2f614f9b698455c4ffd82463b4 |
| medium.en | 1.5 GiB | 8c30f0e44ce9560643ebd10bbe50cd20eafd3723 |
| large-v1 | 2.9 GiB | b1caaf735c4cc1429223d5a74f0f4d0b9b59a299 |
| large-v2 | 2.9 GiB | 0f4c8e34f21cf1a914c59d8b3ce882345ad349d6 |
| large-v2-q5_0 | 1.1 GiB | 00e39f2196344e901b3a2bd5814807a769bd1630 |
| large-v3 | 2.9 GiB | ad82bf6a9043ceed055076d0fd39f5f186ff8062 |
| large-v3-q5_0 | 1.1 GiB | e6e2ed78495d403bef4b7cff42ef4aaadcfea8de |
| large-v3-turbo | 1.5 GiB | 4af2b29d7ec73d781377bfd1758ca957a807e941 |
| large-v3-turbo-q5_0 | 547 MiB | e050f7970618a659205450ad97eb95a18d69c9ee |
执行后相关打印:
D:\Download\whisper-bin-x64\Release> ./whisper-cli.exe -m ggml-medium.bin -f 1767594398074.mp3 -l zh -osrt -otxt --prompt "请用简体中 文输出" whisper_init_from_file_with_params_no_state: loading model from 'ggml-medium.bin' whisper_init_with_params_no_state: use gpu = 1 whisper_init_with_params_no_state: flash attn = 1 whisper_init_with_params_no_state: gpu_device = 0 whisper_init_with_params_no_state: dtw = 0 whisper_init_with_params_no_state: devices = 1 whisper_init_with_params_no_state: backends = 1 whisper_model_load: loading model whisper_model_load: n_vocab = 51865 whisper_model_load: n_audio_ctx = 1500 whisper_model_load: n_audio_state = 1024 whisper_model_load: n_audio_head = 16 whisper_model_load: n_audio_layer = 24 whisper_model_load: n_text_ctx = 448 whisper_model_load: n_text_state = 1024 whisper_model_load: n_text_head = 16 whisper_model_load: n_text_layer = 24 whisper_model_load: n_mels = 80 whisper_model_load: ftype = 1 whisper_model_load: qntvr = 0 whisper_model_load: type = 4 (medium) whisper_model_load: adding 1608 extra tokens whisper_model_load: n_langs = 99 whisper_model_load: CPU total size = 1533.14 MB whisper_model_load: model size = 1533.14 MB whisper_backend_init_gpu: no GPU found whisper_init_state: kv self size = 50.33 MB whisper_init_state: kv cross size = 150.99 MB whisper_init_state: kv pad size = 6.29 MB whisper_init_state: compute buffer (conv) = 28.57 MB whisper_init_state: compute buffer (encode) = 44.60 MB whisper_init_state: compute buffer (cross) = 7.73 MB whisper_init_state: compute buffer (decode) = 98.20 MB system_info: n_threads = 4 / 20 | WHISPER : COREML = 0 | OPENVINO = 0 | CPU : SSE3 = 1 | SSSE3 = 1 | AVX = 1 | AVX2 = 1 | F16C = 1 | FMA = 1 | OPENMP = 1 | REPACK = 1 | main: processing '1767594398074.mp3' (403968 samples, 25.2 sec), 4 threads, 1 processors, 5 beams + best of 5, lang = zh, task = transcribe, timestamps = 1 ... [00:00:00.000 --> 00:00:16.000] 据黑龙江省疾病预防控制中心消息,小寒节气标志着我国大部分地区进入一年中最寒冷时段,寒潮频繁,气温骤降,空气干燥,是呼吸道传染病、心脑血管疾病的高发期。 [00:00:16.000 --> 00:00:25.000] 为保障公众健康,黑龙江省疾控中心特发布健康提示,指导公众科学防寒保暖,健康过冬。 output_txt: saving output to '1767594398074.mp3.txt' output_srt: saving output to '1767594398074.mp3.srt' whisper_print_timings: load time = 833.89 ms whisper_print_timings: fallbacks = 0 p / 0 h whisper_print_timings: mel time = 16.09 ms whisper_print_timings: sample time = 388.43 ms / 750 runs ( 0.52 ms per run) whisper_print_timings: encode time = 12726.37 ms / 1 runs ( 12726.37 ms per run) whisper_print_timings: decode time = 31.95 ms / 1 runs ( 31.95 ms per run) whisper_print_timings: batchd time = 11185.53 ms / 744 runs ( 15.03 ms per run) whisper_print_timings: prompt time = 214.17 ms / 19 runs ( 11.27 ms per run) whisper_print_timings: total time = 25535.54 ms
然后在同级目录,可以看到已MP3文件名命名的srt和txt文件。
我们也可以直接下载WhisperDesktop,然后直接运行WhisperDesktop.exe,可以打开如下页面

选择模型,选择使用GPU或者CPU,多个GPU时选择使用哪个GPU。

选择语音为Chinese,选择目标MP3文件,选择输出问txt和对应目录。
点击转换,就会生成对应的txt文件。
Java小强
未曾清贫难成人,不经打击老天真。
自古英雄出炼狱,从来富贵入凡尘。
发表评论: