diff --git a/docs/API_reference/zh/QuecPython_classlib/audio.Audio.md b/docs/API_reference/zh/QuecPython_classlib/audio.Audio.md index 00793996d6264ca26616b8f03ef45d63d620e67f..0ee806e55acec1d87397e1abc3814c1957ecb18e 100644 --- a/docs/API_reference/zh/QuecPython_classlib/audio.Audio.md +++ b/docs/API_reference/zh/QuecPython_classlib/audio.Audio.md @@ -4,53 +4,6 @@ > 目前支持型号:EC600N系列、EC800N系列、EC600M-CN(LA、LE)、EC800M-CN(LA、LE、GA)、EC600U系列、EC200U系列、EG912U、EG915U、EG915N-EUAG。 -**示例:** - -```python -# -*- coding: UTF-8 -*- -import audio -from machine import Pin -import utime -import uos - -def audio_cb(event): - if event == 0: - print('audio-play start.') - elif event == 7: - print('audio-play finish.') - -aud = audio.Audio(0) -aud.setCallback(audio_cb) -# 设置pa -aud.set_pa(Pin.GPIO15,2) -# 播放MP3 -aud.play(2, 1, 'U:/music.mp3') -utime.sleep(5) -aud.stop() - -# 音频流播放 -size = 10*1024 # 保证一次填充的音频数据足够大以便底层连续播放 -format = 4 - -def play_from_fs(): - file_size = uos.stat("/usr/test.amr")[6] # 获取文件总字节数 - print(file_size) - with open("/usr/test.amr", "rb")as f: - while 1: - b = f.read(size) # read - if not b: - break - aud.playStream(format, b) - utime.sleep_ms(20) - - -play_from_fs() -# 等待播放完成 -utime.sleep_ms(5000) -# 停止本次播放以便不影响下次播放 -aud.stopPlayStream() -``` - ## 构造函数 ### `audio.Audio` @@ -291,4 +244,51 @@ Audio.aud_tone_play_stop() **返回值描述:** -`0` 表示停止播放成功,`-1`表示停止播放失败。 \ No newline at end of file +`0` 表示停止播放成功,`-1`表示停止播放失败。 + +**示例:** + +```python +# -*- coding: UTF-8 -*- +import audio +from machine import Pin +import utime +import uos + +def audio_cb(event): + if event == 0: + print('audio-play start.') + elif event == 7: + print('audio-play finish.') + +aud = audio.Audio(0) +aud.setCallback(audio_cb) +# 设置pa +aud.set_pa(Pin.GPIO15,2) +# 播放MP3 +aud.play(2, 1, 'U:/music.mp3') +utime.sleep(5) +aud.stop() + +# 音频流播放 +size = 10*1024 # 保证一次填充的音频数据足够大以便底层连续播放 +format = 4 + +def play_from_fs(): + file_size = uos.stat("/usr/test.amr")[6] # 获取文件总字节数 + print(file_size) + with open("/usr/test.amr", "rb")as f: + while 1: + b = f.read(size) # read + if not b: + break + aud.playStream(format, b) + utime.sleep_ms(20) + + +play_from_fs() +# 等待播放完成 +utime.sleep_ms(5000) +# 停止本次播放以便不影响下次播放 +aud.stopPlayStream() +``` diff --git a/docs/API_reference/zh/QuecPython_classlib/audio.Record.md b/docs/API_reference/zh/QuecPython_classlib/audio.Record.md index 5fa1bebf17fd370081184554e4a05d69a69943a0..e11f26b9501c5c648f89b48beb9d87755e232eaa 100644 --- a/docs/API_reference/zh/QuecPython_classlib/audio.Record.md +++ b/docs/API_reference/zh/QuecPython_classlib/audio.Record.md @@ -6,52 +6,6 @@ > 目前支持型号:EC600N系列、EC800N系列、EC600M-CN(LA、LE)、EC800M-CN(LA、LE、GA)、EC600U系列、EC200U系列、EG912U、EG915U、EG915N-EUAG。 -**示例:** - -```python -# -*- coding: UTF-8 -*- -import utime -import audio -from machine import Pin - - -flag = 1 -''' -外接喇叭播放录音文件,参数选择0 -''' -aud = audio.Audio(0) -tts = audio.TTS(0) - -aud.setVolume(11) - -def record_callback(args): - global flag - print('file_name:{}'.format(args[0])) - print('file_size:{}'.format(args[1])) - print('record_sta:{}'.format(args[2])) - - record_sta = args[2] - if record_sta == 3: - print('The recording is over, play it') - tts.play(1, 0, 2, '录音结束,准备播放录音文件') - aud.play(1, 0, record.getFilePath('recordfile.wav')) - flag = 0 - elif record_sta == -1: - print('The recording failure.') - tts.play(1, 0, 2, '录音失败') - flag = 0 - -record = audio.Record() -record.end_callback(record_callback) -record.start('recordfile.wav', 10) - -while 1: - if flag: - utime.sleep_ms(200) - else: - break -``` - ## 构造函数 ### `audio.Record` @@ -382,4 +336,50 @@ Record.stream_read(read_buf, len) ### `Record.AMRNB` -amr 格式。 \ No newline at end of file +amr 格式。 + +**示例:** + +```python +# -*- coding: UTF-8 -*- +import utime +import audio +from machine import Pin + + +flag = 1 +''' +外接喇叭播放录音文件,参数选择0 +''' +aud = audio.Audio(0) +tts = audio.TTS(0) + +aud.setVolume(11) + +def record_callback(args): + global flag + print('file_name:{}'.format(args[0])) + print('file_size:{}'.format(args[1])) + print('record_sta:{}'.format(args[2])) + + record_sta = args[2] + if record_sta == 3: + print('The recording is over, play it') + tts.play(1, 0, 2, '录音结束,准备播放录音文件') + aud.play(1, 0, record.getFilePath('recordfile.wav')) + flag = 0 + elif record_sta == -1: + print('The recording failure.') + tts.play(1, 0, 2, '录音失败') + flag = 0 + +record = audio.Record() +record.end_callback(record_callback) +record.start('recordfile.wav', 10) + +while 1: + if flag: + utime.sleep_ms(200) + else: + break +``` diff --git a/docs/API_reference/zh/QuecPython_classlib/audio.TTS.md b/docs/API_reference/zh/QuecPython_classlib/audio.TTS.md index e91488aae4add58b7bc18ddadbf317835a46ef8a..922b79b8c9b275afb0f439f2f3b0488282b26087 100644 --- a/docs/API_reference/zh/QuecPython_classlib/audio.TTS.md +++ b/docs/API_reference/zh/QuecPython_classlib/audio.TTS.md @@ -6,52 +6,6 @@ > 目前支持型号:EC600N系列、EC800N系列、EC600M-CN(LA、LE)、EC800M-CN(LA、LE、GA)、EC600U-CN系列、EC200U-CN系列。 -**示例:** - -```python -# -*- coding: UTF-8 -*- -import log -from audio import TTS -import utime - - -# 设置日志输出级别 -log.basicConfig(level=log.INFO) -tts_Log = log.getLogger("TTS") - -#定义回调函数 -def UsrFunc(event): - if event == 2: - print("开始播放") - elif event == 3: - print("停止播放") - elif event == 4: - print("播放完成") - -if __name__ == '__main__': - # 参数1:device (0:听筒,1:耳机,2:喇叭) - tts = TTS(0) - - #注册用户回调函数 - tts.setCallback(UsrFunc) - - # 获取当前播放音量大小 - volume_num = tts.getVolume() - tts_Log.info("Current TTS volume is %d" %volume_num) - - # 设置音量为6 - volume_num = 6 - tts.setVolume(volume_num) - - # 参数1:优先级 (0-4) - # 参数2:打断模式,0表示不允许被打断,1表示允许被打断 - # 参数3:模式 低四位:(1:UNICODE16(Size end conversion) 2:UTF-8 3:UNICODE16(Don't convert)),高四位:wtts_enable,wtts_ul_enable, wtts_dl_enable - # 参数4:数据字符串 (待播放字符串) - tts.play(1, 1, 2, 'QuecPython') # 执行播放 - tts.play(1,1,tts.wtts_enable|tts.wtts_ul_enable|2, '12345') - tts.close() # 关闭TTS功能 -``` - ## 构造函数 ### `audio.TTS` @@ -406,4 +360,50 @@ TTS.getState() **返回值描述:** -`0` 表示当前无tts播放,`-1`表示当前有tts正在播放。 \ No newline at end of file +`0` 表示当前无tts播放,`-1`表示当前有tts正在播放。 + +**示例:** + +```python +# -*- coding: UTF-8 -*- +import log +from audio import TTS +import utime + + +# 设置日志输出级别 +log.basicConfig(level=log.INFO) +tts_Log = log.getLogger("TTS") + +#定义回调函数 +def UsrFunc(event): + if event == 2: + print("开始播放") + elif event == 3: + print("停止播放") + elif event == 4: + print("播放完成") + +if __name__ == '__main__': + # 参数1:device (0:听筒,1:耳机,2:喇叭) + tts = TTS(0) + + #注册用户回调函数 + tts.setCallback(UsrFunc) + + # 获取当前播放音量大小 + volume_num = tts.getVolume() + tts_Log.info("Current TTS volume is %d" %volume_num) + + # 设置音量为6 + volume_num = 6 + tts.setVolume(volume_num) + + # 参数1:优先级 (0-4) + # 参数2:打断模式,0表示不允许被打断,1表示允许被打断 + # 参数3:模式 低四位:(1:UNICODE16(Size end conversion) 2:UTF-8 3:UNICODE16(Don't convert)),高四位:wtts_enable,wtts_ul_enable, wtts_dl_enable + # 参数4:数据字符串 (待播放字符串) + tts.play(1, 1, 2, 'QuecPython') # 执行播放 + tts.play(1,1,tts.wtts_enable|tts.wtts_ul_enable|2, '12345') + tts.close() # 关闭TTS功能 +``` diff --git a/docs/API_reference/zh/QuecPython_classlib/camera.CamCapture.md b/docs/API_reference/zh/QuecPython_classlib/camera.CamCapture.md index e226d4deae47e317565494daeba95059888918ae..4144b74a2de875d52af50b27f1cdb1b507fe6dc5 100644 --- a/docs/API_reference/zh/QuecPython_classlib/camera.CamCapture.md +++ b/docs/API_reference/zh/QuecPython_classlib/camera.CamCapture.md @@ -4,40 +4,6 @@ > 使用该功能前,需要初始化LCD。 -**示例:** - -```python -from machine import LCD -import camera - -# 先参照machine.LCD类的内容正确初始化LCD对象 -# lcd = LCD() -# lcd.lcd_init(*args) - -# 定义回调函数 -def cam_callback(para): - # para[0] 拍照结果 0:成功 其它:失败 - print("cam capture result is ", para[0]) - # para[1] 保存图片的名称 - if para[0] == 0: - print("image {} has been saved".format(para[1])) - -# 创建camCapture对象 -cam = camera.camCapture(0,640,480,1,240,240) - -# 使能照相机功能 -cam.open() - -# 设置回调函数 -cam.callback(cam_callback) - -# 拍照并保存 -cam.start(240, 240, "image_demo") - -# 关闭照相机功能 -cam.close() -``` - ## 构造函数 ### `camera.camCapture` @@ -143,4 +109,3 @@ def cb(result_list): **返回值描述:** `0` 表示设置拍照回调函数成功,其他表示设置拍照回调函数失败。 - diff --git a/docs/API_reference/zh/QuecPython_classlib/camera.CamDecoder.md b/docs/API_reference/zh/QuecPython_classlib/camera.CamDecoder.md index f5a02d45bbb315ecefe40ddf37a4aac03f16e304..de2e6e0a41865b79725c3b48bf37d99fde84d554 100644 --- a/docs/API_reference/zh/QuecPython_classlib/camera.CamDecoder.md +++ b/docs/API_reference/zh/QuecPython_classlib/camera.CamDecoder.md @@ -4,45 +4,6 @@ > 如果开启预览,需要先初始化LCD。 -**示例:** - -```python -from machine import LCD -import camera - -# 如果开启预览,先参照machine.LCD类的内容正确初始化LCD对象 -# lcd = LCD() -# lcd.lcd_init(*args) - -# 如果不开启预览,可不初始化LCD对象 - -# 定义回调函数 -def scan_callback(para): - # para[0] 识别结果 0:成功 其它:失败 - print("scan result is ", para[0]) - # para[1] 识别内容 - if para[0] == 0: - print("decode content is ", para[1]) - -# 创建camScandecode对象 -scaner = camera.camScandecode(0,1,640,480,1,240,240) - -# 开启摄像头扫码功能 -scaner.open() - -# 注册扫码回调函数 -scaner.callback(scan_callback) - -# 开始扫码 -scaner.start() - -# 结束扫码 -scaner.stop() - -# 关闭摄像头扫码功能 -scaner.close() -``` - ## 构造函数 ### `camera.camScandecode` diff --git a/docs/API_reference/zh/QuecPython_classlib/camera.CamPreview.md b/docs/API_reference/zh/QuecPython_classlib/camera.CamPreview.md index c48dfe58da05043b2866b6aef04cf9e8c3afdc48..d2ddf52f6d0cf7cde3179ae02e80fb69acec1ab8 100644 --- a/docs/API_reference/zh/QuecPython_classlib/camera.CamPreview.md +++ b/docs/API_reference/zh/QuecPython_classlib/camera.CamPreview.md @@ -6,26 +6,6 @@ > 使用该功能前,需要初始化LCD。 -**示例:** - -```python -from machine import LCD -import camera - -# 先参照machine.LCD类的内容正确初始化LCD对象 -# lcd = LCD() -# lcd.lcd_init(*args) - -# 创建camPreview对象 -preview = camera.camPreview(0,640,480,240,240,1) - -# 开启摄像头预览 -preview.open() - -# 关闭摄像头预览 -preview.close() -``` - ## 构造函数 ### `camera.camPreview` diff --git a/docs/API_reference/zh/QuecPython_classlib/camera.md b/docs/API_reference/zh/QuecPython_classlib/camera.md index f7c50173b677a9de315a846e3112c7aae741f8f2..076bb7e7ba2441aba1fca446a79aec3f9192a418 100644 --- a/docs/API_reference/zh/QuecPython_classlib/camera.md +++ b/docs/API_reference/zh/QuecPython_classlib/camera.md @@ -6,54 +6,6 @@ > > 如果需要预览,在初始化camera对象之前,请先参照[machine模块的lcd类的内容](machine.LCD.md)正确初始化LCD对象。 -**示例:** - -```python -# -*- coding: UTF-8 -*- -from machine import LCD -import camera - -# 如果需要预览,请先参照machine模块的lcd类的内容正确初始化LCD对象 -# lcd = LCD() -# lcd.lcd_init(*args) - -# 摄像头预览功能 -preview = camera.camPreview(0,640,480,240,240,1) -preview.open() -preview.close() - -# 摄像头扫码功能 -def scan_callback(para): - # para[0] 识别结果 0:成功 其它:失败 - print("scan result is ", para[0]) - # para[1] 识别内容 - if para[0] == 0: - print("decode content is ", para[1]) - -scaner = camera.camScandecode(0,1,640,480,1,240,240) -scaner.open() -scaner.callback(scan_callback) -scaner.start() -scaner.stop() -scaner.close() - -# 摄像头照相功能 -def cam_callback(para): - # para[0] 拍照结果 0:成功 其它:失败 - print("cam capture result is ", para[0]) - # para[1] 保存图片的名称 - if para[0] == 0: - print("image {} has been saved".format(para[1])) - -cam = camera.camCapture(0,640,480,1,240,240) -cam.open() -cam.callback(cam_callback) -cam.start(240, 240, "image_demo") -cam.close() -``` - - - ## Classes - [class CamPreview - 摄像头预览](./camera.CamPreview.md) diff --git a/docs/API_reference/zh/QuecPython_classlib/machine.LCD.md b/docs/API_reference/zh/QuecPython_classlib/machine.LCD.md index d2e8f916402da63282e54abbb674192e0e9746c1..3fc7465505b3f6448807c8a37158667109a390ee 100644 --- a/docs/API_reference/zh/QuecPython_classlib/machine.LCD.md +++ b/docs/API_reference/zh/QuecPython_classlib/machine.LCD.md @@ -45,10 +45,10 @@ lcd.lcd_init(lcd_init_data, lcd_width, lcd_hight, lcd_clk, data_line, line_num, | 参数 | 类型 | 说明 | | ------------------ | --------- | ------------------------------------------------------------ | -| lcd_init_data | bytearray | LCD 的初始化配置命令 | -| lcd_width | int | LCD 屏幕的宽度,宽度不超过 500 | -| lcd_hight | int | LCD 屏幕的高度,高度不超过 500 | -| lcd_clk | int | LCD SPI 时钟,SPI 时钟为 6.5K/13K/26K/52K | +| lcd_init_data | bytearray | LCD 初始化的配置命令 | +| lcd_width | int | LCD 屏幕的宽度,宽度不超过 500像素 | +| lcd_hight | int | LCD 屏幕的高度,高度不超过 500像素 | +| lcd_clk | int | LCD SPI 时钟频率:
6500: 6.5MHz
13000:13MHz
26000:26MHz
52000:52MHz | | data_line | int | 数据线数,参数值为 1 和 2 | | line_num | int | 线的数量,参数值为 3 和 4 | | lcd_type | int | 屏幕类型,0 - rgb;1 - fstn | @@ -79,9 +79,9 @@ lcd.lcd_init(lcd_init_data, lcd_width, lcd_hight, lcd_clk, data_line, line_num, | 参数 | 类型 | 说明 | | ------------------ | --------- | ------------------------------------------------------------ | -| lcd_init_data | bytearray | LCD 的配置命令 | -| lcd_width | int | LCD 屏幕的宽度,宽度不超过 500 | -| lcd_hight | int | LCD 屏幕的高度,高度不超过 500 | +| lcd_init_data | bytearray | LCD 初始化的配置命令 | +| lcd_width | int | LCD 屏幕的宽度,宽度不超过 500像素 | +| lcd_hight | int | LCD 屏幕的高度,高度不超过 500像素 | | lcd_clk | int | SPI 时钟,见machine.SPI 创建SPI对象参数说明clk | | data_line | int | 数据线数,参数值为 1 和 2 | | line_num | int | 线的数量,参数值为 3 和 4 | @@ -127,8 +127,8 @@ lcd.mipi_init(initbuf, **kwargs) | 参数 | 类型 | 说明 | | ----------- | --------- | ------------------------------------------------------------ | | initbuf | bytearray | 必传,传入 MIPI 的配置命令 | -| width | int | 缺省值:480,屏幕的宽度,示例:width=400 | -| hight | int | 缺省值:854,屏幕的高度,示例:hight=800 | +| width | int | 缺省值:480,屏幕的宽度,单位像素,示例:width=400 | +| hight | int | 缺省值:854,屏幕的高度,单位像素,示例:hight=800 | | bpp | int | 缺省值:16,像素深度 | | DataLane | int | 缺省值:2,数据通道 | | MipiMode | int | 缺省值:0
模式:
0:DSI_VIDEO_MODE
1:DSI_CMD_MODE | @@ -276,7 +276,7 @@ lcd.lcd_brightness(level) lcd.lcd_display_on() ``` -该方法用于打开屏显 ,调用此接口后调用 lcd.lcd_init()中的 lcd_display_on 回调。 +此接口用于向LCD发送lcd_display_on指令来打开屏幕显示,请确保lcd初始化的时候传入了正确的lcd_display_on指令。 **返回值描述:** @@ -288,7 +288,7 @@ lcd.lcd_display_on() lcd.lcd_display_off() ``` -该方法用于关闭屏显 ,调用此接口后调用 lcd.lcd_init()中的 lcd_display_off 回调。 +此接口用于向LCD发送lcd_display_off 指令来关闭屏幕显示,请确保lcd初始化的时候传入了正确的lcd_display_off 指令。 **返回值描述:**