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) # 输出结果
相关推荐
Marktowin4 小时前
Mybatis-Plus更新操作时的一个坑
java·后端
赵文宇4 小时前
CNCF Dragonfly 毕业啦!基于P2P的镜像和文件分发系统快速入门,在线体验
后端
程序员爱钓鱼5 小时前
Node.js 编程实战:即时聊天应用 —— WebSocket 实现实时通信
前端·后端·node.js
Libby博仙5 小时前
Spring Boot 条件化注解深度解析
java·spring boot·后端
源代码•宸6 小时前
Golang原理剖析(Map 源码梳理)
经验分享·后端·算法·leetcode·golang·map
小周在成长6 小时前
动态SQL与MyBatis动态SQL最佳实践
后端
瓦尔登湖懒羊羊6 小时前
TCP的自我介绍
后端
小周在成长6 小时前
MyBatis 动态SQL学习
后端
子非鱼9216 小时前
SpringBoot快速上手
java·spring boot·后端