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

Empty Locales Names List #425

Open dinasorz opened 9 months ago

dinasorz commented 9 months ago

The package works fine with the default English supported language. But I want to get LocaleNames List to know the supported languages in the user device in order to set the language accordingly or else to use another API in case it's not available, however Locale Names return empty []. I'm using Google Chrome v115.0.5790.171 window 10, have tried to use it with Microsoft Edge too but same problem. Any help would be highly appreciated :")

  List<LocaleName> localeNames = [];
  final SpeechToText speech = SpeechToText();

  bool isInitialized = await speech.initialize();
   print(SpeechToText()); //Returns: Instance of 'minified:aju'
   print(SpeechToText().locales()); //Returns: Instance of 'minified:ao<List<minified:fQ>>'

  if (isInitialized) {
    localeNames = await speech.locales();
    print("localeNames: $localeNames"); //Returns: localeNames: []
    ..........
 }
sowens-csd commented 9 months ago

Unfortunately I haven't been able to find an API that returns the supported locales in the browser yet so the locales is empty in the web version.

dinasorz commented 9 months ago

Unfortunately I haven't been able to find an API that returns the supported locales in the browser yet so the locales is empty in the web version.

Thanks for answering! That saved me hours from smashing my head xD <3 So is there a possible available way to check if the user's current web/device supports a certain language? and if so to set it as the target-language / localeID?

longtimedeveloper commented 5 months ago

@sowens-csd I got this to work on Chrome desktop and Chrome Android. window.navigator.languages

One covet: Only works on PRODUCTION BUILDS. For whatever reason, the browser does not return them. Maybe for debug builds, have an overload where we can supply the known languages to your package? Not sure if your package needs to know this or not.

Seems like it will work for all modern browsers. I hope this helps.

` import 'package:universal_html/html.dart'; var langList = window.navigator.languages;

`

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/languages

sowens-csd commented 5 months ago

Thank you for this detailed post. From what I can see the API provides a list of the user's preferred languages. I don't think that list will be the same as the list of languages supported by the speech recognition API. I wonder if the speech API uses that list itself to try to determine what the 'default' current language should be. So a browser in Germany would default to German, one in Spain Spanish, using that list of preferred languages to determine the nearest match.

I just did another quick search and I still don't see any reliable way to find the list of supported languages. I'm wondering if it would be helpful to have a standard list of languages that are probably supported by most browsers? I could document that the list is unreliable on browsers but it would at least mean that most people wouldn't have to look up the standard language codes. Of course I'm not sure I know what that list should contain.

longtimedeveloper commented 5 months ago

@sowens-csd I'm 99% sure it is the languages installed on the host device or computer. When I run the code I provided, it gives me the three languages install on my windows desktop and the Android device. They are ordered by preference.

I get the same exact languages that are installed on my devices.

sowens-csd commented 5 months ago

I agree with that, makes sense.

I'm just not certain that the languages that are installed on the device are the set of languages that can be recognized by the speech recognizer. They might be a subset or they might be a disjoint set but I don't think they have to be the same. Have you seen documentation or usage that suggests differently?

I don't have anything better to offer so maybe it's worth using them anyway, but I don't think we can promise they're the right list.

longtimedeveloper commented 5 months ago

@sowens-csd I have no idea how the package works.

I was answering the original question "But I want to get LocaleNames List to know the supported languages in the user device in order to set the language accordingly" that @dinasorz asked.