How can I read audio files directory in Python?

2.3k Views Asked by At

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.

1

There are 1 best solutions below

2
On

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()