ASR-使用whisper语音识别

安装如下一些依赖:

  • ffmpeg-python
  • transformers

使用如下代码进行识别:

import whisper

model = whisper.load_model("small.pt")
result = model.transcribe("output_audio.wav")
print(result["text"])

另一个更为底层的调用方法:

audio = whisper.load_audio("output.wav")
audio = whisper.pad_or_trim(audio)

mel = whisper.log_mel_spectrogram(audio).to(model.device)
_,probs = model.detect_language(mel)
print("Detected language: {}".format(max(probs, key=probs.get)))
options = whisper.DecodingOptions()
result = whisper.decode(model, mel, options)
print("You say:",result.text)

其中模型可以打开__init__.py文件进行复制,如small模型在https://openaipublic.azureedge.net/main/whisper/models/9ecf779972d90ba49c06d968637d720dd632c55bbf19d441fb42bf17a411e794/small.pt

参考文章:

https://github.com/openai/whisper/tree/v20230306

posted @   月薪几千的牛马  阅读(103)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
点击右上角即可分享
微信分享提示