Skip to content

Instantly share code, notes, and snippets.

@nbogie
Last active April 28, 2018 07:28
Show Gist options
  • Save nbogie/4b2e68e1e4217862b358f232b9c38ece to your computer and use it in GitHub Desktop.
Save nbogie/4b2e68e1e4217862b358f232b9c38ece to your computer and use it in GitHub Desktop.
neill's microbit play raw audio file - first draft
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)
@nbogie
Copy link
Author

nbogie commented Apr 25, 2018

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