如何通过Python中的二进制文件操纵WAV文件的数据
我正在尝试通过使用其二进制结构或其他用语更改其二进制结构来操纵WAV文件的数据(更改评论部分中放入URL的元数据)。这是我尝试这样做的尝试:
with open('test.wav', 'r+b') as f:
b = f.read()
l = b.find(b'\x00ICMT') + 1 # Find the position after ICMT
v = b.find(b'\x00ICRD') - 1 # Find the position before ICRD
f = bytearray(b) # Make f into a bytearray
f[l:v] = b'URL: RandomURL' # Use l and v to get the section I want to rewrite (comment section)
在上面的代码中,我尝试将WAV文件转换为字节数组,然后在ICMT之后找到位置(元数据中的注释部分)以及ICMT部分结束时的位置(之前ICRD的部分)。然后,我使用此信息访问字节数组中的评论部分,并将其放入具有URL的字节中。但是,每当我尝试一下时,我实际上并没有更改WAV文件的内容。我的方法有什么问题,或者有一种更简单的方法来操纵WAV文件的二进制内容以获取我想要的东西?
I'm trying to manipulate a wav file's data (change the metadata to put in a url in the comment section) by using its binary structure, or in other terms change its binary structure. Here is my attempt at trying to do so:
with open('test.wav', 'r+b') as f:
b = f.read()
l = b.find(b'\x00ICMT') + 1 # Find the position after ICMT
v = b.find(b'\x00ICRD') - 1 # Find the position before ICRD
f = bytearray(b) # Make f into a bytearray
f[l:v] = b'URL: RandomURL' # Use l and v to get the section I want to rewrite (comment section)
In the code above I'm trying to convert the wav file into a byte array and then find the position after ICMT (comment section in the metadata) and the position when ICMT's section ends (before ICRD's section). I then use this information to access the comment section within the byte array and make that into a byte that has the url. However, whenever I try this I don't actually change the contents of the wav file, it seems. What is wrong with my approach or is there an easier way to manipulate the binary contents of a wav file to get what I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论