我有一个脚本,可以根据HTTP请求返回的byte对象将音符写入目录。我遇到的问题是.ogg声音文件是5秒长,理想情况下我想缩短到0.5秒。这是否可以通过简单地删除byte对象的块来实现? 我知道通过pysoundfile可以使用帧和采样率来计算持续时间,从而写入x帧。这只适用于静态速率,但是由于提取的是原始形式的音符,因此这些文件的采样速率未知
下面是我写的一些代码
for notenumbers in range(48, 64+1):
note = requests.get(url.format(instrument, notenumbers))
notebinary = note.content
time.sleep(3)
with open("E:\\useraccount\\x\\x\\"+str(dirname)+"\\"+str(instrname)+"\\"+str(instrname) +"-" +str(notenumbers) +".ogg", "wb") as o:
print("Creating file named: " +str(instrname) +":" +str(notenumbers) +".ogg")
o.write(notebinary)
如果你能帮忙的话,谢谢你
目前没有回答
相关问题 更多 >
编程相关推荐