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

Feature: Turn microphone off when not in use #97

Closed
microbit-mark opened this issue Apr 29, 2021 · 10 comments
Closed

Feature: Turn microphone off when not in use #97

microbit-mark opened this issue Apr 29, 2021 · 10 comments
Assignees
Labels
enhancement New feature or request p1
Milestone

Comments

@microbit-mark
Copy link
Collaborator

microbit-mark commented Apr 29, 2021

From support ticket #44785 and #46485

When the microphone is used as part of a program, the LED is lit to signify that it is listening and it remains on for that program.

It may be the case that someone wants to only use the microphone in part of a script. In this Python example, I am only using the microphone functionality when button A is pressed. When it is not pressed, I would expect the microphone to be disabled and as such the LED to turn off.

from microbit import *

soundGraph = Image("11111:"
                    "11111:"
                    "11111:"
                    "11111:"
                    "11111")

while True:
    if button_a.is_pressed():
        display.show(soundGraph * microphone.sound_level())
    else:
        display.show(Image.HAPPY)
@microbit-mark microbit-mark added the enhancement New feature or request label Apr 29, 2021
@microbit-mark microbit-mark changed the title Feature: Turn microphone LED off when not in use Feature: Turn microphone off when not in use Apr 29, 2021
@ukBaz
Copy link

ukBaz commented May 4, 2021

I have also experienced this issue with MakeCode.
My use case was to sample the sound level fairly infrequently and so was looking at this to clearly communicate with users when the microphone is listening/active.
I am also assuming there is some power savings to be had by turning this off when not required.

@Wanderlustcuckoo
Copy link

This is something I have experienced. I've got a program that uses the microphone in one case, but the user can move to other functions that don't use it and the microphone LED stays on all the time. It actually defeats the purpose of the LED if it comes on when people are not being recorded.

@microbit-mark
Copy link
Collaborator Author

People are likely going to want to log sound levels as part of data logging and the mic LED being permanently on will be a drain on battery power. @finneyj This seems like a good feature to fold into the next round of work on the sound APIs if it will benefit data logging too.

@finneyj
Copy link
Contributor

finneyj commented Jun 22, 2021

Fully agree. We just need a policy for what "not in use" means. We need to remember that the only way to turn off the LED is to turn off the microphone entirely - at which point it will likely take a little while to turn back on again and produce an accurate result. Choosing that period of time is therefore important. Also, for applications using streamed data, the microphone should stay enabled until they disconnect from the input stream.

So as a start point, a policy might look a bit like

  • microphone is disabled by default
  • microphone is enable for, say, 200ms every time the volume level is polled, then is automatically disabled.
  • microphone is enabled whenever a streaming interface is connected to it (FFT, audio recorder, ML recogniser), and remains enabled until all such interfaces are disconnected.

@ukBaz
Copy link

ukBaz commented Jun 22, 2021

Is it possible to have a way to manually turn off the microphone? For me the issue was that querying the volume automatically powered the mic but there was then no way for me to turn it off.
Rather than come up with a magic number (e.g. 200ms), an API to power the mic off would be acceptable for my use case. I want to take several readings in a short period then switch off for a long period. Currently there is no API for me to power off the mic.

@finneyj
Copy link
Contributor

finneyj commented Jun 22, 2021

For sure - manual API is totally fine. You can do this in CODAL simply via:

uBit.io.runmic.setDigitalValue(0);

I don't think that's surfaced in the higher level languages though. For kids it's probably a good idea to auto disable after the microphone goes unused for a period of time though - just to lower their barrier to entry. I don't these things are mutually exclusive though - we can do both. Would that cause a problem for you if you also had the manual function @ukBaz?

@ukBaz
Copy link

ukBaz commented Jun 22, 2021

I don't think that's surfaced in the higher level languages though.

I think that is the root of my problem.

I don't these things are mutually exclusive though - we can do both. Would that cause a problem for you if you also had the manual function?

I don't think it would be a problem. My only concern would be as you said "it will likely take a little while to turn back on again and produce an accurate result" so if it turns off too quickly...

For kids it's probably a good idea to auto disable after the microphone goes unused for a period of time though - just to lower their barrier to entry.

I would have thought the current setup is the lowest barrier to entry. If you care about turning off then you are probably at a level to be able to use a manual off. So if I was to express a preference, my vote would be that the auto-off is unnecessary but I can see the pros and cons of both approaches.

Thanks for your discussion on this matter. Very much appreciated.

@finneyj
Copy link
Contributor

finneyj commented Jun 22, 2021

Yes, we'll need to measure and account for any power on delay... that should be abstracted out in a call to read the current volume I think. (i.e. if that call resulted in the device being powered on, it should wait until it's ready before returning a result).

Just having an explicit call to disable the microphone could be an option - one for us to discuss with the MakeCode and micropython teams I think.

Also @JoshuaAHill has been kindly looking to clean up the audio input pipeline and standardize it's use a bit across platforms. Perhaps we could squeeze this feature request into his upcoming PR.

@microbit-carlos
Copy link
Collaborator

@JohnVidler has this been implemented already in the upcoming release?

@microbit-carlos
Copy link
Collaborator

Released with v0.2.37 🎉
@JohnVidler please reopen if that's not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p1
Projects
None yet
Development

No branches or pull requests

6 participants