Skip to content

Instantly share code, notes, and snippets.

@jrg94
Last active July 9, 2020 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrg94/60c6fba1687587ee18fd580bb053d68b to your computer and use it in GitHub Desktop.
Save jrg94/60c6fba1687587ee18fd580bb053d68b to your computer and use it in GitHub Desktop.
A copy of a speech recognition script used to transcribe an interview
import speech_recognition as sr
from pydub import AudioSegment
import os
AudioSegment.converter = r"C:\Users\Jeremy Grifski\AppData\Roaming\JetBrains\PyCharmCE2020.1\scratches\ffmpeg.exe"
r = sr.Recognizer()
for i, filename in enumerate(os.listdir('audio')):
sound = AudioSegment.from_mp3(f'audio/{filename}')
sound.export(f"dump/{filename[:-4]}.wav", format="wav")
with sr.AudioFile(f"dump/{filename[:-4]}.wav") as source, open("transcript.txt", 'a') as transcript:
audio = r.record(source)
print(f"{i * 30} seconds: {r.recognize_google(audio)}", file=transcript)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment