0

I'm trying to make simple beamforming system with two USB microphone, and succeeded connecting both with a computer. Here is my code.

import numpy as np
from scipy.io import wavfile
import time
import pyaudio
import matplotlib.pyplot as plt
import wave

p = pyaudio.PyAudio()
FORMAT = pyaudio.paInt16

def callback1(in_data, frame_count, time_info, flag):
   input_wave1 = np.fromstring(in_data, 'Float32')
   return (input_wave1,pyaudio.paContinue)

def callback2(in_data, frame_count, time_info, flag):
   input_wave2 = np.fromstring(in_data, 'Float32')
   return (input_wave2,pyaudio.paContinue)

CHANNELS = 1
RATE = 22050
buffer_size = 200

stream1 = p.open(format=FORMAT,
               channels=CHANNELS,
               frames_per_buffer = buffer_size,
               rate=RATE,
               output=True,
               input=True,
               input_device_index = 1,
               stream_callback = callback1)

stream2 = p.open(format = FORMAT,
               channels = CHANNELS,
               frames_per_buffer = buffer_size,
               rate = RATE,
               output=True,
               input = True,
               input_device_index = 2,
               stream_callback = callback2)

Now, my problem is that I can't calculate beamforming sound using two data (input_wave1, input_wave2). Is it possible that with only a few edits, or is there another way? My goal is to run this code from raspberry pi. I'm sorry about my poor English.

  • how do you compute beam forming with a single source? this seems like a pretty domain-specific question with out a lot of context. are you having a specific problem with the pyaudio API or are you having trouble implementing a numerical algorithm? – Paul H May 01 '18 at 04:22
  • Thanks for your comment. Yes, it is a single source even thought I have two microphones, because I use two callback functions. My problem is, simply, I want to add two data input_wave1 and input_wave2 from each callback function, and emit the result. But, I think that it is not possible to add them because two stream have their own callback functions in this code. Should I make a new function to unite callback functions or change the callback functions? – Jae Yun Yoo May 01 '18 at 06:14

0 Answers0