WaveFile
– Load a wave file for audio playback¶
A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must be 8 bit unsigned or 16 bit signed.
-
class
audioio.
WaveFile
(filename)¶ Load a .wav file for playback with
audioio.AudioOut
oraudiobusio.I2SOut
.Parameters: file (bytes-like) – Already opened wave file Playing a wave file from flash:
import board import audioio import digitalio # Required for CircuitPlayground Express speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) speaker_enable.switch_to_output(value=True) data = open("cplay-5.1-16bit-16khz.wav", "rb") wav = audioio.WaveFile(data) a = audioio.AudioOut(board.A0) print("playing") a.play(wav) while a.playing: pass print("stopped")
-
deinit
()¶ Deinitialises the WaveFile and releases all memory resources for reuse.
-
__enter__
()¶ No-op used by Context Managers.
-
__exit__
()¶ Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.
-
sample_rate
¶ 32 bit value that dictates how quickly samples are loaded into the DAC in Hertz (cycles per second). When the sample is looped, this can change the pitch output without changing the underlying sample.
-