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) # 输出结果
相关推荐
行百里er6 分钟前
Redis 持久化——RDB 快照 vs AOF 日志
redis·后端
Ysx1 小时前
踩了 5 次"本地全绿、生产失效"之后,我把交付流程做成了 SOP
后端·程序员
pippocao1 小时前
王者荣耀日志组件BqLog为什么这么快之2——从环形队列到自适应数据总线
后端
孟健2 小时前
Stripe出海收款架构设计:水星银行与香港账户实测对比与资金流闭环
后端·架构
程序员cxuan2 小时前
DeepSeek Harness 出了桌面端?我把它扒了一遍
人工智能·后端·程序员
j7~2 小时前
【Python】(篇七)《使用Python库》 -- 详解
开发语言·后端·python·编程学习·python标准库·python第三方库·python拓展
Memory_荒年2 小时前
订单超时未支付?从“定时扫库”一步步到最终形态
java·后端
卷无止境3 小时前
便宜模型和贵模型到底差在哪儿?一份关于Claude与GPT分级体系的深度梳理
后端·python
阿狗童鞋4 小时前
SpringBoot微服务实战指南
spring boot·后端·微服务
FfHUCisI4 小时前
sync.Once 与 sync.Cond 源码与并发控制陷阱
服务器·开发语言·后端·golang