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

相关推荐
MindUp6 天前
多款AI语音转写+LLM复盘方案横评:从Whisper本地部署到网盘智能体全链路实测
人工智能·whisper
Niuguangshuo8 天前
ASR 五代演进(五):Gen 4 · 以 Whisper 为代表的大规模弱监督
whisper
Generalzy14 天前
Whisper + VAD + TTS:一套完整的 Python 本地语音处理流水线
python·whisper·语音识别
shxjnpl15 天前
Whisper + CAM++ + 本地大模型:一套完全离线的AI会议处理链路
人工智能·机器学习·whisper
shxjnpl15 天前
Whisper large-v3 本地部署实战:从语音转写到AI会议纪要完整链路
人工智能·whisper·语音识别
程序猿编码15 天前
不用PyTorch,不用CUDA,我用C++手写了一个能跑GPT和Whisper的推理库
c++·pytorch·gpt·大模型·whisper
今夕资源网1 个月前
今夕语音中枢一键整合包:本地 LuxTTS 发声 + Whisper 听觉 + AIRI一键接入听觉和发声模块
whisper·ai伴侣·airi·ai女友·ai宠物
大鱼>1 个月前
Whisper+GPT-SoVITS:语音识别到音色克隆的全链路实战
gpt·whisper·语音识别
维基框架1 个月前
Apple的SpeechAnalyzer API实测:系统级语音识别与Whisper的差距在哪里
人工智能·whisper·语音识别·xcode
向阳是我2 个月前
在 Mac(M2)上用 faster-whisper 实现高精度中文语音转文字
python·macos·ai·whisper·语音识别