SpeechRecognition으로 오디오 파일 읽기

Python으로 배우는 음성 언어 처리

Daniel Bourke

Machine Learning Engineer/YouTube Creator

AudioFile 클래스

import speech_recognition as sr

# 인식기 인스턴스 설정 recognizer = sr.Recognizer()
# 오디오 파일 읽기 clean_support_call = sr.AudioFile("clean-support-call.wav")
# clean_support_call의 타입 확인 type(clean_support_call)
<class 'speech_recognition.AudioFile'>
Python으로 배우는 음성 언어 처리

AudioFile에서 AudioData로

recognizer.recognize_google(audio_data=clean_support_call)
AssertionError: ``audio_data`` must be audio data
# AudioFile을 AudioData로 변환
with clean_support_call as source:

# 오디오 녹음 clean_support_call_audio = recognizer.record(source)
# 타입 확인 type(clean_support_call_audio)
<class 'speech_recognition.AudioData'>
Python으로 배우는 음성 언어 처리

AudioData 전사하기

# 클린 지원 통화 전사
recognizer.recognize_google(audio_data=clean_support_call_audio)
hello I'd like to get some help setting up my account please
Python으로 배우는 음성 언어 처리

Duration과 offset

  • durationoffset은 기본값이 모두 None입니다.
# duration과 offset을 기본값으로 유지
with clean_support_call as source:
    clean_support_call_audio = recognizer.record(source,
                                                 duration=None,
                                                 offset=None)
# 처음 2초만 가져오기
with clean_support_call as source:
    clean_support_call_audio = recognizer.record(source,
                                                 duration=2.0)
hello I'd like to get
Python으로 배우는 음성 언어 처리

연습해 봅시다!

Python으로 배우는 음성 언어 처리

Preparing Video For Download...