Created
July 12, 2020 12:20
-
-
Save jaecheoljung/783a5f14b79a450acd59ee6eb3a316e5 to your computer and use it in GitHub Desktop.
m4a audio file to text
This file contains hidden or 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 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