Python으로 배우는 음성 언어 처리
Daniel Bourke
Machine Learning Engineer/YouTube Creator
# 오디오 파일 불러오기
wav_file = AudioSegment.from_file("wav_file.wav")
# 60 dB 감소
quiet_wav_file = wav_file - 60
# 작은 소리 오디오 인식 시도
recognizer.recognize_google(quiet_wav_file)
UnknownValueError:
# 볼륨 10 dB 증가
louder_wav_file = wav_file + 10
# 인식 시도
recognizer.recognize_google(louder_wav_file)
this is a wav file
# AudioSegment 임포트 및 정규화
from pydub import AudioSegment
from pydub.effects import normalize
from pydub.playback import play
# 크기 편차가 큰 오디오 불러오기
loud_quiet = AudioSegment.from_file("loud_quiet.wav")
# 음량 정규화
normalized_loud_quiet = normalize(loud_quiet)
# 소리 확인
play(normalized_loud_quiet)
# 시작에 잡음이 있는 오디오 불러오기
static_at_start = AudioSegment.from_file("static_at_start.wav")
# 슬라이싱으로 잡음 제거
no_static_at_start = static_at_start[5000:]
# 새 소리 확인
play(no_static_at_start)
# 두 오디오 파일 불러오기
wav_file_1 = AudioSegment.from_file("wav_file_1.wav")
wav_file_2 = AudioSegment.from_file("wav_file_2.wav")
# 두 오디오 파일 결합
wav_file_3 = wav_file_1 + wav_file_2
# 소리 확인
play(wav_file_3)
# 두 wav 파일을 결합하고 더 크게 만들기
louder_wav_file_3 = wav_file_1 + wav_file_2 + 10
# 통화 오디오 불러오기
phone_call = AudioSegment.from_file("phone_call.wav")
# 채널 수 확인
phone_call.channels
2
# 스테레오를 모노로 분리
phone_call_channels = phone_call.split_to_mono()
phone_call_channels
[<pydub.audio_segment.AudioSegment, <pydub.audio_segment.AudioSegment>]
# 첫 번째 항목의 채널 수 확인
phone_call_channels[0].channels
1
# 첫 번째 채널 인식
recognizer.recognize_google(phone_call_channel_1)
the pydub library is really useful
Python으로 배우는 음성 언어 처리