简体   繁体   中英

How to get number of samples from wav file?

I know that I can do soxi file.wav to get info such as

Input File     : '2.wav'
Channels       : 1
Sample Rate    : 8000
Precision      : 16-bit
Duration       : 00:04:14.54 = 2036320 samples ~ 19090.5 CDDA sectors
File Size      : 4.07M
Bit Rate       : 128k
Sample Encoding: 16-bit Signed Integer PCM

Where I can see that it has 2036320 samples . However how do I do the same thing in python?

I have tried this through reading some articles but I keep getting <bound method Wave_read.readframes of <wave.Wave_read instance at...

import wave

audio_file = wave.open(wavfile, 'r')
print(audio_file.readframes)
audio_file.close()

The solution was to use getnframes() method instead of readframes

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