> 文章列表 > python语音识别whisper

python语音识别whisper

python语音识别whisper

一、背景

最近想提取一些视频的字幕,语音文案,研究了一波

二、whisper语音识别

Whisper 是一种通用的语音识别模型。它在不同音频的大型数据集上进行训练,也是一个多任务模型,可以执行多语言语音识别以及语音翻译和语言识别。
stable-ts在 OpenAI 的 Whisper 之上修改并添加了更大的破解代码发布,生成更准确的阶段时间切换,并在无须额外推介的情况下获得申领

  • 安装pip install openai-whisper pip install stable-ts
  • Size Parameters English-only model Multilingual model Required VRAM Relative speed
    tiny 39 M tiny.en tiny ~1 GB ~32x
    base 74 M base.en base ~1 GB ~16x
    small 244 M small.en small ~2 GB ~6x
    medium 769 M medium.en medium ~5 GB ~2x
    large 1550 M N/A large ~10 GB 1x

三、示例

模型越大,越精确,相应话费的时间越长
自带语言识别功能,language最好加上,下面歌曲识别为英语,加后为中文
stable_whisper 是 whisper 进化版

import whisper
import stable_whisper as whisperclass WhisperTranscriber(object):def __init__(self, model_name):self.model = whisper.load_model(model_name)def whisper_transcribe(self, audio_path):audio = self.model.transcribe(audio_path, fp16=False, language='Chinese')return audio['text']if __name__ == '__main__':transcriber = WhisperTranscriber("base")text = transcriber.whisper_transcribe("257853511.mp3")print(text)

可能是伴奏声音过大,你才出来这是什么歌了吗?python语音识别whisperstable_whisper 别的用法、生成字幕

import stable_whisper
model = stable_whisper.load_model('base')
results = model.transcribe('257853511.mp3', fp16=False, language='Chinese')
stable_whisper.results_to_sentence_srt(results, 'audio')
stable_whisper.results_to_sentence_word_ass(results, 'audio.ass')

四、封装工具

buzz https://github.com/chidiwilliams/buzz

如果遇到简繁转换可以石下面
pip install zhconvzh-cn 大陆简体
zh-hant 繁體from zhconv import convert     
convert('Python是一种动态的、面向对象的脚本语言', 'zh-hant')
'Python是一種動態的、面向對象的腳本語言'