unbias-one / video2txt.py
Jordan
Unbias - Version one push
10f417b
raw
history blame contribute delete
766 Bytes
import speech_recognition as sr
import moviepy.editor as mp
import os
def convert_video_to_audio(file_path):
vid_clip = mp.VideoFileClip(file_path)
vid_clip.audio.write_audiofile("temp_converted_mp3.wav")
def convert_audio_to_text():
recogniser = sr.Recognizer()
audio_file = sr.AudioFile(r"temp_converted_mp3.wav")
with audio_file as source:
audio_source = recogniser.record(source)
audio_result = recogniser.recognize_google(audio_source)
os.remove("temp_converted_mp3.wav")
return audio_result
def read_video_file_and_return_text(filepath=r"C:\Users\Shringar\Documents\Python Scripts\hface\course\emma_1.mp4"):
convert_video_to_audio(filepath)
converted_text = convert_audio_to_text()
return converted_text