小编S_e*_*ror的帖子

如何使用Python正确解码.wav

我正在编码WAVE音频文件的基本频率analisys,但是在从WAVE帧转换为整数时遇到麻烦。

这是我的代码的相关部分:

import wave
track = wave.open('/some_path/my_audio.wav', 'r')

byt_depth = track.getsampwidth() #Byte depth of the file in BYTES
frame_rate = track.getframerate()
buf_size = 512

def byt_sum (word):
#convert a string of n bytes into an int in [0;8**n-1]
    return sum( (256**k)*word[k] for k in range(len(word)) )

raw_buf = track.readframes(buf_size)
'''
One frame is a string of n bytes, where n = byt_depth.
For instance, with a 24bits-encoded file, track.readframe(1) could be:
b'\xff\xfe\xfe'.
raw_buf[n] returns an int in [0;255]
'''

sample_buf …
Run Code Online (Sandbox Code Playgroud)

python audio int byte wave

5
推荐指数
1
解决办法
2276
查看次数

标签 统计

audio ×1

byte ×1

int ×1

python ×1

wave ×1