File size: 766 Bytes
10f417b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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