From 347c5b0251012972aff09950ff3070e7e886ddbe Mon Sep 17 00:00:00 2001 From: "carlos.meng" <7754760+meng_zhengwei@user.noreply.gitee.com> Date: Sat, 14 Jun 2025 20:28:25 +0800 Subject: [PATCH] =?UTF-8?q?docs=20(audio):=20=E5=BD=95=E9=9F=B3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=BD=95=E9=9F=B3=E6=B5=81=E5=8A=9F=E8=83=BD=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=92=8C=E5=B8=B8=E9=87=8F=E6=8F=8F=E8=BF=B0=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BD=95=E9=9F=B3=E6=B5=81=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.修改stream_start接口参数的描述。 2.修改录音常量描述 3.新增stream_stop接口 固件版本: N/A 是否需要文案翻译: 否 --- en/medialib/audio.Record.md | 35 ++++++++++++++---- zh/medialib/audio.Record.md | 71 +++++++++++++++++++++++++++++++++---- 2 files changed, 92 insertions(+), 14 deletions(-) diff --git a/en/medialib/audio.Record.md b/en/medialib/audio.Record.md index 50ae724..821322f 100644 --- a/en/medialib/audio.Record.md +++ b/en/medialib/audio.Record.md @@ -342,13 +342,13 @@ The parameter is passed: no return value if the parameter is correct, and an exc Record.stream_start(format, samplerate, time) ``` -This method starts recording audio streams. Note that when recording an audio stream, read the audio stream timely. Currently, a loop buffer is used. Failure to read the audio stream in time will result in data loss. +This method starts recording audio streams. Note that when recording an audio stream, max cached 8k bytes,read the audio stream timely. Currently, a loop buffer is used. Failure to read the audio stream in time will result in data loss. **Parameter:** -- `format` - Integer type. Audio format. Currently supports AMR format. See constant. -- `samplerate` - Integer type. Sample rate. Currently supports 8000 sps and 16000 sps. -- `time` - Integer type. Recording duration. Unit: second. +- `format` - Integer type. Audio format. See constant. Different module projects can support different audio formats for recording, and the support situation needs to be consulted with Quectel technical personnel. +- `samplerate` - Integer type. Sample rate. Except for MP3 format, it currently supports 8000 sps and 16000 sps, and only supports 22050 sps in MP3 format +- `time` - Integer type. Recording duration. Unit: second. Setting to 0 means continuous recording until stopped using the `Record.stream_stop` interface. **Return Value:** @@ -371,8 +371,29 @@ This method reads the recording stream. Returns the number of bytes actually read for successful execution or -1 if failed. -## Constant +### Record.stream_stop + +```python +Record.stream_stop() +``` + +This method stop the recording stream. + +**Parameter:** -### Record.AMRNB +No parameter. + +**Return Value:** + +Returns the number of bytes actually read for successful execution or -1 if failed. + +## Constant -AMR format. \ No newline at end of file +| Constant | Value | Description | +| ---------------- | ----- | ------------------------------------------------------------ | +| `Record.PCM` | 1 | Record audio data in PCM format. | +| `Record.WAV` | 2 | Record audio data in WAV format, and set the recording time to 0 when recording this format. | +| `Record.MP3` | 3 | Record audio data in MP3 format. | +| `Record.AMRNB` | 4 | Record audio data in AMR-NB format, with a sampling rate set to 8000 sps when recording this format. | +| `Record.AMRWB` | 5 | Record audio data in AMR-WB format, with a sampling rate set to 16000 sps when recording this format. | +| `Record.OGGOPUS` | 11 | Record audio data in OggOpus format. | \ No newline at end of file diff --git a/zh/medialib/audio.Record.md b/zh/medialib/audio.Record.md index dec73c1..0a59527 100644 --- a/zh/medialib/audio.Record.md +++ b/zh/medialib/audio.Record.md @@ -298,13 +298,13 @@ Record.amrEncDtx_enable(on_off) Record.stream_start(format, samplerate, time) ``` -该方法用于开始录音音频流。注意:录制音频流的同时,应及时读取音频流。目前是采用循环buf,不及时读取,会导致数据丢失。 +该方法用于开始录音音频流。注意:录制音频流的同时,应及时读取音频流。目前是采用循环buf,最大缓存8K字节数据,不及时读取,会导致数据丢失。 **参数描述:** -- `format` - 音频格式,int型,目前支持 amr 格式,见常量。 -- `samplerate` - 采样率,int型,目前支持8000 和 16000 。 -- `time` - 录音时长,int型,单位 S (秒)。 +- `format` - 音频格式,int型,见常量。不同的模组项目所能支持录制的音频格式不同,支持情况需咨询移远技术人员。 +- `samplerate` - 采样率,int型,除MP3格式外,目前支持8000 和 16000,MP3格式下只支持22050 。 +- `time` - 录音时长,int型,单位 S (秒),设置为0表示持续录音,直到使用`Record.stream_stop`接口停止。 **返回值描述:** @@ -327,16 +327,38 @@ Record.stream_read(read_buf, len) 成功返回实际读取的字节数,失败返回整型-1。 -## 常量 +### `Record.stream_stop` + +```python +Record.stream_stop() +``` + +该方法用于停止录音流录制。 + +**参数描述** + +无参数。 + +**返回值描述:** + +成功返回实际读取的字节数,失败返回整型-1。 -### `Record.AMRNB` +## 常量 -amr 格式。 +| 常量 | 值 | 说明 | +| ---------------- | ---- | ----------------------------------------------------------- | +| `Record.PCM` | 1 | 录制PCM格式的音频数据 | +| `Record.WAV` | 2 | 录制WAV格式的音频数据,录制该格式时录制时间需设置为`0` | +| `Record.MP3` | 3 | 录制MP3格式的音频数据 | +| `Record.AMRNB` | 4 | 录制AMR-NB格式的音频数据,录制该格式时采样率需设置为`8000` | +| `Record.AMRWB` | 5 | 录制AMR-WB格式的音频数据,录制该格式时采样率需设置为`16000` | +| `Record.OGGOPUS` | 11 | 录制OggOpus格式的音频数据 | **示例:** ```python # -*- coding: UTF-8 -*- +#文件录音 import utime import audio from machine import Pin @@ -378,3 +400,38 @@ while 1: else: break ``` + +```python +# -*- coding: UTF-8 -*- +#录音流 +import audio +''' +外接喇叭播放录音文件,参数选择0 +''' +rec = audio.Record(0) +aud = audio.Audio(0) + +record_time = 10 +buf = bytearray(0) #空buff用来缓存音频 +aud_type = rec.AMRNB + +aud.setVolume(10) + +def stream_rec_cb(para): + global buf + print("para:", para) + if(para[0] == 'stream'): + if(para[2] == 1): + read_buf = bytearray(para[1]) + rec.stream_read(read_buf,para[1]) + buf += read_buf + del read_buf + elif (para[2] == 3): + pass + aud.stopPlayStream() + aud.playStream(aud_type, buf) + +rec.end_callback(stream_rec_cb) +rec.stream_start(aud_type, 8000, record_time) +``` + -- Gitee