Skip to content

Commit 13ce4ff

Browse files
authored
Merge pull request #45 from DavidLiu123/main
update AUDIO Tone and AUDIO Stream play example
2 parents cad0d23 + 018ae05 commit 13ce4ff

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

zh-cn/api/QuecPythonClasslib.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3811,6 +3811,144 @@ aud.play(1, 0, 'U:/test.mp3')
38113811

38123812

38133813

3814+
###### 音频流播放
3815+
3816+
> aud.playStream(format, buf)
3817+
3818+
音频流播放,支持mp3、amr和wav格式的音频流播放。
3819+
3820+
* 参数
3821+
3822+
| 参数 | 参数类型 | 参数说明 |
3823+
| ------ | -------- | ------------------------------------------------------------ |
3824+
| format | int | 音频流格式<br/>1- PCM(暂不支持)<br/>2 - WAVPCM<br/>3 - MP3<br/>4 - AMRNB |
3825+
| buf | buf | 音频流内容 |
3826+
3827+
* 返回值
3828+
3829+
播放成功返回整型0;
3830+
3831+
播放失败返回整型-1;
3832+
3833+
3834+
3835+
###### 停止音频流播放
3836+
3837+
> audio_test.stopPlayStream()
3838+
3839+
停止音频流播放
3840+
3841+
* 参数
3842+
3843+
3844+
3845+
* 返回值
3846+
3847+
停止成功返回整型0;
3848+
3849+
停止失败返回整型-1;
3850+
3851+
3852+
- 示例
3853+
3854+
```python
3855+
import audio
3856+
import utime
3857+
3858+
audio_test = audio.Audio(0)
3859+
3860+
size = 10*1024 # 保证一次填充的音频数据足够大以便底层连续播放
3861+
format = 4
3862+
3863+
def play_from_fs():
3864+
file_size = uos.stat("/usr/test.amr")[6] # 获取文件总字节数
3865+
print(file_size)
3866+
with open("/usr/test.amr", "rb")as f:
3867+
while 1:
3868+
b = f.read(size) # read
3869+
if not b:
3870+
break
3871+
audio_test.playStream(format, b)
3872+
utime.sleep_ms(20)
3873+
f.close()
3874+
3875+
3876+
play_from_fs()
3877+
utime.sleep_ms(5000) # 等待播放完成
3878+
audio_test.stopPlayStream() # 停止本次播放以便不影响下次播放
3879+
```
3880+
3881+
3882+
3883+
###### Tone音播放
3884+
3885+
支持平台EC600U/EC200U/EC600N/EC800N
3886+
3887+
> aud.aud_tone_play(tone, time)
3888+
3889+
播放tone音,播放一段时间(time)后自动停止播放
3890+
3891+
* 参数
3892+
3893+
| 参数 | 参数类型 | 参数说明 |
3894+
| ---- | -------- | ------------------------------------------------------------ |
3895+
| tone | int | tone类型<br/>0~15- 按键音(0~9、A、B、C、D、#、*)(仅EC600U/EC200U平台支持)<br/>16 - 拨号音,(注:EC600N/EC800N平台为连续的tone音,而EC600U/EC200U平台是播放、停顿交替的tone音)<br/>17 - busy(仅EC600U/EC200U平台支持)<br/>18- radio ack(仅EC600U/EC200U平台支持)<br/>19- call drop(仅EC600U/EC200U平台支持)<br/>20- special information(仅EC600U/EC200U平台支持)<br/>21- call waiting(仅EC600U/EC200U平台支持)<br/>22- ringing(仅EC600U/EC200U平台支持) |
3896+
| time | int | 播放时长,单位ms<br/>0 - 不停止一直播放,只能调用aud.aud_tone_play_stop()接口才能停止(仅EC600N/EC800N平台支持,EC600U/EC200U平台填0则无动作)<br/>大于0 - 播放时长time ms |
3897+
3898+
* 返回值
3899+
3900+
播放成功返回整型0;
3901+
3902+
播放失败返回整型-1;
3903+
3904+
3905+
3906+
###### 停止Tone音播放
3907+
3908+
仅EC600N/EC800N平台支持
3909+
3910+
> aud.aud_tone_play_stop()
3911+
3912+
主动停止播放tone音
3913+
3914+
* 参数
3915+
3916+
3917+
3918+
* 返回值
3919+
3920+
停止成功返回整型0;
3921+
3922+
停止失败返回整型-1;
3923+
3924+
3925+
3926+
3927+
- 示例
3928+
3929+
```python
3930+
import audio
3931+
import utime
3932+
3933+
aud = audio.Audio(0)
3934+
3935+
# EC600U/EC200U平台
3936+
def dial_play_ec600u():
3937+
aud.aud_tone_play(16, 5000)
3938+
3939+
# EC600N/EC800N平台
3940+
def dial_play_ec600n():
3941+
for i in range(0,20):
3942+
aud.aud_tone_play(16, 1000)
3943+
utime.sleep(2)
3944+
aud.aud_tone_play_stop()
3945+
3946+
# dial_play_ec600n()
3947+
dial_play_ec600u()
3948+
```
3949+
3950+
3951+
38143952
##### Record
38153953

38163954
注意:BC25PA平台不支持此模块。

0 commit comments

Comments
 (0)