whisper实时语音转文字

复制代码
import whisper

import os


def check_file_exists(file_path):
    if not os.path.exists(file_path):
        raise FileNotFoundError(f"音频文件不存在: {file_path}")


# 音频文件路径
audio_path = r"D:\视频\temp_audio.wav"

# 检查文件是否存在
check_file_exists(audio_path)

# 加载模型
model = whisper.load_model("large-v2")  # 使用较小的模型进行测试

# 转录音频文件
result = model.transcribe(audio_path)

# 打印识别结果
print(result["text"])

安装Whisper

pip install -U openai-whisper

1

此外你还需要安装ffmpeg。

下载模型:

Whisper提供了多种大小的模型,您可以根据需要下载。例如,要下载large-v2模型,可以使用以下命令:

wget https://openaipublic.azureedge.net/main/whisper/models/81f7c96c852ee8fc832187b0132e569d6c3065a3252ed18e56effd0b6a73e524/large-v2.pt

1

模型文件通常保存在~/.cache/whisper/目录下。

Openai whisper模型下载链接,包括medium(中型),large-v1、large-v2、large-v3

复制代码
medium:https://openaipublic.azureedge.net/main/whisper/models/345ae4da62f9b3d59415adc60127b97c714f32e89e936602e85993674d08dcb1/medium.pt

large-v1: https://openaipublic.azureedge.net/main/whisper/models/e4b87e7e0bf463eb8e6956e646f1e277e901512310def2c24bf0e11bd3c28e9a/large-v1.pt   

large-v2: https://openaipublic.azureedge.net/main/whisper/models/81f7c96c852ee8fc832187b0132e569d6c3065a3252ed18e56effd0b6a73e524/large-v2.pt

large-v3:https://openaipublic.azureedge.net/main/whisper/models/e5b1a55b89c1367dacf97e3e19bfd829a01529dbfdeefa8caeb59b3f1b81dadb/large-v3.pt


{
    "tiny.en": "https://openaipublic.azureedge.net/main/whisper/models/d3dd57d32accea0b295c96e26691aa14d8822fac7d9d27d5dc00b4ca2826dd03/tiny.en.pt",
    "tiny": "https://openaipublic.azureedge.net/main/whisper/models/65147644a518d12f04e32d6f3b26facc3f8dd46e5390956a9424a650c0ce22b9/tiny.pt",
    "base.en": "https://openaipublic.azureedge.net/main/whisper/models/25a8566e1d0c1e2231d1c762132cd20e0f96a85d16145c3a00adf5d1ac670ead/base.en.pt",
    "base": "https://openaipublic.azureedge.net/main/whisper/models/ed3a0b6b1c0edf879ad9b11b1af5a0e6ab5db9205f891f668f8b0e6c6326e34e/base.pt",
    "small.en": "https://openaipublic.azureedge.net/main/whisper/models/f953ad0fd29cacd07d5a9eda5624af0f6bcf2258be67c92b79389873d91e0872/small.en.pt",
    "small": "https://openaipublic.azureedge.net/main/whisper/models/9ecf779972d90ba49c06d968637d720dd632c55bbf19d441fb42bf17a411e794/small.pt",
    "medium.en": "https://openaipublic.azureedge.net/main/whisper/models/d7440d1dc186f76616474e0ff0b3b6b879abc9d1a4926b7adfa41db2d497ab4f/medium.en.pt",
    "medium": "https://openaipublic.azureedge.net/main/whisper/models/345ae4da62f9b3d59415adc60127b97c714f32e89e936602e85993674d08dcb1/medium.pt",
    "large-v1": "https://openaipublic.azureedge.net/main/whisper/models/e4b87e7e0bf463eb8e6956e646f1e277e901512310def2c24bf0e11bd3c28e9a/large-v1.pt",
    "large-v2": "https://openaipublic.azureedge.net/main/whisper/models/81f7c96c852ee8fc832187b0132e569d6c3065a3252ed18e56effd0b6a73e524/large-v2.pt",
    "large-v3": "https://openaipublic.azureedge.net/main/whisper/models/e5b1a55b89c1367dacf97e3e19bfd829a01529dbfdeefa8caeb59b3f1b81dadb/large-v3.pt",
    "large": "https://openaipublic.azureedge.net/main/whisper/models/e5b1a55b89c1367dacf97e3e19bfd829a01529dbfdeefa8caeb59b3f1b81dadb/large-v3.pt",
}
相关推荐
羊羊小栈9 分钟前
基于「多模态大模型 + BGE向量检索增强RAG」的航空维修智能问答系统(vue+flask+AI算法)
vue.js·人工智能·python·语言模型·flask·毕业设计
星期天要睡觉13 分钟前
模型部署——Flask 部署 PyTorch 模型
pytorch·python·flask
weixin_4569042719 分钟前
SHAP可视化代码详细讲解
python
DTS小夏20 分钟前
算法社Python基础入门面试题库(新手版·含答案)
python·算法·面试
刘一哥GIS34 分钟前
Windows环境搭建:PostGreSQL+PostGIS安装教程
数据库·python·arcgis·postgresql·postgis
西柚小萌新41 分钟前
【深入浅出PyTorch】--4.PyTorch基础实战
人工智能·pytorch·python
用户83562907805144 分钟前
掌控PDF页面:使用Python轻松实现添加与删除
后端·python
用户3721574261351 小时前
Python 实现 Excel 文件加密与保护
python
Derrick__11 小时前
Python访问数据库——使用SQLite
数据库·python·sqlite
总有刁民想爱朕ha2 小时前
AI大模型学习(17)python-flask AI大模型和图片处理工具的从一张图到多平台适配的简单方法
人工智能·python·学习·电商图片处理