Mic
Mic 用于控制主机内部集成的按键。以下是主机的 Mic 支持详细:
Controller |
SPM1423 |
ES7210 |
|---|---|---|
AtomS3 |
||
AtomS3 Lite |
||
AtomS3U |
✔ |
|
StampS3 |
||
CoreS3 |
✔ |
|
Core2 |
✔ |
|
TOUGH |
Micropython Example:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8import time 9 10 11label0 = None 12 13 14rec_data = None 15 16 17def setup(): 18 global label0, rec_data 19 20 M5.begin() 21 Widgets.fillScreen(0x222222) 22 label0 = Widgets.Label("label0", 123, 58, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 23 24 Speaker.begin() 25 Speaker.setVolumePercentage(1) 26 Speaker.end() 27 Mic.begin() 28 rec_data = bytearray(8000 * 5) 29 label0.setText(str("rec...")) 30 Mic.record(rec_data, 8000, False) 31 while Mic.isRecording(): 32 time.sleep_ms(500) 33 Mic.end() 34 Speaker.begin() 35 label0.setText(str("play...")) 36 Speaker.playRaw(rec_data, 8000) 37 while Speaker.isPlaying(): 38 time.sleep_ms(500) 39 label0.setText(str("done")) 40 41 42def loop(): 43 global label0, rec_data 44 M5.update() 45 46 47if __name__ == "__main__": 48 try: 49 setup() 50 while True: 51 loop() 52 except (Exception, KeyboardInterrupt) as e: 53 try: 54 from utility import print_error_msg 55 56 print_error_msg(e) 57 except ImportError: 58 print("please update to latest firmware")
UIFLOW2 Example:
class Mic
重要
Mic Class的方法重度依赖 M5.begin() 和
M5.update() 。
调用 Mic 对象的所有方法,需要放在 M5.begin() 的后面,并在 主循环中调用
M5.update() 。
Methods
- Mic.config([cfg:mic_config_t])
- Mic.config('param')
- Mic.config(param=value)
获取或者设置 Mic 对象的参数。
当不传入任何参数时,会返回
mic_config_t的对象。当传入一个mic_config_t的对象, Mic 会设置 Mic 的所有支持的参数。当传入下表中的参数, Mic 会对传入的参数进行获取或者设置。
以下是支持的参数:
Parameter
Type
Description
pin_data_in
(integer)
I2S 的串行数据线,用二进制补码表示的音频数据。
pin_bck
(integer)
I2S 的串行时钟线,对应数字音频的每一位数据。
pin_mck
(integer)
I2S 的主时钟线。一般为了使系统间能够更好地同步时增加MCLK信号,MCLK的频率 = 256 * 采样频率。
pin_ws
(integer)
I2S 的帧时钟,用于切换左右声道的数据。
sample_rate
(integer)
输入音频的目标采样率。
stereo
(boolean)
使用双声道输出。
over_sampling
(integer)
求平均值的采样次数。
magnification
(integer)
输入值的乘数。
noise_filter_level
(integer)
先前值的系数,用于噪声过滤。
use_adc
(boolean)
使用模拟输入麦克风(仅需要 pin_data_in )。
dma_buf_len
(integer)
I2S 的DMA缓冲区长度。
dma_buf_count
(integer)
I2S 的DMA缓冲区数量。
task_priority
(integer)
后台任务优先级。
task_pinned_core
(integer)
后台任务使用的CPU。
i2s_port
(integer)
I2S端口。
UIFLOW2:
读取属性:
Python:
Mic.config("pin_data_in")


设置属性:
Python:
Mic.config(pin_data_in=1)


- Mic.isRecording() int
获取 Mic 是否处于录音状态, 返回int类型。
返回值:
0=not recording
1=recording (There’s room in the queue)
2=recording (There’s no room in the queue.)
UIFLOW2:







