简体   繁体   English

如何在 Python 中读取音频文件目录?

[英]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.我的桌面上存储了一个文件夹,其中包含 19 个 WAV 格式的音频文件。 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???当我执行以下代码读取音频文件时,len(audio-files) 的输出为 0..但它必须为 19。我该如何解决这个问题???

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

output: 0 .输出: 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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