`audio.stop()` and `microphone.stop_recording()` don't work
microbit-carlos opened this issue · 4 comments
Tested with v2.1.2 and the lates recording&playback branch.
audio.stop
doesn't work in this example:
from microbit import *
while True:
if button_a.is_pressed():
audio.play(Sound.HAPPY, wait=False)
# We can see here that the image is shown as soon as the sound starts playing
display.show(Image.HAPPY)
# But the sound plays to completion
audio.stop()
sleep(200)
sleep(100)
display.clear()
Simpler example in REPL (the next prompt >>>
appears before the sound naturally ends playing):
>>> audio.play(Sound.HAPPY, wait=False); audio.stop()
>>> audio.play(Sound.HAPPY, wait=False); sleep(10); audio.stop()
>>>
Replacing the play call with audio.play(audio.SoundEffect(duration=3000), wait=False)
doesn't work either.
This is not related to the audio-recording branch, it's a bug in the master branch.
Now fixed on master by c143b24
Sorry, I forgot to mention that microphone.stop_recording()
didn't work either:
>>> a = microphone.record(4000)
>>> # Recording plays for 4 seconds instead of 1
>>> audio.play(a, wait=False); sleep(1000); microphone.stop_recording()
>>>
I'm not sure what's wrong with the above code. It should play for 4 seconds. The microphone.record()
is synchronous and records for 4 seconds, then the audio.play()
will play the full sample, because microphone.stop_recording()
has no effect on audio playback.
Oh yes, you are right, brain fart from my side!