Last active
April 28, 2018 07:28
-
-
Save nbogie/4b2e68e1e4217862b358f232b9c38ece to your computer and use it in GitHub Desktop.
neill's microbit play raw audio file - first draft
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
from microbit import display, sleep, button_a | |
import audio | |
def frames_from_file(sndfile, frame): | |
while(sndfile.readinto(frame, 32) > 0): | |
yield frame | |
def play_snd(fname): | |
frame = audio.AudioFrame() | |
with open(fname, 'rb') as sndfile: | |
audio.play(frames_from_file(sndfile, frame),wait=False) | |
sleep(1000) | |
audio.stop() | |
del frame | |
display.show('r') | |
while True: | |
if button_a.is_pressed(): | |
play_snd('clip.raw') | |
sleep(200) | |
Here's another one that triggers on receiving a radio message https://gist.github.com/nbogie/0731380a4b5be26cbed45133d59b38cc
I've also improved it to wait the correct amount of time before closing the audio.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issues: