Skip to content

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

@compulim

Description

@compulim

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-speechbugIndicates an unexpected problem or an unintended behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions