2017-02-10 26 views
3

我要計算的單信道的數據(爲了計算信道1和信道之間的音頻互相關4)該代碼的:PyAudio - 多通道管理離析

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

您似乎在問[相同]問題[http://support.microsoft.com/kb/41922139/]和[結束](http:///stackoverflow.com/q/42027487/)。我建議你從小開始學習一些關於NumPy的基礎知識(網上有很多很好的教程)。你可能想看看[this](http://nbviewer.jupyter.org/github/mgeier/python-audio/blob/master/simple-signals.ipynb)和[that](http:// nbviewer .jupyter.org/github上/ mgeier /蟒音頻/斑點/主/音頻文件/音頻文件與 - wave.ipynb)。 – Matthias

+0

一旦你這樣做了,你可以再看看我之前展示過的[示例](https://github.com/spatialaudio/python-sounddevice/blob/master/examples/plot_input.py)。 – Matthias

回答

0

我找到了答案,用print loudness(samps[:,0]), loudness(samps[:,3])。它打印在外殼「麥克風1的響度,麥克風4的響度」

+0

你可以接受你自己的anwser!見:HTTP://stackoverflow.com/help/self-answer –