我想制作一个为视频制作字幕的应用,如下所示提取音频文件
import sys
from moviepy.video.tools.subtitles import SubtitlesClip
from moviepy.editor import *
video = VideoFileClip(sys.argv[1])
audio = video.audio
audio.write_audiofile()
,我将其转换为文本,但我想记录制作srt文件的时间.. 我可以记录音频文件中有语音或从音频文件中创建srt文件的任何方式的时间,以下代码是将音频转换为文本
import speech_recognition as sr
AUDIO_FILE=("audi.wav")
r=sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
audio=r.record(source)
# sr.recognize_api()
googletext = r.recognize_google(audio)
with open("audio5.txt","w") as f:
f.write(googletext)
with open("audio.srt","w") as f:
f.write(googletext)