csdcorp / speech_to_text

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

Can't get locales on Android #505

Open FaFre opened 2 weeks ago

FaFre commented 2 weeks ago

I tried to run the example but the call SpeechToTextPlatform.instance.locales() is never returning on my device. I tried several rebuilds and reinstalls, but it wouldn't work. I have two languages offline installed. I tried to fish with logcat, but there is nothing. Flutter is not throwing anything as well.

Edit: Tag v6.2.0 is working (but only showing one of my two available languages), all version above are not working. I'm on Flutter 3.21.0-1.0.pre.2

Edit: After setting up a new example I can identify that the following version breaks the locales platform call on my device (Android 13):

Android 33+ now returns a valid list from locales. It returns the supported on device languages. This is (probably) smaller than the full list of online languages but better than the current list that only has the default language in it. It also seems to be the only option that's available.
sowens-csd commented 2 weeks ago

Is this on a real device or a simulator? If real which device?

I'm definitely not happy with that method of getting the locales. Sure wish Android with fix the default previously working method or implement their suggested new method consistently. However, I've never seen it just hang. That's very surprising. Can you do a run with debugLogging: true in the initialize call and post the log output?

FaFre commented 2 weeks ago

This is on a real device Xiaomi Poco F3 (M2012K11AG). I use LineageOS 20 (Android 13) with all available Android patches until 05.04.2024, so the System is very up-to date.

This is the output:

D/SpeechToTextPlugin(11005): Start initialize
D/SpeechToTextPlugin(11005): Checked permission
D/SpeechToTextPlugin(11005): has permission, completing
D/SpeechToTextPlugin(11005): completeInitialize
D/SpeechToTextPlugin(11005): Testing recognition availability
D/BluetoothHeadset(11005): Binding service...
D/SpeechToTextPlugin(11005): sending result
D/SpeechToTextPlugin(11005): leaving complete
D/SpeechToTextPlugin(11005): leaving initializeIfPermitted
D/BluetoothHeadset(11005): Proxy object connected
D/SpeechToTextPlugin(11005): Found a headset: android.bluetooth.BluetoothHeadset@1be0189
I/Gralloc4(11005): Adding additional valid usage bits: 0x546c08202000

I should have everything set up:

Screenshot_20240411-092222_Settings Screenshot_20240411-092159_Google Screenshot_20240411-092140_Google Screenshot_20240411-092131_Speech Recognition and Synthesis from Google

sowens-csd commented 2 weeks ago

So on newer Android builds locales are retrieved using on device speech recognition if it is available. From what I've seen in the past some devices, possibly including Xiaomi do not fully implement all parts of Android. I think there is/was some disagreement with Google that blocked it. I wonder if the on device speech recognition is not working. I'll have a look at the way it looks up the on device and see if maybe it's failing to catch an exception or something there.

FaFre commented 2 weeks ago

I'm using LineageOS which should be almost vanilla Android.

FaFre commented 2 weeks ago

@sowens-csd when you can give me a bit of guidance on how to debug it, I will happily do it. I'm just not really familiar with native android to build up a small test application with ease.

sowens-csd commented 2 weeks ago

Thanks for the offer. I’d love to work with you on it. Unfortunately it will be a few weeks. I’ll post again when I can work on it. Sorry for the delay.