Whisper 通过 mp3输出中文

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

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

用python实现。


不懂代码的,用图形界面buzz和const-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) # 输出结果
相关推荐
猿究院_夏燊5 小时前
Spring Bean 生命周期
java·后端·spring
CCblandy7 小时前
雪花 ID 四个边界实测:时钟回拨重号 500 个,前端 JSON.parse 直接丢精度
后端·python·算法·性能优化·架构
我是人✓7 小时前
SpringBoot项目的五种创建方式
java·spring boot·后端
念念清晰9 小时前
000-OpenJDK17 源码构建:MacOS环境(M芯片)
java·后端
来福猿9 小时前
SpringCloud Config 源码分析:配置拉取、刷新与多环境管理
后端·spring·spring cloud
IT_陈寒11 小时前
React组件莫名重渲染?你可能忘了这个小细节
前端·人工智能·后端
用户98883218717411 小时前
给 .NET 网络调用设定“预算”:用 CancellationTokenSource.CancelAfter 处理超时取消
后端
清风儿32912 小时前
一块不会说话的电表,把我们折腾了半个月
后端
预知同行12 小时前
深入解析 MoE 混合专家模型:从 Router 到 All-to-All 的架构全景与生产实践
后端·架构
upala12 小时前
【仓颉语言入门 · 第二篇 第 8 课】
后端