繁体   English   中英

在python中获取WAV文件的特定帧的函数

[英]Function to get a particular frame of a WAV file in python

python中的readframes(n)函数用于读取WAV文件读取并返回最多n帧音频,以字节字符串的形式出现。 python中是否有一个函数返回WAV文件的第K个帧?

从我所看到的,没有直接函数来获取第K个帧。

但是,您可以使用以下代码轻松完成此操作

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

暂无
暂无

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

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