简体   繁体   中英

Function to get a particular frame of a WAV file in python

The function readframes(n) in python to read a WAV file Reads and returns at most n frames of audio, as a string of bytes. Is there a function in python which returns the Kth frame of the WAV file?

From what I see, there is no direct function to fetch the Kth frame.

However you can easily do this with following code

# Calculate the frame size
framesize = wave.getsampwidth() * wave.getnchannels()

# Resets the pointer to beginning of the stream
wave.rewind()             

# Set the new position to Kth frame           
wave.setpos(wave.tell() + K * framesize)

# Read the Kth frame
frame = wave.readframes(1) 

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