Skip to content

Instantly share code, notes, and snippets.

@ameisehaufen
Created March 18, 2021 00:43
Show Gist options
  • Save ameisehaufen/601306473ee88d674e1f21506b542a0e to your computer and use it in GitHub Desktop.
Save ameisehaufen/601306473ee88d674e1f21506b542a0e to your computer and use it in GitHub Desktop.
Speech to Text script, only for small videos, using google speech recognition.
#!/usr/bin/env python3
import speech_recognition as sr
import moviepy.editor as mp
import sys
clip = mp.VideoFileClip(sys.argv[1])
clip.audio.write_audiofile(r"/tmp/converted.wav")
audio = sr.AudioFile("/tmp/converted.wav")
r = sr.Recognizer()
with audio as source:
audio_file = r.record(source)
# result = r.recognize_google(audio_file)
result = r.recognize_google(audio_file, language = "pt-BR")
# exporting the result
with open('recognized.txt',mode ='w') as file:
file.write("Recognized Speech:")
file.write("\n")
file.write(result)
print("ready!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment