audioi2sin – Support for recording audio from an I2S input source.

The audioi2sin module contains the I2SIn class for recording audio from an external I2S source such as a MEMS microphone (e.g. SPH0645LM4H or INMP441).

All classes change hardware state and should be deinitialized when they are no longer needed. To do so, either call deinit() or use a context manager.

Available on these boards
  • 01Space 0.42 OLED ESP32C3
  • 0xCB Gemini
  • 0xCB Helios
  • 42. Keebs Frood
  • 8086 RP2040 Interfacer
  • 8086 USB Interposer
  • AITHinker ESP32-C3S_Kit
  • AITHinker ESP32-C3S_Kit_2M
  • ATMegaZero ESP32-S2
  • Adafruit Camera
  • Adafruit Feather ESP32 V2
  • Adafruit Feather ESP32-C6 4MB Flash No PSRAM
  • Adafruit Feather ESP32-S2 Reverse TFT
  • Adafruit Feather ESP32-S2 TFT
  • Adafruit Feather ESP32-S3 Reverse TFT
  • Adafruit Feather ESP32-S3 TFT
  • Adafruit Feather ESP32S2
  • Adafruit Feather ESP32S3 4MB Flash 2MB PSRAM
  • Adafruit Feather ESP32S3 No PSRAM
  • Adafruit Feather HUZZAH32
  • Adafruit Feather RP2040
  • Adafruit Feather RP2040 Adalogger
  • Adafruit Feather RP2040 CAN
  • Adafruit Feather RP2040 DVI
  • Adafruit Feather RP2040 Prop-Maker
  • Adafruit Feather RP2040 RFM
  • Adafruit Feather RP2040 Scorpio
  • Adafruit Feather RP2040 ThinkInk
  • Adafruit Feather RP2040 USB Host
  • Adafruit Feather RP2350
  • Adafruit Feather RP2350 Adalogger
  • Adafruit Floppsy RP2040
  • Adafruit Fruit Jam
  • Adafruit FunHouse
  • Adafruit HUZZAH32 Breakout
  • Adafruit ItsyBitsy ESP32
  • Adafruit ItsyBitsy RP2040
  • Adafruit KB2040
  • Adafruit Macropad RP2040
  • Adafruit MagTag
  • Adafruit MatrixPortal S3
  • Adafruit Metro ESP32S2
  • Adafruit Metro ESP32S3
  • Adafruit Metro RP2040
  • Adafruit Metro RP2350
  • Adafruit Mini Sparkle Motion
  • Adafruit P4 GPIO
  • Adafruit QT Py ESP32 PICO
  • Adafruit QT Py ESP32-S3 4MB Flash 2MB PSRAM
  • Adafruit QT Py ESP32-S3 no psram
  • Adafruit QT Py ESP32C3
  • Adafruit QT Py ESP32S2
  • Adafruit QT Py RP2040
  • Adafruit QT2040 Trinkey
  • Adafruit Sparkle Motion
  • Adafruit Sparkle Motion Stick
  • Adafruit Tinychad RP2350
  • Adafruit Vindie S2
  • Adafruit-Qualia-S3-RGB666
  • Ai Thinker ESP32-CAM
  • Archi RP2040
  • Arduino Nano ESP32
  • Arduino Nano RP2040 Connect
  • Artisense Reference Design RD00
  • AutosportLabs-ESP32-CAN-X2
  • BARDUINO 4.0.2
  • BBQ20KBD
  • BLING!
  • BLOK
  • BPI-Bit-S2
  • BPI-Leaf-S3
  • BPI-PicoW-S3
  • BastWiFi
  • Bee-Data-Logger
  • Bee-Motion-S3
  • Bee-S3
  • BlizzardS3
  • Bradán Lane STUDIO Explorer Badge
  • COSMO-Pico
  • CRCibernetica IdeaBoard
  • Challenger NB RP2040 WiFi
  • Challenger RP2040 LTE
  • Challenger RP2040 LoRa
  • Challenger RP2040 SD/RTC
  • Challenger RP2040 SubGHz
  • Challenger RP2040 WiFi
  • Challenger RP2040 WiFi/BLE
  • Challenger+ RP2350 BConnect
  • Challenger+ RP2350 WiFi6/BLE5
  • CircuitART Zero S3
  • ColumbiaDSL-Sensor-Board-V1
  • CrowPanel 4.2 EPaper
  • CrumpS2
  • Cytron EDU PICO 2
  • Cytron EDU PICO W
  • Cytron IRIV IO Controller
  • Cytron MOTION 2350 Pro
  • Cytron Maker Feather AIoT S3
  • Cytron Maker Nano RP2040
  • Cytron Maker Pi RP2040
  • Cytron Maker Uno RP2040
  • DFRobot Beetle ESP32-C3
  • DFRobot FireBeetle 2 ESP32-S3
  • Datanoise PicoADK
  • Datanoise PicoADK V2
  • Deneyap Kart
  • Deneyap Kart 1A
  • Deneyap Kart 1A v2
  • Deneyap Kart G
  • Deneyap Mini
  • Deneyap Mini v2
  • E-Fidget
  • EDGES3D
  • ELECFREAKS PICO:ED
  • ES3ink
  • ESP 12k NodeMCU
  • ESP32 Devkit V1
  • ESP32-C3-DevKitM-1
  • ESP32-C3-Lyra-V2
  • ESP32-C6-DevKitC-1-N8
  • ESP32-C6-DevKitM-1
  • ESP32-C61-DevKitC-1-N8R2
  • ESP32-H2-DevKitM-1
  • ESP32-P4 Stamp XL
  • ESP32-P4-Function-EV
  • ESP32-P4X-Function-EV
  • ESP32-S2-DevKitC-1-N4
  • ESP32-S2-DevKitC-1-N4R2
  • ESP32-S2-DevKitC-1-N8R2
  • ESP32-S3-Box-2.5
  • ESP32-S3-Box-Lite
  • ESP32-S3-DevKitC-1-N16
  • ESP32-S3-DevKitC-1-N32R8
  • ESP32-S3-DevKitC-1-N8
  • ESP32-S3-DevKitC-1-N8R2
  • ESP32-S3-DevKitC-1-N8R2 (ROS version)
  • ESP32-S3-DevKitC-1-N8R8
  • ESP32-S3-DevKitC-1-N8R8-with-HACKTABLET
  • ESP32-S3-DevKitM-1-N8
  • ESP32-S3-EYE
  • ESP32-S3-USB-OTG-N8
  • Elecrow CrowPanel
  • Electrolama minik
  • EncoderPad RP2040
  • Espressif ESP32 DevKitc V4 WROOM-32E
  • Espressif ESP32 DevKitc V4 WROVER
  • Espressif ESP32 TTGO T8 v1.7
  • Espressif ESP32-EYE
  • Espressif ESP32-LyraT
  • Espressif-ESP32-S3-LCD-EV-Board
  • Espressif-ESP32-S3-LCD-EV-Board_v1.5
  • FeatherS2
  • FeatherS2 Neo
  • FeatherS2 PreRelease
  • FeatherS3
  • FeatherS3 Neo
  • Fig Pi
  • Flipper Zero Wi-Fi Dev
  • Franzininho WIFI w/Wroom
  • Franzininho WIFI w/Wrover
  • Freenove ESP32-WROVER-DEV-CAM
  • Gravitech Cucumber M
  • Gravitech Cucumber MS
  • Gravitech Cucumber R
  • Gravitech Cucumber RS
  • HEIA-FR Picomo V2
  • HEIA-FR Picomo V3
  • HMI-DevKit-1.1
  • HXR.DK SAO Digital Multimeter
  • Hack Club Sprig
  • Hardkernel Odroid Go
  • Heltec ESP32-S3-WIFI-LoRa-V3
  • Heltec Vison Master E290
  • Heltec Wireless Paper
  • HexKyS2
  • IoTs2
  • Kaluga 1
  • LILYGO T-DISPLAY
  • LILYGO T-DISPLAY S3 v1.2
  • LILYGO T-Deck (Plus)
  • LILYGO T-Display S3 Pro
  • LILYGO T-Dongle S3
  • LILYGO T-QT PRO NO PSRAM
  • LILYGO T-QT PRO PSRAM
  • LILYGO T-Watch-S3
  • LILYGO TEMBED ESP32S3
  • LILYGO TTGO T-01C3
  • LILYGO TTGO T-DISPLAY v1.1
  • LILYGO TTGO T-DISPLAY v1.1 4M
  • LILYGO TTGO T-OI PLUS
  • LILYGO TTGO T8 ESP32-S2
  • LILYGO TTGO T8 ESP32-S2 w/Display
  • LOLIN S3 16MB Flash 8MB PSRAM
  • LOLIN S3 MINI 4MB Flash 2MB PSRAM
  • LOLIN S3 MINI PRO 4MB Flash 2MB PSRAM
  • LOLIN S3 PRO 16MB Flash 8MB PSRAM
  • Lilygo T-watch 2020 V3
  • Luatos Core-ESP32C3
  • M5STACK STAMP-C3
  • M5Stack Atom Echo
  • M5Stack Atom Lite
  • M5Stack Atom Matrix
  • M5Stack Atom U
  • M5Stack AtomS3
  • M5Stack AtomS3 Lite
  • M5Stack AtomS3U
  • M5Stack Cardputer
  • M5Stack Cardputer (ROS version)
  • M5Stack Core Basic
  • M5Stack Core Fire
  • M5Stack Core2
  • M5Stack CoreS3
  • M5Stack CoreS3 SE
  • M5Stack Dial
  • M5Stack DinMeter
  • M5Stack M5Paper
  • M5Stack Stamp-S3
  • M5Stack Stick C
  • M5Stack Stick C Plus
  • M5Stack Stick C Plus2
  • M5Stack Tab5
  • M5Stack Timer Camera X
  • MORPHEANS MorphESP-240
  • MagiClick S3 N4R2
  • Maker Go ESP32C3 Supermini
  • Maker Go ESP32C6 Supermini
  • Maker badge by Czech maker
  • MakerFabs-ESP32-S3-Parallel-TFT-With-Touch-7inch
  • Maple Computing Elite-Pi
  • Melopero Shake RP2040
  • MicroDev microC3
  • MicroDev microS2
  • MixGo CE
  • Music Thing Modular Workshop Computer
  • NHB Systems JL401-S3 4MB Flash 2MB PSRAM
  • NanoS3
  • Neuron
  • Noise Nugget 2040
  • OMGS3
  • Oak Dev Tech BREAD2040
  • Oak Dev Tech Cast-Away RP2040
  • Oak Dev Tech PixelWing ESP32S2
  • Oak Dev Tech RPGA Feather
  • Orpheus Pico
  • Oxocard Artwork
  • Oxocard Connect
  • Oxocard Galaxy
  • Oxocard Science
  • PCBCupid GLYPH S3
  • PCBCupid Glyph Mini 2040
  • PROVES Kit v4
  • Pajenicko PicoPad
  • Pimoroni Badger 2040
  • Pimoroni Badger 2040 W
  • Pimoroni Badger 2350
  • Pimoroni Explorer
  • Pimoroni Inky Frame 5.7
  • Pimoroni Inky Frame 7.3
  • Pimoroni Interstate 75
  • Pimoroni Keybow 2040
  • Pimoroni Motor 2040
  • Pimoroni PGA2040
  • Pimoroni PGA2350
  • Pimoroni Pico DV Base W
  • Pimoroni Pico LiPo (16MB)
  • Pimoroni Pico LiPo (4MB)
  • Pimoroni Pico Plus 2
  • Pimoroni Pico Plus 2 W
  • Pimoroni Pico dv Base
  • Pimoroni PicoSystem
  • Pimoroni Plasma 2040
  • Pimoroni Plasma 2040W
  • Pimoroni Plasma 2350
  • Pimoroni Plasma 2350W
  • Pimoroni Servo 2040
  • Pimoroni Tiny 2040 (2MB)
  • Pimoroni Tiny 2040 (8MB)
  • Pimoroni Tiny 2350
  • Pimoroni Tiny FX
  • ProS3
  • Prokyber Ai-On-The-Edge-Cam
  • PyKey 18 Numpad
  • PyKey 44 Ergo
  • PyKey 60
  • PyKey 87 TKL
  • RF.Guru RP2040
  • RGBTouch Mini
  • RP2.65-F
  • RP2040 Stamp
  • RP2350 Stamp
  • RP2350 Stamp XL
  • Raspberry Breadstick
  • Raspberry Pi Pico
  • Raspberry Pi Pico 2
  • Raspberry Pi Pico 2 W
  • Raspberry Pi Pico W
  • Red S2-WROOM
  • S2Mini
  • S2Pico
  • SQFMI Watchy
  • Saola 1 w/Wroom
  • Saola 1 w/Wrover
  • Seeed Studio XIAO ESP32C3
  • Seeed Xiao ESP32-C6 4MB Flash 512KB SRAM
  • Seeed Xiao ESP32-S3 Sense
  • Seeeduino XIAO RP2040
  • Seeeduino XIAO RP2350
  • Silicognition LLC RP2040-Shim
  • SparkFun MicroMod RP2040 Processor
  • SparkFun Pro Micro RP2040
  • SparkFun Pro Micro RP2350
  • SparkFun Thing Plus - RP2040
  • SparkFun Thing Plus RP2350
  • Spotpear ESP32C3 LCD 1.44
  • Spotpear ESP32C3 LCD 1.69
  • Studiolab Pico Expander
  • Sunton ESP32-2424S012
  • Sunton-ESP32-8048S050
  • Sunton-ESP32-8048S070
  • TTGO T8 ESP32-S2-WROOM
  • Targett Module Clip w/Wroom
  • Targett Module Clip w/Wrover
  • ThingPulse Pendrive S3
  • TinyC6
  • TinyCircuits Thumby
  • TinyCircuits Thumby Color
  • TinyPICO
  • TinyPICO Nano
  • TinyS2
  • TinyS3
  • TinyWATCH S3
  • VCC-GND Studio YD RP2040
  • VCC-GND YD-ESP32-S3 (N16R8)
  • VCC-GND YD-ESP32-S3 (N8R8)
  • VIDI X V1.1
  • W5100S-EVB-Pico
  • W5100S-EVB-Pico2
  • W5500-EVB-Pico
  • W5500-EVB-Pico2
  • WK-50 Trackball Keyboard
  • Waveshare ESP32-C6 LCD 1.47
  • Waveshare ESP32-S2-Pico
  • Waveshare ESP32-S2-Pico-LCD
  • Waveshare ESP32-S3 LCD 1.47
  • Waveshare ESP32-S3 Touch LCD 1.47
  • Waveshare ESP32-S3 Touch LCD 2.8
  • Waveshare ESP32-S3-ETH
  • Waveshare ESP32-S3-GEEK
  • Waveshare ESP32-S3-Matrix
  • Waveshare ESP32-S3-Pico
  • Waveshare ESP32-S3-Tiny
  • Waveshare ESP32-S3-Tiny-N8R8
  • Waveshare ESP32-S3-Touch-AMOLED-2.41
  • Waveshare ESP32-S3-Zero
  • Waveshare ESP32S3 LCD 1.28
  • Waveshare ESP32S3 Touch LCD 2
  • Waveshare RP2040-GEEK
  • Waveshare RP2040-LCD-0.96
  • Waveshare RP2040-LCD-1.28
  • Waveshare RP2040-One
  • Waveshare RP2040-PiZero
  • Waveshare RP2040-Plus (16MB)
  • Waveshare RP2040-Plus (4MB)
  • Waveshare RP2040-TOUCH-LCD-1.28
  • Waveshare RP2040-Tiny
  • Waveshare RP2040-Zero
  • Waveshare RP2350-GEEK
  • Waveshare RP2350-LCD-0.96
  • Waveshare RP2350-LCD-1.28
  • Waveshare RP2350-One
  • Waveshare RP2350-Plus
  • Waveshare RP2350-TOUCH-LCD-1.28
  • Waveshare RP2350-Tiny
  • Waveshare RP2350-Zero
  • WeAct ESP32-C6 (4MB)
  • WeAct ESP32-C6 (8MB)
  • WeAct Studio Pico
  • WeAct Studio Pico 16MB
  • WeAct Studio RP2350B Core
  • WeMos LOLIN32 Lite
  • Wemos Lolin C3 Mini
  • Wemos Lolin C3 Pico
  • WisdPi Ardu2040M
  • WisdPi Tiny RP2040
  • Xteink X4
  • Yoto Mini 2024
  • Yoto Player V3
  • cezerio dev ESP32C6
  • nanoESP32-S2 w/Wrover
  • nanoESP32-S2 w/Wroom
  • nullbits Bit-C PRO
  • senseBox MCU-S2 ESP32S2
  • senseBox-eye ESP32S3
  • splitkb.com Liatris
  • sunton_esp32_2432S024C
  • sunton_esp32_2432S028
  • sunton_esp32_2432S032C
  • takayoshiotake Octave RP2040
  • uGame S3
  • uGame22

class audioi2sin.I2SIn(bit_clock: microcontroller.Pin, word_select: microcontroller.Pin, data: microcontroller.Pin, *, main_clock: microcontroller.Pin | None = None, sample_rate: int = 16000, bit_depth: int = 16, output_bit_depth: int | None = None, mono: bool = True, left_justified: bool = False, samples_signed: bool = True)

Record an input I2S audio stream from an external I2S source such as a MEMS microphone.

Create an I2SIn object associated with the given pins. This allows you to record audio signals from an external I2S source (e.g. an I2S MEMS microphone like the SPH0645LM4H or INMP441).

The pin signature mirrors audiobusio.I2SOut so users can swap classes; recording parameters mirror audiobusio.PDMIn.

Parameters:
  • bit_clock (Pin) – The bit clock (or serial clock) pin

  • word_select (Pin) – The word select (or left/right clock) pin

  • data (Pin) – The data input pin

  • main_clock (Pin) – The main clock pin. Not all ports support this.

  • sample_rate (int) – Target sample rate of the resulting samples. Check sample_rate for actual value.

  • bit_depth (int) –

    Number of bits per sample on the I2S bus. Must be 8, 16, 24, or 32. 8-bit only supported on espressif. The destination buffer typecode is determined by output_bit_depth (or bit_depth when output_bit_depth is None):

    samples_signed

    output_bit_depth

    Required typecode(s)

    True

    24 or 32

    'i'

    True

    16

    'h'

    True

    8

    'b' or BYTEARRAY

    False

    24 or 32

    'I'

    False

    16

    'H'

    False

    8

    'B' or BYTEARRAY

    Note that 24-bit samples from mics like the SPH0645LM4H / INMP441 are transported in 32-bit slots, so use bit_depth=32 and an 'I' buffer.

  • output_bit_depth (int) – If set, recorded samples are rescaled from bit_depth to this width before being written to the destination buffer (8, 16, 24, or 32). Widening bit-replicates so full-scale input maps to full-scale output (e.g. 16-bit 0xFFFF -> 24-bit 0xFFFFFF); narrowing arithmetic-shifts the value right (sign-preserving when samples_signed is True). When None (the default) the destination buffer holds samples at bit_depth (a 24-bit sample still occupies a 32-bit 'i'/'I' slot, sign-extended without rescaling).

  • mono (bool) – True when capturing a single channel of audio, captures two channels otherwise.

  • left_justified (bool) – True when data bits are aligned with the word select clock. False when they are shifted by one to match classic I2S protocol. Set True for mics like the SPH0645LM4H.

  • samples_signed (bool) – Samples are signed (True) or unsigned (False). I2S mics deliver signed two’s-complement PCM natively; set False to have the recorded samples converted to unsigned PCM (the top/sign bit is flipped, matching the WAV convention for unsigned samples).

Example, recording 16-bit mono samples from an INMP441:

import array
import audioi2sin
import board

buf = array.array("h", [0] * 16000)
with audioi2sin.I2SIn(board.D9, board.D10, board.D11,
                       sample_rate=16000, bit_depth=16) as mic:
    mic.record(buf, len(buf))
deinit() None

Deinitialises the I2SIn and releases any hardware resources for reuse.

__enter__() I2SIn

No-op used by Context Managers.

__exit__() None

Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.

record(destination: circuitpython_typing.WriteableBuffer, destination_length: int) int

Records destination_length samples to destination. This is blocking.

Returns:

The number of samples recorded. If this is less than destination_length, some samples were missed due to processing time.

sample_rate: int

The actual sample rate of the recording. This may not match the constructed sample rate due to internal clock limitations.

bit_depth: int

The actual bit depth of the recording. (read-only)

output_bit_depth: int

The bit depth of samples written to the destination buffer. Equals bit_depth when output_bit_depth was not supplied (or was None) at construction time. (read-only)

samples_signed: bool

True if recorded samples are signed PCM, False for unsigned. (read-only)