函数以获取python中WAV文件的特定帧
python中读取WAV文件的函数readframes(n)读取并返回最多n帧的音频(以字节字符串形式)。python中是否有函数返回WAV文件的第k帧?据我所见,没有直接函数获取第k帧 但是,您可以使用以下代码轻松地完成此操作函数以获取python中WAV文件的特定帧,python,wav,Python,Wav,python中读取WAV文件的函数readframes(n)读取并返回最多n帧的音频(以字节字符串形式)。python中是否有函数返回WAV文件的第k帧?据我所见,没有直接函数获取第k帧 但是,您可以使用以下代码轻松地完成此操作 # Calculate the frame size framesize = wave.getsampwidth() * wave.getnchannels() # Resets the pointer to beginning of the stream wave.
# 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)