Created
March 26, 2021 17:11
-
-
Save martindaniel4/d22a77d64bf3559072c1b7adc216c108 to your computer and use it in GitHub Desktop.
video_transcription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wave, math, contextlib | |
import speech_recognition as sr | |
from moviepy.editor import AudioFileClip | |
transcribed_audio_file_name = "transcribed_speech.wav" | |
zoom_video_file_name = "video.mp4" | |
audioclip = AudioFileClip(zoom_video_file_name) | |
audioclip.write_audiofile(transcribed_audio_file_name) | |
with contextlib.closing(wave.open(transcribed_audio_file_name,'r')) as f: | |
frames = f.getnframes() | |
rate = f.getframerate() | |
duration = frames / float(rate) | |
total_duration = math.ceil(duration / 60) | |
r = sr.Recognizer() | |
for i in range(0, total_duration): | |
with sr.AudioFile(transcribed_audio_file_name) as source: | |
audio = r.record(source, offset=i*60, duration=60) | |
f = open("transcription.txt", "a") | |
f.write(r.recognize_google(audio)) | |
f.write(" ") | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment