본문 바로가기
Python

librosa와 soundfile 패키지를 이용한 음성 다운 샘플링

by daewooki 2022. 9. 29.
반응형

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import librosa
import soundfile
import os
 
def down_sample(source_path,dest_path):
    extlist = ['.wav''.pcm']
    for (path, dir, files) in os.walk(source_path):
        for filename in files:
            ext = os.path.splitext(filename)[-1]
            if ext in extlist:
                wav_source_path = source_path + os.sep + filename
                wav_dest_path = dest_path + os.sep + filename
                y,sr = librosa.load(wav_source_path, sr=44100)
                resample = librosa.resample(y,sr,22050)
                soundfile.write(wav_dest_path,resample,22050)
 
if __name__ == '__main__':
    source_path = '<Sound File Path for Load>'
    dest_path = '<Sound File Path to Save'
    down_sample(source_path, dest_path)
cs
반응형

댓글