> ## Documentation Index
> Fetch the complete documentation index at: https://humain.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Audio hardware

> Microphone and speaker selection guide for embedded kiosk terminals — USB, I²S, MEMS, and analogue options with STT accuracy notes.

Audio quality is the single biggest factor in STT accuracy. A poor microphone in a noisy
environment degrades transcription quality more than any model or parameter change. This page
helps you choose the right hardware for your deployment.

For audio session configuration on iOS and Android, see
[iOS audio session](https://humain.mintlify.site/mobile/audio-session-ios.md) and
[Android audio configuration](https://humain.mintlify.site/mobile/audio-session-android.md).

***

## Microphone selection

| Interface | Example | SNR | Best for | Notes |
| - | - | - | - | - |
| **USB** | Blue Yeti Nano, RØDE NT-USB Mini | ≥ 80 dB | Desktop kiosk, Raspberry Pi | Easiest to integrate — plug and play on Linux (ALSA) |
| **I²S** | Adafruit SPH0645, InvenSense ICS-43434 | 65–70 dB | Embedded Linux HAT | Requires I²S kernel driver or bit-bang; low latency |
| **MEMS PDM** | STMicro MP34DT05, Knowles SPH0641 | 61–64 dB | MCU (STM32, nRF52) | Integrated digital output; easy on-board placement |
| **Analogue** | Adafruit MAX9814 | 50–60 dB | Prototyping only | ADC noise floor limits STT accuracy; avoid in production |

> [!NOTE]
>
> Gemini Live — the model that handles live voice sessions — performs best with microphones
> that deliver **≥ 16 kHz sample rate** and **SNR ≥ 65 dB**. Below this threshold, transcription
> accuracy degrades significantly in noisy environments.

### Connecting to the C library

How you wire audio hardware to `kiosk-c` depends on the interface:

**USB microphone (Linux)** — the built-in ALSA helper is the simplest path. Pass `"default"` or
the specific ALSA device name to `kiosk_alsa_create()`:

```c theme={null}
kiosk_alsa_config_t alsa_cfg = {
    .capture_device  = "hw:1,0",   /* USB mic — check arecord -l */
    .playback_device = "hw:0,0",   /* I²S speaker — check aplay -l */
    .sample_rate     = 16000,
};
kiosk_audio_capture_fn  cap  = NULL;
kiosk_audio_playback_fn play = NULL;
void *alsa_ud = NULL;
kiosk_alsa_create(&alsa_cfg, &cap, &play, &alsa_ud);
```

**I²S MEMS microphone** — supply a custom `capture_fn` that reads from your DMA ring buffer.
The callback runs on the library's audio thread and must complete within `frame_ms` (default 20 ms):

```c theme={null}
static int i2s_capture(int16_t *buf, size_t buf_len, int frames, void *userdata) {
    /* Copy frames from DMA ring buffer into buf.
     * Must not block, allocate memory, or call printf. */
    return dma_ring_read(buf, frames); /* returns frames actually written */
}
```

**I²S DAC (playback)** — supply a custom `playback_fn` that writes PCM to your DAC driver:

```c theme={null}
static void i2s_playback(const int16_t *buf, int frames, void *userdata) {
    dac_write(buf, frames); /* non-blocking write to I²S DMA buffer */
}
```

Pass these callbacks in `kiosk_voice_config_t` instead of the ALSA helper. Full callback
signatures and real-time constraints are documented in the
[C library reference](https://humain.mintlify.site/embedded/c-library.md).

***

## Microphone placement and acoustic treatment

* **Distance:** Place the microphone 20–50 cm from the speaker's mouth for countertop kiosks.
  Drive-through applications may require a directional beamforming array.
* **Enclosure:** Avoid mounting microphones in fully enclosed plastic casings — resonances
  colour the signal and reduce STT accuracy. Use a mesh grille.
* **Echo cancellation:** If your device plays TTS audio through a speaker, the microphone will
  pick it up and the server-side AEC (Acoustic Echo Cancellation) must remove it. AEC works
  best when speaker and microphone are on different surfaces of the enclosure. Aim for ≥ 10 dB
  acoustic isolation.

***

## Speaker and amplifier

| Component | Example | Power | Notes |
| - | - | - | - |
| **USB speaker** | Jabra Speak 410 | — | All-in-one — mic + speaker, USB audio class |
| **Class D amp + driver** | TPA2012D2 + 4 Ω 3 W speaker | 3 W | Compact, efficient for kiosk enclosures |
| **I²S amp** | MAX98357A | 3.2 W | Directly driven from I²S, no separate DAC needed |
| **HDMI audio** | HDMI display built-in speaker | — | Convenient for touchscreen kiosks; latency may vary |

For kiosk deployments, a **Class D mono amplifier + dedicated speaker** gives the best audio
quality at lowest cost. Use an 8 Ω, 5 W speaker for enclosed cabinets; a 4 Ω speaker if heat
dissipation is not a concern.

***

## ALSA configuration for Raspberry Pi

Configure ALSA to use your USB microphone and I²S speaker simultaneously:

```bash theme={null}
# List available audio devices
aplay -l   # playback devices
arecord -l # capture devices
```

Create `/etc/asound.conf`:

```text theme={null}
# ALSA config — USB mic (card 1) + I2S speaker (card 0)
pcm.!default {
    type asym
    playback.pcm "hw:0,0"   # I2S speaker on card 0
    capture.pcm  "hw:1,0"   # USB microphone on card 1
}

ctl.!default {
    type hw
    card 0
}
```

Test with:

```bash theme={null}
# Record 5 seconds from USB mic
arecord -D hw:1,0 -f S16_LE -r 16000 -c 1 -d 5 test.wav

# Play back through I2S speaker
aplay -D hw:0,0 test.wav
```

***

> [accordion] STT accuracy optimisation
>
> **Sample rate:** Capture at 16 000 Hz (16 kHz) or 48 000 Hz. Do not resample from 8 kHz
> — low-frequency audio discards speech harmonics critical for STT.
>
> **Bit depth:** 16-bit PCM is sufficient. 24-bit or 32-bit PCM is wasteful over the network
> and provides no STT benefit after codec encoding.
>
> **Noise suppression:** Enable hardware noise suppression if your microphone supports it
> (many USB conference microphones do). Do not stack software noise suppression on top of
> hardware suppression — double-processing degrades the signal.
>
> **Gain staging:** Aim for an average capture level of −12 dBFS during speech, with peaks
> below −3 dBFS. Clipping (above 0 dBFS) destroys STT accuracy and cannot be recovered.
> Use `alsamixer` or `amixer` to set input gain.
>
> **Silence and VAD:** The Humain server runs voice activity detection (VAD). Do not
> gate the microphone client-side — let the server handle VAD. Sending silence between
> utterances is expected and has no cost impact.
>
> **Acoustic echo cancellation:** If you implement speaker playback, enable server-side AEC
> by setting `AudioManager.MODE_IN_COMMUNICATION` (Android) or `AVAudioSession.mode =
>     .voiceChat` (iOS). On embedded Linux, `kiosk-c` enables AEC automatically when a voice
> session is opened with ALSA capture + playback.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.