csdcorp / speech_to_text

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

Speech recognition not available on this device #159

Closed answer0732 closed 3 years ago

answer0732 commented 3 years ago

Hello, I'm using pixel2(android 11) to test this plugin, and I have enabled the microphone permission (including flutter app and google), but I got an error, can you tell me the reason, thank you

  Future<void> _startSpeech() async{
    stt.SpeechToText speech = stt.SpeechToText();
    bool available = await speech.initialize(
      debugLogging: true,
      onStatus: (s) {}, 
      onError: (e) {},
    );
    if ( available ) {
      speech.listen( onResult: (r) {});
    }
    else {

    }
  }

here is debug info:

D/SpeechToTextPlugin(17989): Start initialize
D/SpeechToTextPlugin(17989): Checked permission
D/SpeechToTextPlugin(17989): has permission, completing
D/SpeechToTextPlugin(17989): completeInitialize
D/SpeechToTextPlugin(17989): Testing recognition availability
E/SpeechToTextPlugin(17989): Speech recognition not available on this device
D/SpeechToTextPlugin(17989): leaving initializeIfPermitted
E/flutter (17989): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(recognizerNotAvailable, Speech recognition not available on this device, , null)
E/flutter (17989): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7)
E/flutter (17989): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18)
E/flutter (17989): <asynchronous suspension>
E/flutter (17989): #2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
E/flutter (17989): #3      MethodChannelSpeechToText.initialize (package:speech_to_text_platform_interface/method_channel_speech_to_text.dart:39:21)
E/flutter (17989): #4      SpeechToText.initialize (package:speech_to_text/speech_to_text.dart:199:10)
sowens-csd commented 3 years ago

This is like because that device doesn't have speech recognition installed / enabled. There's information here that should help: https://github.com/csdcorp/speech_to_text/blob/main/speech_to_text/README.md#not-working-on-a-particular-android-device

answer0732 commented 3 years ago

Hi, thanks for you reply! I found the solution: Modify my targetSdkVersion 30 to 28, and it works!

But I try to keep my file targetSdkVersion 30, and modify the targetSdkVersion of the speech_to_text plugin to 30, it still shows ‘Speech recognition not available on this device’ It only supports 28 ?

sowens-csd commented 3 years ago

Very interesting. I don't know of any changes to 30 that would make it incompatible, but that doesn't mean there aren't any. I'll have to try it on an SDK emulator and see what's up. Thanks for reporting.

answer0732 commented 3 years ago

I also modified your plugin version to make it consistent with my app, but it also does not work

buildscript {
    ext.kotlin_version = '1.4.20'   // changed , consistent with my app
    ....
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'  // changed,  consistent with my app
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
android {
    compileSdkVersion 30  //changed, consistent with my app
    ....
}

// gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip  // changed,  consistent with my app

Seems to only work on 28

answer0732 commented 3 years ago

Very interesting. I don't know of any changes to 30 that would make it incompatible, but that doesn't mean there aren't any. I'll have to try it on an SDK emulator and see what's up. Thanks for reporting.

ok, thanks !

sowens-csd commented 3 years ago

I've recreated the issue on an Android 30 emulator and resolved it. It seems to be related to a new security requirement on Android 30. Could you try the fix on a real device and let me know if it is working for you? The good news is that it doesn't require any change to the plugin, just to the AndroidManifest.xml file. I found the solution from this helpful SO post:

https://stackoverflow.com/questions/64319117/speechrecognizer-not-available-when-targeting-android-11 https://developer.android.com/about/versions/11/privacy/package-visibility

Here's the fix:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.csdcorp.speech_to_text_example">
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <queries>
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>
...

The change is the addition of the queries element.

answer0732 commented 3 years ago

it works ~ think you!

kangshuisheng commented 3 years ago

I've recreated the issue on an Android 30 emulator and resolved it. It seems to be related to a new security requirement on Android 30. Could you try the fix on a real device and let me know if it is working for you? The good news is that it doesn't require any change to the plugin, just to the AndroidManifest.xml file. I found the solution from this helpful SO post:

https://stackoverflow.com/questions/64319117/speechrecognizer-not-available-when-targeting-android-11 https://developer.android.com/about/versions/11/privacy/package-visibility

Here's the fix:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.csdcorp.speech_to_text_example">
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <queries>
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>
...

The change is the addition of the queries element.

I've recreated the issue on an Android 30 emulator and resolved it. It seems to be related to a new security requirement on Android 30. Could you try the fix on a real device and let me know if it is working for you? The good news is that it doesn't require any change to the plugin, just to the AndroidManifest.xml file. I found the solution from this helpful SO post:

https://stackoverflow.com/questions/64319117/speechrecognizer-not-available-when-targeting-android-11 https://developer.android.com/about/versions/11/privacy/package-visibility

Here's the fix:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.csdcorp.speech_to_text_example">
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <queries>
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>
...

The change is the addition of the queries element.

Hello, sir. on HUAWEI P30, this solution does not work

stevepopovich commented 3 years ago

This worked on OnePlus 7T that doesn't even use this library. Thanks!

kundan24 commented 3 years ago

Uninstall apk from mobile then

Build.gradle

        minSdkVersion 21,
        targetSdkVersion 30
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <queries>
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>

and run cmd: flutter run

gabrielhrr commented 2 years ago

You can open your google search and click on the microphone, then accept the permitions.

akmaljoha commented 2 years ago

I've recreated the issue on an Android 30 emulator and resolved it. It seems to be related to a new security requirement on Android 30. Could you try the fix on a real device and let me know if it is working for you? The good news is that it doesn't require any change to the plugin, just to the AndroidManifest.xml file. I found the solution from this helpful SO post:

https://stackoverflow.com/questions/64319117/speechrecognizer-not-available-when-targeting-android-11 https://developer.android.com/about/versions/11/privacy/package-visibility

Here's the fix:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.csdcorp.speech_to_text_example">
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <queries>
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>
...

The change is the addition of the queries element.

it works ~ think you!

yeah it work, thanks

sdkysfzai commented 1 year ago

I've recreated the issue on an Android 30 emulator and resolved it. It seems to be related to a new security requirement on Android 30. Could you try the fix on a real device and let me know if it is working for you? The good news is that it doesn't require any change to the plugin, just to the AndroidManifest.xml file. I found the solution from this helpful SO post:

https://stackoverflow.com/questions/64319117/speechrecognizer-not-available-when-targeting-android-11 https://developer.android.com/about/versions/11/privacy/package-visibility

Here's the fix:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.csdcorp.speech_to_text_example">
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <queries>
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>
...

The change is the addition of the queries element.

I'm having the same issue and this doesn't fix it. Unhandled Exception: PlatformException(recognizerNotAvailable, Speech recognition not available on this device, , null)

hmtbasdas commented 1 year ago

I've recreated the issue on an Android 30 emulator and resolved it. It seems to be related to a new security requirement on Android 30. Could you try the fix on a real device and let me know if it is working for you? The good news is that it doesn't require any change to the plugin, just to the AndroidManifest.xml file. I found the solution from this helpful SO post: https://stackoverflow.com/questions/64319117/speechrecognizer-not-available-when-targeting-android-11 https://developer.android.com/about/versions/11/privacy/package-visibility Here's the fix:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.csdcorp.speech_to_text_example">
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <queries>
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>
...

The change is the addition of the queries element.

I'm having the same issue and this doesn't fix it. Unhandled Exception: PlatformException(recognizerNotAvailable, Speech recognition not available on this device, , null)

Yeah this solution not working. I tried every way but still im gettinng same error SpeechRec.... not available on this device

fenix237 commented 2 days ago

ok pour moi