我想计算此代码的单通道数据(以便计算通道1和通道4之间的音频互相关):
import time
import numpy as np
import pyaudio
import scipy
from scipy import signal, fftpack
pyaud = pyaudio.PyAudio()
#open the stream
stream = pyaud.open(
format = pyaudio.paInt16,
channels = 4,
rate = 16000,
input_device_index = 4,
output = False,
input = True,
frames_per_buffer=2048,)
while True:
rawsamps = stream.read(2048)
samps = np.fromstring(rawsamps, dtype=np.int16)
frames_per_buffer_length = len(samps) / 4 #(channels)
assert frames_per_buffer_length == int(frames_per_buffer_length)
samps = np.reshape(samps, (frames_per_buffer_length, 4)) #4 channels
假设原始数据是交错的 这是我需要使用的功能:
signal.correlate(n1, n2, mode='full')
如何为每个通道创建数据数组以使用关联功能?代码的最后几行是否正确?
谢谢
答案 0 :(得分:0)
我使用print loudness(samps[:,0]), loudness(samps[:,3])
找到了答案。它打印在外壳“mic 1响度,麦克风4响度”