Contents

音频转文字 Whisper

简介

一个音频转文本的模型 https://github.com/openai/whisper

依赖

  • python
  • ffmpeg

命令行使用

验证GPU

venv环境下 输入whisper -h

–device # 如果默认是cpu 则证明cuda安装失败

# 这样也能验证cuda是否安装了
python -c "import torch; print(torch.version.cuda)"

重装torch gpu版本

# 卸载纯cpu版
pip uninstall torch
# clean cache
pip cache purge
# copy from  https://pytorch.org/get-started/locally/
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

再次验证 whisper -h

–device # 如果默认是cuda 则证明成功

运行demo

whisper {vocieFile} --model large-v2 --model_dir {modelPath} \
--ourput_dir {outputDir}  --output_format txt --device cuda --language Chinese

界面版

界面版 https://github.com/Const-me/Whisper

用的模型是 https://huggingface.co/ggerganov/whisper.cpp/tree/main

执行任务速度有所提升,但是损失了辨别成功率

声音提取器

非常的强大,用于人声,BGM提取

https://github.com/Anjok07/ultimatevocalremovergui

CPP版本构建

项目 https://github.com/ggerganov/whisper.cpp

在window上下载Visual Studio 2022

安装cuda

小问题

编译有GPU版本会遇到CUDA compile problems on Windows, Cmake error: No CUDA toolset found

根据文中提示,我这边的实操是

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\extras\visual_studio_integration\MSBuildExtensions 里面的文件全拷贝到 C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations 目录下

编译

接下来进入到项目目录

mkdir build
cd build
cmake   -DCMAKE_BUILD_TYPE=Release -DWHISPER_CUBLAS=1 ..
cmake --build .  --config Release

在build\bin\Release下就有main.exe了

mp3转wav ffmpeg -i input.mp3 -ar 16000 -ac 1 -c:a pcm_s16le output.wav

wav转字幕 ./main -m {模型.bin} -f {.wav文件} -otxt {输出文件名} -l auto