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) # 输出结果
相关推荐
想用offer打牌8 小时前
MCP (Model Context Protocol) 技术理解 - 第二篇
后端·aigc·mcp
KYGALYX10 小时前
服务异步通信
开发语言·后端·微服务·ruby
掘了10 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
爬山算法10 小时前
Hibernate(90)如何在故障注入测试中使用Hibernate?
java·后端·hibernate
Moment11 小时前
富文本编辑器在 AI 时代为什么这么受欢迎
前端·javascript·后端
Cobyte11 小时前
AI全栈实战:使用 Python+LangChain+Vue3 构建一个 LLM 聊天应用
前端·后端·aigc
程序员侠客行12 小时前
Mybatis连接池实现及池化模式
java·后端·架构·mybatis
Honmaple12 小时前
QMD (Quarto Markdown) 搭建与使用指南
后端
PP东13 小时前
Flowable学习(二)——Flowable概念学习
java·后端·学习·flowable
invicinble13 小时前
springboot的核心实现机制原理
java·spring boot·后端