Skip to content

Instantly share code, notes, and snippets.

@jaecheoljung
Created July 12, 2020 12:20
Show Gist options
  • Save jaecheoljung/783a5f14b79a450acd59ee6eb3a316e5 to your computer and use it in GitHub Desktop.
Save jaecheoljung/783a5f14b79a450acd59ee6eb3a316e5 to your computer and use it in GitHub Desktop.
m4a audio file to text
import speech_recognition as sr
import sys
from pydub import AudioSegment
if __name__ == "__main__":
args = sys.argv
if len(args) < 3:
print("Input filename, language(ex. ko-KR)")
exit(0);
speech = AudioSegment.from_file(args[1], "m4a")
speech.export("output.wav", format="wav")
recognizer = sr.Recognizer()
recognizer.energy_threshold = 300
audiofile = sr.AudioFile("output.wav")
with audiofile as source:
audio = recognizer.record(source)
print(recognizer.recognize_google(audio_data=audio, language=args[2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment