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)
| 163 | video.close() |
| 164 | |
| 165 | def 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 | |
| 197 | if __name__ == "__main__": |
| 198 | import argparse |
nothing calls this directly
no outgoing calls
no test coverage detected