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

Safari: Expecting input hint should not block microphone access #2516

Closed
compulim opened this issue Oct 30, 2019 · 1 comment · Fixed by #2517 or #2520
Closed

Safari: Expecting input hint should not block microphone access #2516

compulim opened this issue Oct 30, 2019 · 1 comment · Fixed by #2517 or #2520
Labels
area-speech bug Indicates an unexpected problem or an unintended behavior.

Comments

@compulim
Copy link
Contributor

compulim commented Oct 30, 2019

Version

master

Describe the bug

On Safari (Mac and iOS), if the microphone is being opened without user interactions, Safari will block the access.

Technical details

To detect whether Safari block or not:

async function canOpenMicrophone() {
  const audioContext = new AudioContext();

  try {
    if (audioContext.state === 'suspended') {
      return await Promise.race([
        audioContext.resume().then(() => true),
        new Promise(resolve => setImmediate(resolve)).then(() => false)
      ]);
    }

    return true;
  } finally {
    await audioContext.close();
  }
}

Note: the result of this call is asynchronous and code executed after the result will fail user interaction requirement.

To Reproduce

Steps to reproduce the behavior:

  1. Go to sample 06.c
  2. Click on microphone
  3. Say "input hint expected"
  4. Wait until the bot response completed synthesis

Expected behavior

The microphone will open. Or on Safari, it should never open.

Actual, the microphone is being opened, but Safari blocked access and suspended our code.

[Bug]

@compulim compulim added bug Indicates an unexpected problem or an unintended behavior. Pending labels Oct 30, 2019
@compulim
Copy link
Contributor Author

The check function is not reliable across platforms.

This is because on Firefox, it will always be "suspended" even resumed, until the user clicked agree on the microphone consent dialog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-speech bug Indicates an unexpected problem or an unintended behavior.
Projects
None yet
1 participant