Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audio.stop() and microphone.stop_recording() don't work #180

Closed
microbit-carlos opened this issue Apr 8, 2024 · 4 comments
Closed

audio.stop() and microphone.stop_recording() don't work #180

microbit-carlos opened this issue Apr 8, 2024 · 4 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@microbit-carlos
Copy link
Contributor

microbit-carlos commented Apr 8, 2024

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.

@microbit-carlos microbit-carlos added the bug Something isn't working label Apr 8, 2024
@microbit-carlos microbit-carlos added this to the 2.2.0-beta.1 milestone Apr 8, 2024
dpgeorge added a commit that referenced this issue Apr 30, 2024
@dpgeorge
Copy link
Collaborator

This is not related to the audio-recording branch, it's a bug in the master branch.

Now fixed on master by c143b24

@microbit-carlos
Copy link
Contributor Author

microbit-carlos commented Apr 30, 2024

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()
>>> 

@microbit-carlos microbit-carlos changed the title audio.stop() doesn't work audio.stop() and microphone.stop_recording() don't work Apr 30, 2024
@dpgeorge
Copy link
Collaborator

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.

@microbit-carlos
Copy link
Contributor Author

Oh yes, you are right, brain fart from my side!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants