-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
998 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
config BUILD_WITH_MAIXPY | ||
bool "Used to indicate that maixpy is compiling" | ||
default y | ||
help | ||
application code can use this macro to do special process when compiling MaixPy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
title: MaixPy Playback Audio | ||
update: | ||
- date: 2024-05-20 | ||
author: lxowalle | ||
version: 1.0.0 | ||
content: Initial document | ||
--- | ||
|
||
## Introduction | ||
|
||
This document provides instructions on how to play audio | ||
|
||
|
||
## How to use | ||
|
||
### Hardware operation | ||
|
||
![image-20240520134637905](../../../static/image/maixcam_hardware_back.png) | ||
|
||
The `MaixCAM` does not have a built-in speaker, so you will need to solder a `1W` speaker yourself. The pins for soldering the speaker are shown in the diagram above on the `VOP` and `VON` pins corresponding to the Speaker. | ||
|
||
Note: If the `MaixCAM` has copper posts attached to these pins, they can be soldered directly to the posts, or on the other side of the board for aesthetic reasons. | ||
|
||
### Code | ||
|
||
Method of playing a PCM file | ||
|
||
```python | ||
from maix import audio, time, app | ||
|
||
p = audio.Player() | ||
|
||
with open('/root/output.pcm', 'rb') as f: | ||
ctx = f.read() | ||
|
||
p.play(bytes(ctx)) | ||
|
||
while not app.need_exit(): | ||
time.sleep_ms(10) | ||
|
||
print("play finish!") | ||
``` | ||
|
||
Steps: | ||
|
||
|
||
1. Import the audio, time and app modules: | ||
|
||
```python | ||
from maix import audio, time, app | ||
``` | ||
|
||
2. Initialize the player: | ||
|
||
```python | ||
p = audio.Player() | ||
``` | ||
- Note that the default sample rate is 48k, the sample format is little-endian format - signed 16-bit, and the sample channel is 1. You can also customise the parameters like this `p = audio.Player(sample_rate=48000, format=audio.Format.FMT_S16_LE, channel = 1)`. So far only tested with sample rate 48000, format `FMT_S16_LE`, and number of sampling channels 1. | ||
|
||
3. Open and playback a PCM file | ||
|
||
```python | ||
with open('/root/output.pcm', 'rb') as f: | ||
ctx = f.read() | ||
|
||
p.play(bytes(ctx)) | ||
|
||
while not app.need_exit(): | ||
time.sleep_ms(10) | ||
``` | ||
- `with open(‘xxx’,‘rb’) as f:` open file `xxx` and get file object `f` | ||
- `ctx = f.read()` reads the contents of the file into `ctx` | ||
- `p.play(bytes(ctx))` plays the audio, `p` is the opened player object, `ctx` is the `PCM` data converted to type bytes | ||
- `time.sleep_ms(10)` Here there is a loop to wait for the playback to complete, as the playback operation is performed asynchronously, and if the program exits early, then it may result in the audio not being played completely. | ||
|
||
4. Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
title: MaixPy Audio Record | ||
update: | ||
- date: 2024-05-20 | ||
author: lxowalle | ||
version: 1.0.0 | ||
content: Initial document | ||
--- | ||
|
||
## Introduction | ||
|
||
This document provides methods for recording | ||
|
||
### How to use | ||
|
||
An example of a recording | ||
|
||
```python | ||
from maix import audio, time, app | ||
|
||
r = audio.Recorder() | ||
r.volume(12) | ||
print("sample_rate:{} format:{} channel:{}".format(r.sample_rate(), r.format(), r.channel())) | ||
|
||
while not app.need_exit(): | ||
data = r.record() | ||
print("data size", len(data)) | ||
|
||
time.sleep_ms(10) | ||
|
||
print("record finish!") | ||
``` | ||
|
||
Steps: | ||
|
||
1. Import the audio, time and app modules: | ||
|
||
```python | ||
from maix import audio, time, app | ||
``` | ||
|
||
2. Initialize Recorder | ||
|
||
```python | ||
r = audio.Recorder() | ||
r.volume(12) | ||
``` | ||
|
||
- Note that the default sample rate is 48k, the sample format is little-endian format - signed 16-bit, and the sample channel is 1. You can also customise the parameters like this `r = audio.Recorder(sample_rate=48000, format=audio.Format.FMT_S16_LE, channel = 1)`. So far only tested with sample rate 48000, format `FMT_S16_LE`, and number of sampling channels 1. | ||
|
||
- `r.volume(12)` is used to set the volume, the volume range is [0,24] | ||
|
||
3. Start recording | ||
|
||
```python | ||
data = r.record() | ||
``` | ||
|
||
- `data` is `bytes` type data in `PCM` format that holds the currently recorded audio. The `PCM` format is set when initialising the `Recorder` object, see step 2. | ||
|
||
4. Done, you can do voice processing on the `PCM` data returned by `r.record()` when doing your own applications. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.