csdcorp / speech_to_text

A Flutter plugin that exposes device specific text to speech recognition capability.
BSD 3-Clause "New" or "Revised" License
372 stars 231 forks source link

listen() immediately fails on Android Chrome browser #412

Open eilzo opened 1 year ago

eilzo commented 1 year ago

Related: https://github.com/csdcorp/speech_to_text/issues/389

My app can successfully call listen() and get STT responses as a web app running on desktop Chrome, and when installed as an Android app. However, it fails when called from a web application running on a mobile Android device.

After calling listen(), I get an immediate error SpeechRecognitionError msg: not-allowed, permanent: false.

The microphone works correctly on all other mobile websites that use the microphone (Google search, keyboard input, etc). I've verified SpeechToText().hasPermission before calling listen().

To recreate

git clone https://github.com/csdcorp/speech_to_text.git
cd speech_to_text
flutter run -d web-server --web-port 8080 --web-hostname 0.0.0.0

Open <IP address>:8080 on tethered Android device.

Other notes:

sowens-csd commented 1 year ago

Does initialize return true on that browser? I know that on Chrome desktop there is a permission step to grant access to the microphone for web apps. Do you know if the same is true on their mobile browser? The error makes me think that possibly the web app doesn't have permission to use the microphone.

eilzo commented 1 year ago

Howdy, thanks for the quick response!

My mobile browser requests permissions, confirms initialization, starts listening, then fails:

  bool isInitialized = await speech.initialize(onError: (error) {
    speech.stop();
    print('$error');
  });

  if (isInitialized && speech.isNotListening) {
    print('starting text recording'); // this prints
    speech.listen(... // fails here
eilzo commented 1 year ago

As another note, I just tried running the example of https://pub.dev/packages/record and that works successfully on my mobile browser, so this seems to be a package-specific issue.

Edit: The record package works on my Pixel 4, but still fails on a Pixel 7 and an iPhone 13.

sowens-csd commented 9 months ago

As part of another issue I've just been testing this on Android Chrome and version 6.5.0 seems to work fine. I know this has been a while but if you have a chance to try the updated version do let me know.