- MicroPython Cookbook
- Marwan Alsabbagh
- 104字
- 2021-06-24 14:28:14
How it works...
The first line of code imports the Circuit Playground Express library. The cpx object exposes a property method called play_file. This method accepts one argument in the .wav filename, which will be played on the onboard speaker.
The audio file should be in WAV file format; it should have a sample rate of 22,050 kHz, be 16-bit format, and have a mono channel of audio. This method will open the audio file and start the playback on the speaker. It will also keep polling the audio device until the playback is finished and will return once the audio playback has completed.