简体   繁体   中英

How can I read audio files directory in Python?

I have a folder stored on the my desktop, and its contains 19 audio file in WAV format. When I execute the following code for read the audio file the output for len(audio-files) was 0..but its must be 19. How can I solve this problem???

from glob import glob
data_dir = './audio featur-extraction\audio-setA/'
audio_files = glob(data_dir + '*.wav')
len(audio_files)
 

output: 0 .

If you really just want the audio data.

import wave, os, glob
zero = []
path = '/path/to/directory'
for filename in glob.glob(os.path.join(path, '*.wav')):
    w = wave.open(filename, 'r')
    d = w.readframes(w.getnframes())
    zero.append(d)
    w.close()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM