当前位置:AIGC资讯 > AIGC > 正文

whisper生成字幕python代码实现

def excute(model_name,file_path,start_time):
    model = whisper.load_model(model_name)
    result = model.transcribe(file_path)
    for segment in result["segments"]:
        now = arrow.get(start_time)
        start = now.shift(seconds=segment["start"]).format("YYYY-MM-DD HH:mm:ss")
        end = now.shift(seconds=segment["end"]).format("YYYY-MM-DD HH:mm:ss")
        print("【"+start+"->" +end+"】:"+segment["text"])
# excute函数中,第一个参数是whisper模型,第二参数是视频地址,第三个参数是开始时间
if __name__ == '__main__':
    excute("small","C:/Users/hp/Desktop/音频测试/1.mp4","2023-4-24 21:20:00")

whisper模型

更新时间 2024-01-17