Adafruit_Learning_System_Gu.../CircuitPython_Templates/pwm_wav_playback/code.py
2023-03-30 10:07:03 -04:00

28 lines
737 B
Python

# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
CircuitPython PWM Audio Out WAV example
Play a WAV file once.
Remove this line and all of the following docstring content before submitting to the Learn repo.
Update the audio out pin to match the wiring chosen for the microcontroller.
Update the following pin name to a viable pin:
* AUDIO_OUTPUT_PIN
"""
import board
from audiocore import WaveFile
from audiopwmio import PWMAudioOut as AudioOut
audio = AudioOut(board.AUDIO_OUTPUT_PIN)
with open("StreetChicken.wav", "rb") as wave_file:
wave = WaveFile(wave_file)
print("Playing wav file!")
audio.play(wave)
while audio.playing:
pass
print("Done!")