Why Connect a Microphone to an AI Agent?
Voice control is the next frontier for IoT automation. With a MEMS microphone like the INMP441 or an analog electret microphone amplifier like the MAX9814, you can turn any ESP32 or Raspberry Pi into a voice-command receiver. Pair it with ASI Biont, and the AI agent can process audio, recognize commands, and trigger actions—without writing complex speech recognition pipelines from scratch.
ASI Biont doesn't require a pre-built device integration. Instead, it uses execute_python to generate and run custom Python code that talks to your microphone hardware. You just describe your setup in the chat, and the AI handles the rest.
How ASI Biont Connects to a Microphone
Microphones are not industrial PLCs—they don't speak Modbus or BACnet. The typical connection looks like this:
| Component | Role | Connection Method |
|---|---|---|
| ESP32 with I2S MEMS mic (e.g., INMP441) | Captures audio, streams over Wi-Fi | MQTT or WebSocket (via execute_python) |
| Raspberry Pi with USB mic (e.g., MAX9814 via ADC) | Captures audio locally, processes with Python | SSH (via execute_python + paramiko) |
ASI Biont can connect to either:
- ESP32 via MQTT: The ESP32 publishes raw audio samples or frequency data to a broker. ASI Biont subscribes using paho-mqtt in execute_python, analyzes the data, and sends commands back.
- Raspberry Pi via SSH: The AI writes a Python script that runs on the Pi, captures audio with pyaudio or sounddevice, performs simple command recognition (e.g., keyword spotting via cross-correlation or spectral analysis), and returns results.
Concrete Example: ESP32 + INMP441 + ASI Biont
The Setup
Hardware:
- ESP32 DevKit (e.g., ESP32-DevKitC)
- INMP441 MEMS microphone (I2S interface)
- Breadboard and jumper wires
Wiring:
| INMP441 Pin | ESP32 Pin |
|---|---|
| L/R (select left/right) | GND (left channel) |
| DOUT (data out) | GPIO 32 (I2S data in) |
| BCLK (bit clock) | GPIO 26 (I2S bit clock) |
| WS (word select) | GPIO 25 (I2S word select) |
| VDD | 3.3V |
| GND | GND |
Step 1: ESP32 Microphone Code
Flash the ESP32 with Arduino code that samples audio and sends a simple metric—like the RMS volume—over MQTT every second.
#include <WiFi.h>
#include <PubSubClient.h>
#include <driver/i2s.h>
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
const char* mqtt_server = "broker.hivemq.com";
WiFiClient espClient;
PubSubClient client(espClient);
#define I2S_WS 25
#define I2S_SD 32
#define I2S_SCK 26
#define I2S_PORT I2S_NUM_0
#define SAMPLE_RATE 16000
#define SAMPLE_BITS 16
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(500);
client.setServer(mqtt_server, 1883);
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = SAMPLE_RATE,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = I2S_COMM_FORMAT_I2S,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 8,
.dma_buf_len = 64
};
i2s_pin_config_t pin_config = {
.bck_io_num = I2S_SCK,
.ws_io_num = I2S_WS,
.data_out_num = -1,
.data_in_num = I2S_SD
};
i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
i2s_set_pin(I2S_PORT, &pin_config);
}
void loop() {
if (!client.connected()) {
client.connect("ESP32Mic");
}
client.loop();
int16_t buffer[512];
size_t bytes_read;
i2s_read(I2S_PORT, buffer, sizeof(buffer), &bytes_read, portMAX_DELAY);
float rms = 0;
int samples = bytes_read / 2;
for (int i = 0; i < samples; i++) {
rms += buffer[i] * buffer[i];
}
rms = sqrt(rms / samples);
char msg[16];
snprintf(msg, sizeof(msg), "%.2f", rms);
client.publish("home/esp32/mic/rms", msg);
delay(1000);
}
Step 2: Connect ASI Biont to the MQTT Stream
In the ASI Biont chat, you simply describe:
"Connect to MQTT broker at broker.hivemq.com:1883, subscribe to topic 'home/esp32/mic/rms', and alert me in Telegram if RMS exceeds 1000 for more than 3 consecutive readings."
ASI Biont generates and runs the following Python code (execute_python sandbox):
import paho.mqtt.client as mqtt
import time
BROKER = "broker.hivemq.com"
PORT = 1883
TOPIC = "home/esp32/mic/rms"
THRESHOLD = 1000
CONSECUTIVE_COUNT = 3
high_count = 0
# This function is called by ASI Biont after it receives the MQTT message
# (simplified for clarity)
def on_message(client, userdata, msg):
global high_count
rms = float(msg.payload.decode())
if rms > THRESHOLD:
high_count += 1
if high_count >= CONSECUTIVE_COUNT:
# Trigger Telegram alert via ASI Biont's built-in notification
# (The AI agent sends the alert automatically)
print(f"ALERT: Loud noise detected! RMS = {rms}")
high_count = 0
else:
high_count = 0
client = mqtt.Client()
client.on_message = on_message
client.connect(BROKER, PORT, 60)
client.subscribe(TOPIC)
client.loop_start()
# Keep the script alive (sandbox timeout is 30s, so this runs for 30s)
time.sleep(30)
The AI agent runs this script in the sandbox environment. It receives the MQTT messages, processes them, and can send you a Telegram alert if the threshold is exceeded. No manual programming needed.
Step 3: Voice Command Recognition (Raspberry Pi + MAX9814)
For more advanced use—like recognizing spoken words—you can connect a Raspberry Pi with a MAX9814 analog microphone via an ADC (e.g., MCP3008) or a USB sound card. ASI Biont connects via SSH.
Example prompt:
"SSH into my Raspberry Pi at 192.168.1.100 (user: pi, password: raspberry). Install pyaudio and numpy. Write a script that listens for the word 'light' using simple spectral matching, and if detected, publish 'ON' to MQTT topic home/light/command."
ASI Biont generates the full paramiko script, uploads it, and executes it on the Pi. The Pi captures 1-second audio chunks, computes a Mel-frequency cepstral coefficient (MFCC) approximation (using numpy FFT), and compares it to a pre-recorded template for "light".
Why this matters: You don't need cloud speech APIs. The voice command stays local, and ASI Biont orchestrates everything via chat.
Pitfalls to Avoid
- I2S wiring mistakes: INMP441 requires 3.3V, not 5V. Wrong voltage can damage the mic.
- Sample rate mismatch: ESP32 I2S driver supports 16 kHz to 48 kHz. Match your analysis code.
- MQTT broker reliability: If the broker goes down, the ESP32 buffers data. Use
client.publish()with QoS 1 for critical alerts. - Sandbox timeout: execute_python scripts are limited to 30 seconds. For continuous monitoring, use MQTT subscription with
loop_start()and keep the script alive withtime.sleep(). - Audio noise: The MAX9814 has a gain adjust pin (GAIN). Set it to 40 dB (connect to VDD) for moderate sensitivity; 60 dB (float) may saturate in loud environments.
Why ASI Biont Makes This Easy
Traditional voice integration requires:
- Writing MQTT client code
- Setting up a cloud function for alerting
- Debugging serial protocols
With ASI Biont, you skip all of that. You describe your hardware (ESP32 + INMP441, or Raspberry Pi + MAX9814) and your goal ("alert me when noise level exceeds threshold", "turn on a light when I say 'light'"). The AI agent writes the integration code using execute_python, connects via MQTT or SSH, and handles the logic.
No dashboard, no buttons, no waiting for new integrations. Just chat.
Get Started Today
You can try this integration right now on asibiont.com. Wire up your microphone, connect your ESP32 or Raspberry Pi, and tell the AI agent what you want. It will generate the Python code, connect to your device, and start monitoring—all within seconds.
Voice control has never been simpler.
Comments