OpenAI Whisper 把mp3语音转文字

github地址: https://github.com/openai/whisper

环境准备:

pip install -U openai-whisper

on Ubuntu or Debian

sudo apt update && sudo apt install ffmpeg

on Arch Linux

sudo pacman -S ffmpeg

on MacOS using Homebrew (https://brew.sh/)

brew install ffmpeg

on Windows using Chocolatey (https://chocolatey.org/)

choco install ffmpeg

on Windows using Scoop (https://scoop.sh/)

scoop install ffmpeg

如果有GPU推荐额外安装(加速)根据自己 CUDA 版本换

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
whisper D:\video\test.mp4 --model medium --language Chinese --output_format txt

Python方式

复制代码
import whisper
from pathlib import Path


def video_to_txt(video_path, txt_path=None, model_name="medium"):
    # 加载模型
    model = whisper.load_model(model_name)

    # 自动识别视频音频
    result = model.transcribe(
        video_path,
        language="zh",  # 中文
        fp16=False      # CPU必须False
    )

    text = result["text"]

    if txt_path is None:
        txt_path = Path(video_path).with_suffix(".txt")

    with open(txt_path, "w", encoding="utf-8") as f:
        f.write(text)

    print("完成 →", txt_path)


if __name__ == "__main__":
    video_to_txt("test.mp4")

视频音质差建议

ffmpeg -i test.mp4 -ar 16000 -ac 1 test.wav

whisper test.wav --model medium --language zh --output_format txt

相关推荐
abigriver4 小时前
打造 Linux 离线大模型级语音输入法:Whisper.cpp + 3090 显卡加速与 Rime 中英混输终极调优指南
linux·运维·whisper
J心流5 天前
89ms实时Whisper,显存还降48%
whisper
iDao技术魔方9 天前
whisper.cpp 深度解析:从边缘设备到实时语音识别
人工智能·whisper·语音识别
Gc9umsbL112 天前
从FLAC到WAV:whisper.cpp中的FFmpeg音频预处理全解析
ffmpeg·whisper·音视频
Bofu-16 天前
【音频测试】03-WPF 实现声道自动验证 + Whisper 语音识别录音检测
c#·whisper·wpf·音视频·音频测试·naudio 声道控制
JK Chen19 天前
faster_whisper,视频转文字,并生成字幕文件
python·whisper·音视频
工作log21 天前
10分钟搭建本地语音识别服务 (Whisper large-v3-turbo)
人工智能·whisper·语音识别
shao91851622 天前
第10章 Streaming(上):初级音频应用(1)——项目三:自建服务器的Mini-Omni实时语音聊天机器人
ffmpeg·whisper·asr·mini-omni·自建语音服务器
code_pgf1 个月前
MNN Whisper 实时 ASR 工程实现
人工智能·whisper·mnn
独占的甜蜜1 个月前
从FLAC到WAV:whisper.cpp中的FFmpeg音频预处理全解析过程
ffmpeg·whisper·音视频