我正在尝试将汉明窗应用于音频流,该流缓冲区的缓冲区大小为200,并且输入音频数据(每个缓冲区/块)是以16,000 Hz采样的音频。
def hamming_window(audio_stream, sample_rate):
frame_size = float(0.025) # Frame size: 25 ms
frame_increment = float(0.010) # Overlap: 15 ms
frame_length = int(round(frame_size * sample_rate)) # seconds to samples
frame_step = int(round(frame_increment * sample_rate)) # seconds to samples
stream_length = len(audio_stream)
num_frames = int(np.ceil(np.abs(stream_length - frame_length) / frame_step)) # atleast 1
# preventing the last frame from not be missing any samples by filling it with zeros
padding_length = num_frames * frame_step + frame_length
zeroes_padding = np.zeros(padding_length - stream_length)
padded_stream = np.append(audio_stream, zeroes_padding)
# create frames by indexing the audio stream
num_frame_arr = np.arange(start=0, stop=frame_length) # evenly spaced array '0' to 'frame_length - 1'
frame_len_arr = np.arange(start=0, stop= num_frames*frame_step, step=frame_step)
indices = np.tile(num_frame_arr, (num_frames, 1)) + np.tile(frame_len_arr, (frame_length, 1)).T
frames = padded_stream[indices.astype(np.int32, copy=False)]
...
return frames
结果是“ IndexError:索引81超出了轴1的尺寸81。” 在'帧= padded_stream [indices.astype(np.int32,copy = False)]'
关于如何解决此IndexError的任何想法? 谢谢!