Convert/Extract Speech from Video to Text with Python

  1. Video editing library to extract speech — MoviePy
#install libs
!pip install SpeechRecognition moviepy
import moviepy.editor as mpe
#convert to audio
video = mpe.VideoFileClip("raw.mp4")
video.audio.write_audiofile(r"converted.wav")
#convert to text
import speech_recognition as sr
r = sr.Recognizer()audio = sr.AudioFile("converted.wav")
with audio as source:
audio_file = r.record(source)
result = r.recognize_google(audio_file)
# exporting text 
with open('recognized.txt',mode ='w') as file:
file.write("Recognized Speech:")
file.write("\n")
file.write(result)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Renee LIN

Renee LIN

Passionate about web dev and data analysis. Huge FFXIV fan.