openai whisper 语音识别,语音翻译

编辑于 2024-03-07 12:29:13 阅读 236

简介

Whisper 是openai开源的一个通用的语音识别模型,同时支持把各种语言的音频翻译为成英文(音频->文本)。

安装

apt install ffmpeg

pip install -U openai-whisper

使用

指令

whisper video.mp4
whisper audio.flac audio.mp3 audio.wav --model medium
whisper japanese.wav --language Japanese
whisper chinese.mp4 --language Chinese --task translate
whisper --help

代码中使用,以下是Python示例

import whisper

model = whisper.load_model("base")
result = model.transcribe("audio.mp3")
print(result["text"])

扩展,Whisper ASR Webservice

whisper 只支持服务端代码调用,如果前端要使用得通过接口,Whisper ASR Webservice帮我们提供了这样的接口,目前提供两个接口,一个音频语言识别和音频转文字(支持翻译和转录)

Whisper ASR Webservice除了支持Whisper,还支持faster-whisperfaster-whisper据说能够实现比 Whisper更快的转录功能,同时显存占用也比较小。

Whisper ASR Webservicegit 仓库 下的docker-compose.gpu.yml可以直接使用

接口文档

http://localhost:9000/docs

其中,音频转文字接口,识别出的文字可能是简体,繁体混合的,可以通过参数initial_prompt调节,比如设置参数值为以下是普通话的句子,这是一段会议记录。,来源: https://blog.csdn.net/gootyking/article/details/134475995

参考

https://zhuanlan.zhihu.com/p/617770448

https://github.com/openai/whisper

https://github.com/SYSTRAN/faster-whisper

广而告之,我的新作品《语音助手》上架Google Play了,欢迎下载体验