PyDub으로 오디오 변환 및 저장

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

Daniel Bourke

Machine Learning Engineer/YouTube Creator

오디오 파일 내보내기

from pydub import AudioSegment

# 오디오 파일 불러오기
wav_file = AudioSegment.from_file("wav_file.wav")

# 10데시벨 증가 louder_wav_file = wav_file + 10
# 더 큰 오디오 파일 내보내기 louder_wav_file.export(out_f="louder_wav_file.wav", format="wav")
<_io.BufferedRandom name='louder_wav_file.wav'>
Python으로 배우는 음성 언어 처리

여러 오디오 재포맷 및 내보내기

def make_wav(wrong_folder_path, right_folder_path):

# 형식이 잘못된 파일 반복 처리 for file in os.scandir(wrong_folder_path):
# 수정 대상 오디오 확장자만 처리 if file.path.endswith(".mp3") or file.path.endswith(".flac"):
# 새 .wav 파일명 생성 out_file = right_folder_path + os.path.splitext(os.path.basename(file.path))[0] + ".wav"
# 오디오를 읽어 wav 형식으로 내보내기 AudioSegment.from_file(file.path).export(out_file, format="wav")
print(f"Creating {out_file}")
Python으로 배우는 음성 언어 처리

여러 오디오 재포맷 및 내보내기

# 새 함수 호출
make_wav("data/wrong_formats/", "data/right_format/")
Creating data/right_types/wav_file.wav
Creating data/right_types/flac_file.wav
Creating data/right_types/mp3_file.wav
Python으로 배우는 음성 언어 처리

편집 및 내보내기

def make_no_static_louder(static_quiet, louder_no_static):
    # 잡음 있고 작은 음량 파일 반복 처리(wav 형식)
    for file in os.scandir(static_quiet_folder_path):

# 새 파일 경로 생성 out_file = louder_no_static + os.path.splitext(os.path.basename(file.path))[0] + ".wav"
# 오디오 읽기 audio_file = AudioSegment.from_file(file.path)
# 처음 3초 제거, 10데시벨 증가, 내보내기 audio_file = (audio_file[3100:] + 10).export(out_file, format="wav") print(f"Creating {out_file}")
Python으로 배우는 음성 언어 처리

편집 및 내보내기

# 잡음 제거 및 음량 증가
make_no_static_louder("data/static_quiet/", "data/louder_no_static/")
Creating data/louder_no_static/speech-recognition-services.wav
Creating data/louder_no_static/order-issue.wav
Creating data/louder_no_static/help-with-acount.wav
Python으로 배우는 음성 언어 처리

이제 당신의 차례!

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

Preparing Video For Download...