Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

General Question: Best approach on granting permission to access microphone #1407

Open
inglesuniversal opened this issue May 3, 2022 · 5 comments
Labels

Comments

@inglesuniversal
Copy link

Hello,

What is the best way for an App built with Nativefier to request permission to the user to access the microphone on both MacOS & Windows platforms.

Would this work?

/* Handle Microphone permission */ 
function getLocalStream() {
    navigator.mediaDevices.getUserMedia({video: false, audio: true}).then( stream => {
        window.localStream = stream;
        window.localAudio.srcObject = stream;
        window.localAudio.autoplay = true;
        alert('Microphone has been enabled.')
    }).catch( err => {
        alert("Error:" + err)
    });
}

getLocalStream();
@inglesuniversal
Copy link
Author

UPDATE: Found this very simple App and it works by recognizing the user's voice input from his Microphone (Tested on MacOS 12.3.1

Demo_Aoo

Hope it can help to figure out why all of the sudden Nativefier does not want to recognize voice input, when it worked a few months back using alternate services like MS Azure - Speech

Thanks

@inglesuniversal

This comment was marked as off-topic.

@TheCleric
Copy link
Collaborator

The problem with microphone access is twofold (at least on Mac):

  1. The page you are accessing uses an API that would require access to the microphone (in the annyang demo app you link to, it accesses the SpeechRecognition browser API). This then causes the browser to ask the user if the page should be able to access the microphone. So you don't actually request microphone access, you have to let the browser figure out if it should ask.
  2. In MacOS the app itself also has to have microphone access from the OS. In this case, there's a special electron api call that would need to be made to request access: https://www.electronjs.org/docs/latest/api/system-preferences#systempreferencesaskformediaaccessmediatype-macos

So to answer your question depends on a few things:

  • What are you actually trying to access the microphone for?
  • On MacOS we'd have to implement a Nativefier flag that requests those permissions on app launch and you'd have to build the app with that flag since we don't want to ask for those permissions for every app.

@inglesuniversal

This comment was marked as off-topic.

@inglesuniversal

This comment was marked as off-topic.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants