MCPcopy Create free account
hub / github.com/TIGER-AI-Lab/TheoremExplainAgent / extract_trasnscript

Function extract_trasnscript

src/core/parse_video.py:165–195  ·  view source on GitHub ↗

Extract transcript from video audio using Google Speech Recognition. Args: video_path (str): Path to the video file. Returns: str: Transcribed text from the video audio. Raises: FileNotFoundError: If video file does not exist.

(video_path)

Source from the content-addressed store, hash-verified

163 video.close()
164
165def extract_trasnscript(video_path):
166 """Extract transcript from video audio using Google Speech Recognition.
167
168 Args:
169 video_path (str): Path to the video file.
170
171 Returns:
172 str: Transcribed text from the video audio.
173
174 Raises:
175 FileNotFoundError: If video file does not exist.
176 """
177 if not os.path.exists(video_path):
178 raise FileNotFoundError(f"Video file not found: {video_path}")
179
180 clip = VideoFileClip(video_path)
181
182 # write the video to a temporary audio file
183 audio_path = os.path.join(os.path.dirname(video_path), "audio.wav")
184 clip.audio.write_audiofile(audio_path)
185
186 try:
187 # extract the subtitles from the audio file
188 recognizer = sr.Recognizer()
189 with sr.AudioFile(audio_path) as source:
190 audio = recognizer.record(source)
191 return recognizer.recognize_google(audio)
192 finally:
193 # clean up the temporary audio file
194 if os.path.exists(audio_path):
195 os.remove(audio_path)
196
197if __name__ == "__main__":
198 import argparse

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected