Mic

Mic is used to control the built-in microphone inside the host device. Below is the detailed Mic support for the host:

Controller

SPM1423

ES7210

AtomS3

AtomS3 Lite

AtomS3U

StampS3

CoreS3

Core2

TOUGH

Micropython Example:

pass

UIFLOW2 Example:

pass

class Mic

Important

Methods of the Mic Class heavily rely on M5.begin() M5.begin.svg and M5.update() M5.update.svg.

All calls to methods of Mic objects should be placed after M5.begin() M5.begin.svg, and M5.update() M5.update.svg should be called in the main loop.

Methods

Mic.config([cfg:mic_config_t])
Mic.config('param')
Mic.config(param=value)

Get or set the parameters of the Mic object.

When no parameters are passed, it returns an object of mic_config_t. When a mic_config_t object is passed, Mic sets all supported parameters of the Mic.

When passing parameters from the table below, Mic will get or set the passed parameters.

The following parameters are supported:

Parameter

Type

Description

pin_data_in

(integer)

Serial data line of I2S, representing audio data in binary complement.

pin_bck

(integer)

Serial clock line of I2S, corresponding to each bit of digital audio data.

pin_mck

(integer)

Master clock line of I2S. Generally, to better synchronize between systems, increase the MCLK signal, MCLK frequency = 256 * sampling frequency.

pin_ws

(integer)

Frame clock of I2S, used to switch left and right channel data.

sample_rate

(integer)

Target sampling rate of input audio.

stereo

(boolean)

Use stereo output.

over_sampling

(integer)

Number of times to average the sampling.

magnification

(integer)

Multiplier of the input value.

noise_filter_level

(integer)

Coefficient of the previous value used for noise filtering.

use_adc

(boolean)

Use analog input microphone (only pin_data_in is needed).

dma_buf_len

(integer)

DMA buffer length of I2S.

dma_buf_count

(integer)

Number of DMA buffers of I2S.

task_priority

(integer)

Priority of background tasks.

task_pinned_core

(integer)

CPU used by background tasks.

i2s_port

(integer)

I2S port.

UIFLOW2:

Read property:

Python:

Mic.config("pin_data_in")

config.svg

Set property:

Python:

Mic.config(pin_data_in=1)

config1.svg

Mic.begin() bool

Start the Mic function. Returns True if successful.

UIFLOW2:

begin.svg

Mic.end() bool

Stop the Mic function. Returns True if successful.

UIFLOW2:

end.svg

Mic.isRunning() bool

Check if Mic is running. Returns a boolean value.

UIFLOW2:

isRunning.svg

Mic.isEnabled() bool

Check if Mic is enabled. Returns a boolean value.

UIFLOW2:

isEnabled.svg

Mic.isRecording() int

Check if Mic is recording. Returns an integer value.

Return values:

  • 0=not recording

  • 1=recording (There’s room in the queue)

  • 2=recording (There’s no room in the queue.)

UIFLOW2:

isRecording.svg

Mic.setSampleRate(sample_rate) None

Set the sampling rate. The parameter sample_rate generally includes 8000, 11025, 22050, 32000, 44100.

UIFLOW2:

setSampleRate.svg

Mic.record(rec_data[, rate[, stereo]]) bool

Record audio data.

The parameter rec_data requires passing a buffer. The parameter rate generally includes 8000, 11025, 22050, 32000, 44100, with a default of 8000. The parameter stereo is passed as True or False.

UIFLOW2:

record.svg

class mic_config_t

mic_config_t.pin_data_in: int

Serial data line of I2S, representing audio data in binary complement.

mic_config_t.pin_bck: int

Serial clock line of I2S, corresponding to each bit of digital audio data.

mic_config_t.pin_mck: int

Master clock line of I2S. Generally, to better synchronize between systems, increase the MCLK signal, MCLK frequency = 256 * sampling frequency.

mic_config_t.pin_ws: int

Frame clock of I2S, used to switch left and right channel data.

mic_config_t.sample_rate: int

Target sampling rate of input audio.

mic_config_t.stereo: bool

Use stereo output.

mic_config_t.over_sampling: int

Number of times to average the sampling.

mic_config_t.magnification: int

Multiplier of the input value.

mic_config_t.noise_filter_level: int

Coefficient of the previous value used for noise filtering.

mic_config_t.use_adc: bool

Use analog input microphone (only pin_data_in is needed).

mic_config_t.dma_buf_len: int

DMA buffer length of I2S.

mic_config_t.dma_buf_count: int

Number of DMA buffers of I2S.

mic_config_t.task_priority: int

Priority of background tasks.

mic_config_t.task_pinned_core: int

CPU used by background tasks.

mic_config_t.i2s_port: int

I2S port.