dlutton / flutter_tts

Flutter Text to Speech package
MIT License
617 stars 258 forks source link

Build in release mode doesn't work #261

Open jporrinoclapps opened 3 years ago

jporrinoclapps commented 3 years ago

πŸ› Bug Report

When I build my app in debug mode everything works OK. But, in release mode, although the tts engine is set to default (com.google.android.tts) correctly, the getLanguages method returns an empty array and the isLanguageAvailable always returns false. Also, the app crashes without any further call to any other methods (this last thing I think is related to the set of tts engine and not the languages).

Logs:

Installing build/app/outputs/flutter-apk/app.apk...
I/flutter (26524): Tts Init State: LOADING
I/flutter (26524): Db Init State: LOADING
I/flutter (26524): com.google.android.tts
I/flutter (26524): []
I/flutter (26524): Tts Init State: ERROR
I/flutter (26524): Language not available
I/flutter (26524): Db Init State: SUCCESS
E/AndroidRuntime(26524): FATAL EXCEPTION: main
E/AndroidRuntime(26524): Process: xyz.clapps.flutter_tts, PID: 26524
E/AndroidRuntime(26524): java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime(26524):    at io.flutter.embedding.engine.e.b$a.a(Unknown Source:35)
E/AndroidRuntime(26524):    at d.a.c.a.j$a$a.a(Unknown Source:14)
E/AndroidRuntime(26524):    at b.c.a.a.r(Unknown Source:6)
E/AndroidRuntime(26524):    at b.c.a.a.a(Unknown Source:582)
E/AndroidRuntime(26524):    at b.c.a.a$e.run(Unknown Source:6)
E/AndroidRuntime(26524):    at b.c.a.a$d.onInit(Unknown Source:110)
E/AndroidRuntime(26524):    at android.speech.tts.TextToSpeech.dispatchOnInit(TextToSpeech.java:831)
E/AndroidRuntime(26524):    at android.speech.tts.TextToSpeech.access$1500(TextToSpeech.java:63)
E/AndroidRuntime(26524):    at android.speech.tts.TextToSpeech$Connection$SetupConnectionAsyncTask.onPostExecute(TextToSpeech.java:2222)
E/AndroidRuntime(26524):    at android.speech.tts.TextToSpeech$Connection$SetupConnectionAsyncTask.onPostExecute(TextToSpeech.java:2177)
E/AndroidRuntime(26524):    at android.os.AsyncTask.finish(AsyncTask.java:695)
E/AndroidRuntime(26524):    at android.os.AsyncTask.access$600(AsyncTask.java:180)
E/AndroidRuntime(26524):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
E/AndroidRuntime(26524):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(26524):    at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime(26524):    at android.app.ActivityThread.main(ActivityThread.java:6923)
E/AndroidRuntime(26524):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(26524):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime(26524):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)

Doctor:

[βœ“] Flutter (Channel stable, 2.2.3, on macOS 11.5.1 20G80 darwin-x64, locale en-AR)
    β€’ Flutter version 2.2.3 at /Users/jporrino/Downloads/flutter
    β€’ Framework revision f4abaa0735 (4 weeks ago), 2021-07-01 12:46:11 -0700
    β€’ Engine revision 241c87ad80
    β€’ Dart version 2.13.4

[βœ“] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    β€’ Android SDK at /Users/jporrino/Library/Android/sdk
    β€’ Platform android-30, build-tools 30.0.3
    β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    β€’ All Android licenses accepted.

[βœ“] Xcode - develop for iOS and macOS
    β€’ Xcode at /Applications/Xcode.app/Contents/Developer
    β€’ Xcode 12.5.1, Build version 12E507
    β€’ CocoaPods version 1.10.1

[βœ“] Chrome - develop for the web
    β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[βœ“] Android Studio (version 4.1)
    β€’ Android Studio at /Applications/Android Studio.app/Contents
    β€’ Flutter plugin can be installed from:
      πŸ”¨ https://plugins.jetbrains.com/plugin/9212-flutter
    β€’ Dart plugin can be installed from:
      πŸ”¨ https://plugins.jetbrains.com/plugin/6351-dart
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[βœ“] Connected device (2 available)
    β€’ moto g 6 (mobile) β€’ ZY322P3D75 β€’ android-arm    β€’ Android 9 (API 28)
    β€’ Chrome (web)      β€’ chrome     β€’ web-javascript β€’ Google Chrome 92.0.4515.107

β€’ No issues found!

Expected behavior

App behavior should not change depending on build mode

Configuration

Added the following code as instructed but noticed no change. Also, the gradle's minSdkVersion is set to 21.

<manifest ... >
...
   <queries>
       <intent>
           <action android:name="TextToSpeech.Engine.INTENT_ACTION_TTS_SERVICE" />
       </intent>
   </queries>
...
</manifest>

Version: ^3.2.1

Platform:

dlutton commented 3 years ago

@jporrinoclapps I'm already looking into the issue as it's related to the same error mentioned in #260

jporrinoclapps commented 3 years ago

@dlutton I read the FlutterTtsPlugin.java to further understand how the package works and how I could solve at least my problem. Also, to get rid of other variables in the equation, I continued my testing using your example code and running it in release mode.

Turns out I didn't need to use the setEngine method, as I am not going to change the tts engine from its default value, and an instance of TextToSpeech is already created during the package initialization (in the call to initInstance made after attachment to the FlutterEngine). I found that, as long as I don't use the setEngine method, the release mode build works just fine.

Also, the crash did not occur if I call the method speak before calling the method setEngine.

I hope this information helps you to figure out this strange behavior.

dlutton commented 3 years ago

@jporrinoclapps that is very helpful thank you.

dqtorres commented 3 years ago

If the exact same thing happens to me before the realease is released, it breaks when performing a setEngine

dlutton commented 3 years ago

@dqtorres are you possibly setting it to an engine that isn't installed on the device? By default it uses the Google TTS engine, so the setEngine method isn't necessary unless you plan on setting it to a different engine. You can call the method getEngines to see the options available to you.

dqtorres commented 3 years ago

@dlutton Thanks, if the setEngine method works correctly but only in debug, when the application is passed to release mode it gives the exception reported, all the devices work fine but only in debug. My goal is to use another tts engine and I get it to work on the device but when the realease is created on the same device by making the setEngines break, the getEngines method has previously been called to see the engines available on the device, it is a very error rare that it is not appreciated unless the release is created, thanks

dlutton commented 3 years ago

@dqtorres do you receive the same error as mentioned by @jporrinoclapps?

Syutkin commented 3 years ago

@dqtorres After setting engine, it takes some time to fully initialize tts. Can you test example app with Future.delayed(Duration(seconds: 1)); right after setEngine?

dqtorres commented 3 years ago

@Syutkin @dlutton You are right, the release mode is too fast, I did what you said and fantastic it already works, but after initialization, Thank you very much again

initTts() async { flutterTts = FlutterTts(); await Future.delayed(Duration (seconds: 1));