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

Example code: speech.locales() stops initSpeechState() from completing on physical device (Samsung S8+, Android 9) #154

Closed Ban11gers closed 3 years ago

Ban11gers commented 3 years ago

I was trying to run example code from speech_to_text pub.dev on my physical device, and found tapping Initialise would not enable the start button. So doing some logging at certain lines led me to find that speech.locales() was not completing and once I commented out

if (hasSpeech) {
    _localeNames = await speech.locales();

    var systemLocale = await speech.systemLocale();
    _currentLocaleId = systemLocale.localeId;
}

I was able to record my voice.

here is the debug log when above code is not commented out:

Installing build\app\outputs\flutter-apk\app.apk...
Waiting for SM G955F to report its views...
Debug service listening on ws://127.0.0.1:58591/UTz9v8WgAt8=/ws
Syncing files to device SM G955F...
D/ViewRootImpl@5aabcf5[MainActivity](23327): ViewPostIme pointer 0
D/ViewRootImpl@5aabcf5[MainActivity](23327): ViewPostIme pointer 1
D/SpeechToTextPlugin(23327): Start initialize
D/SpeechToTextPlugin(23327): Checked permission
D/SpeechToTextPlugin(23327): has permission, completing
D/SpeechToTextPlugin(23327): completeInitialize
D/SpeechToTextPlugin(23327): Testing recognition availability
D/SpeechToTextPlugin(23327): Creating recognizer
D/SpeechToTextPlugin(23327): Setting listener
D/SpeechToTextPlugin(23327): before setup intent
D/SpeechToTextPlugin(23327): setupRecognizerIntent
D/SpeechToTextPlugin(23327): after setup intent
D/SpeechToTextPlugin(23327): sending result
D/SpeechToTextPlugin(23327): leaving complete
D/SpeechToTextPlugin(23327): leaving initializeIfPermitted
D/SpeechToTextPlugin(23327): In RecognizerIntent apply
D/SpeechToTextPlugin(23327): put model
D/SpeechToTextPlugin(23327): put package
D/SpeechToTextPlugin(23327): put partial

On an Android emulator list gets populated but no way to record voice.

sowens-csd commented 3 years ago

Thanks for reporting, I haven't seen that problem before. It sounds like it is hitting a problem while retrieving or encoding the list of locales on the device. Could you let me know what languages are installed on that device? I'm wondering if I'm having a problem with a Unicode or just unexpected character in a device name.

cosmosdesigner commented 3 years ago

Hi @sowens-csd , i have same issue, i have a samsung s8. Where i can see what languages are installed?

cosmosdesigner commented 3 years ago

Ohh just find it, settings, general, languages, language, Portuguese and English

sowens-csd commented 3 years ago

Thanks, any special characters in the language name? Anything with accents or that looks like Unicode? I'm just trying to figure out what I'm doing wrong encoding the names.

cosmosdesigner commented 3 years ago

Nop, i don't see anything that could break local names... how can a retrieve all unicodes?

Ban11gers commented 3 years ago

Here is a dump of all locales from my device

ar
ar-AE
ar-IL
as
as-IN
az
az-AZ
be
be-BY
bg
bg-BG
bn
bn-BD
bn-IN
bs
bs-BA
ca
ca-ES
cs
cs-CZ
da
da-DK
de
de-AT
de-CH
de-DE
el
el-GR
en
en-AU
en-CA
en-GB
en-IE
en-NZ
en-PH
en-US
en-ZA
en-ZG
es
es-ES
es-US
et
et-EE
eu
eu-ES
fa
fa-IR
fi
fi-FI
fil
fil-PH
fr
fr-BE
fr-CA
fr-CH
fr-FR
ga
ga-IE
gl
gl-ES
gu
gu-IN
hi
hi-IN
hr
hr-HR
hu
hu-HU
hy
hy-AM
in
in-ID
is
is-IS
it
it-IT
iw
iw-IL
ja
ja-JP
ka
ka-GE
kk
kk-KZ
km
km-KH
kn
kn-IN
ko
ko-KR
ky
ky-KG
lo
lo-LA
lt
lt-LT
lv
lv-LV
mk
mk-MK
ml
ml-IN
mn
mn-MN
mr
mr-IN
ms
ms-MY
my
my-MM
my-ZG
nb
nb-NO
ne
ne-NP
nl
nl-BE
nl-NL
or
or-IN
pa
pa-IN
pl
pl-PL
pl-SP
pt
pt-BR
pt-PT
ro
ro-RO
ru
ru-RU
si
si-LK
sk
sk-SK
sl
sl-SI
sq
sq-AL
sr
sr-RS
sv
sv-SE
ta
ta-IN
te
te-IN
tg
tg-TJ
th
th-TH
tk
tk-TM
tr
tr-TR
uk
uk-UA
ur
ur-PK
uz
uz-UZ
vi
vi-VN
zh-CN
zh-HK
zh-TW
sowens-csd commented 3 years ago

I just committed a potential fix for this issue. There are two aspects to the fix. The first is some extra debug logging around building the language list. The second is a change so that even if the language list is not available the locales method will still return a result with the default language on the device. The previous code didn't return a result in that case which makes me suspect if that is what's happening on your devices. The logging will show whether that is true. If you could try this on a device that is currently failing and let me know what happens that would be great, thanks!

The new log statements only show with debugLogging: true on initialize they are:

If languages are found:

D/SpeechToTextPlugin: Received extra language broadcast
D/SpeechToTextPlugin: Extra supported languages

If languages are not found:

D/SpeechToTextPlugin: Received extra language broadcast
D/SpeechToTextPlugin: No extra supported languages
Ban11gers commented 3 years ago

Currently not seeing any change

pubspec.lock:

speech_to_text:
    dependency: "direct main"
    description:
      name: speech_to_text
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.1"

Here is the log:

Launching lib\main.dart on SM G955F in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Waiting for SM G955F to report its views...
Debug service listening on ws://127.0.0.1:59050/bO_rYuyUgRs=/ws
Syncing files to device SM G955F...
D/ViewRootImpl@2f0ab62[MainActivity](22599): ViewPostIme pointer 0
D/ViewRootImpl@2f0ab62[MainActivity](22599): ViewPostIme pointer 1
D/SpeechToTextPlugin(22599): Start initialize
D/SpeechToTextPlugin(22599): Checked permission
D/SpeechToTextPlugin(22599): has permission, completing
D/SpeechToTextPlugin(22599): completeInitialize
D/SpeechToTextPlugin(22599): Testing recognition availability
D/SpeechToTextPlugin(22599): Creating recognizer
D/SpeechToTextPlugin(22599): Setting listener
D/SpeechToTextPlugin(22599): before setup intent
D/SpeechToTextPlugin(22599): setupRecognizerIntent
D/SpeechToTextPlugin(22599): after setup intent
D/SpeechToTextPlugin(22599): sending result
D/SpeechToTextPlugin(22599): leaving complete
D/SpeechToTextPlugin(22599): leaving initializeIfPermitted
D/SpeechToTextPlugin(22599): In RecognizerIntent apply
D/SpeechToTextPlugin(22599): put model
D/SpeechToTextPlugin(22599): put package
D/SpeechToTextPlugin(22599): put partial
D/ViewRootImpl@2f0ab62[MainActivity](22599): ViewPostIme pointer 0
D/ViewRootImpl@2f0ab62[MainActivity](22599): ViewPostIme pointer 1
sowens-csd commented 3 years ago

I just want to make sure of a few things because that log is surprising:

  1. You are using a pubspec.yaml dependency on GitHub not the official version from pub.dev.
  2. You have uncommented the locales method in the example app.
  3. You are seeing the same behaviour; the example app hangs and does not complete initialization.

For reference the pubspec dependency would look like this:

  speech_to_text:
    git: https://github.com/csdcorp/speech_to_text.git
KWinston commented 3 years ago

Hi @sowens-csd , I have a Samsung S7, Android 8.0.0 and also ran into this issue. After pointing to this package, it works correctly. After launching the example code with the locales initialization code, the dropdown now shows up and includes the only language I have on. English (United States)

With debugLogging on, I see:

D/SpeechToTextPlugin(11047): Received extra language broadcast
D/SpeechToTextPlugin(11047): No extra supported languages

To connect to this package instead of the pub.dev I added to dependencies like this to link to this package.

  speech_to_text:
    git:
      url: https://github.com/csdcorp/speech_to_text.git
      path: speech_to_text
sowens-csd commented 3 years ago

Thanks a lot for letting me know, I appreciate it.

I'll probably release this version soon with this fix and a few others I've been working.

Ban11gers commented 3 years ago

Confirming no issue on my device with the current changes you've made.

Thanks for that

sowens-csd commented 3 years ago

This is resolved in the 3.1.0 release that is live now.