To create a 3-mic beamforming assembly using three ESP-WROOM-32s, you'll need to follow these steps:
- Set up the microphones and ESP-WROOM-32s
- Stream audio data from microphones to the workstation
- Process the audio data and implement beamforming on the workstation
- (Optional) Send the processed audio data back to ESP-WROOM-32s for further use
Here is a code outline for both MicroPython (running on ESP-WROOM-32) and Python (running on the workstation) to achieve this:
MicroPython on ESP-WROOM-32:
- Configure I2S to read audio data from the microphones:
from machine import I2S, Pin
i2s_config = {
'sck': Pin(18),
'ws': Pin(19),
'sdin': Pin(23),
'mode': I2S.MASTER_RX,
'bits': 32,
'format': I2S.FORMAT_I2S_MSB,
'rate': 16000,
'buffers': 8
}
i2s = I2S(0, i2s_config)
- Send audio data to the workstation over WiFi:
import socket
import struct
import network
WIFI_SSID = 'your_wifi_ssid'
WIFI_PASSWORD = 'your_wifi_password'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
while not wlan.isconnected():
pass
server_ip = 'workstation_ip'
server_port = 8080
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((server_ip, server_port))
while True:
audio_data = i2s.read(1024)
sock.send(struct.pack('<I', len(audio_data)) + audio_data)
Python on the workstation:
- Receive audio data from ESP-WROOM-32s:
import socket
import struct
import numpy as np
def receive_audio_data(conn, addr):
while True:
data_length = struct.unpack('<I', conn.recv(4))[0]
audio_data = conn.recv(data_length)
audio_array = np.frombuffer(audio_data, dtype=np.int32)
process_audio_data(audio_array)
server_ip = ''
server_port = 8080
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((server_ip, server_port))
sock.listen(3)
while True:
conn, addr = sock.accept()
threading.Thread(target=receive_audio_data, args=(conn, addr)).start()
- Process the audio data and implement beamforming:
import numpy as np
from scipy.signal import fftconvolve
def process_audio_data(audio_array):
# Process the audio data and implement beamforming here
# For example, if you have 3 audio arrays from 3 microphones:
# audio_array_1, audio_array_2, audio_array_3
# Delay-and-sum beamforming example:
delay_1_2 = 0 # calculate the time delay between mic1 and mic2
delay_1_3 = 0 # calculate the time delay between mic1 and mic3
delayed_audio_2 = np.roll(audio_array_2, delay_1_2)
delayed_audio_3 = np.roll(audio_array_3, delay_1_3)
beamformed_audio = audio_array_1 + delayed_audio_2 + delayed_audio_3
Note: You will need to adjust the time delays according to your microphone array geometry and desired direction of arrival (DOA) for the beamforming.
This is a basic outline of how you can create a 3-mic beamforming assembly using ESP-WROOM-32s and MicroPython. You will need to adjust the code according to your specific hardware and requirements.