一、背景
最近想提取一些視頻的字幕,語音文案,研究了一波
二、whisper語音識別
Whisper 是一種通用的語音識別模型。它在不同音頻的大型數(shù)據(jù)集上進(jìn)行訓(xùn)練,也是一個多任務(wù)模型,可以執(zhí)行多語言語音識別以及語音翻譯和語言識別。
stable-ts在 OpenAI 的 Whisper 之上修改并添加了更大的破解代碼發(fā)布,生成更準(zhǔn)確的階段時間切換,并在無須額外推介的情況下獲得申領(lǐng)
- 安裝
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
三、示例
模型越大,越精確,相應(yīng)話費的時間越長
自帶語言識別功能,language最好加上,下面歌曲識別為英語,加后為中文
stable_whisper 是 whisper 進(jìn)化版 即 python的這個包stable-ts
import whisper
import stable_whisper as whisper
class 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)
可能是伴奏聲音過大,你猜出來這是什么歌了嗎?stable_whisper 別的用法、生成字幕
文章來源:http://www.zghlxwxcb.cn/news/detail-448541.html
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文章來源地址http://www.zghlxwxcb.cn/news/detail-448541.html
如果遇到簡繁轉(zhuǎn)換可以石下面
pip install zhconv
zh-cn 大陸簡體
zh-hant 繁體
from zhconv import convert
convert('Python是一種動態(tài)的、面向?qū)ο蟮哪_本語言', 'zh-hant')
'Python是一種動態(tài)的、面向?qū)ο蟮哪_本語言'
到了這里,關(guān)于python語音識別whisper的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!