Whisper 通过 mp3输出中文

像剪映和一些软件一样,识别字幕,输出文本,用Whisper。

Whisper是openai推出的,一种开源语音识别模型,能够识别很多种语言,然后将音频转成文字

python实现。


不懂代码的,用图形界面buzzconst-me/whisper


python记住一定要安装3.9 - 3.11 之间,我用到3.9.9


命令是这样:whisper --language Chinese --model large audio.mp3

就可以输出了。


也可以写代码:

代码如下:

py 复制代码
import os.path
import whisper

model = whisper.load_model("turbo")

# load audio and pad/trim it to fit 30 seconds
audio_path = os.path.join(os.path.dirname(__file__), "1.mp3")
audio = whisper.load_audio(audio_path)
audio = whisper.pad_or_trim(audio)

# make log-Mel spectrogram and move to the same device as the model
mel = whisper.log_mel_spectrogram(audio, n_mels=model.dims.n_mels).to(model.device)

# detect the spoken language
_, probs = model.detect_language(mel)
print(f"Detected language: {max(probs, key=probs.get)}") # 检测是哪国语言

# decode the audio
options = whisper.DecodingOptions()
result = whisper.decode(model, mel, options)

# print the recognized text
print(result.text) # 输出结果
相关推荐
ConardLi3 分钟前
Harness 实践:让 Agent 全自动制作知识讲解视频
前端·人工智能·后端
tanis_207712 分钟前
DeepSeek-TUI 也能读 PDF 了:Skill + MinerU CLI 终端文档解析实战
人工智能·后端·深度学习·pdf·csdn开发云
谁在黄金彼岸14 分钟前
AI 服务 Connection Reset by Peer 问题修复
后端
MageGojo23 分钟前
怎么用 Node.js 接入内容审核 API:从调通到评论风控的完整做法
后端
BING_Algorithm23 分钟前
开发常用Git核心知识
git·后端
星栈25 分钟前
Rust 泛型注入:一个 Service 协调四个 DDD 聚合的实战复盘
后端·架构
木雷坞30 分钟前
vLLM 服务上 K8s 前,我先把 GPU、探针和镜像过了一遍
后端
用户2986985301430 分钟前
用 Java 操作 Word 文档?试试添加内容控件
java·后端
golang学习记42 分钟前
Go 里什么时候可以“panic”?
后端