Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Speech Recognizer does not honor lowercase tags

 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm messing around with language detection in multiple languages, and noticed that the language code seems to be case sensitive. The problem with this is, Locale().getLanguage() results are lowercased! Here's an example if you'd like to try and verify this behavior for me.

  • Create a project using the defaults and an Empty Activity
  • Add the Record Audio permission to AndroidManifest.xml


  • Replace the XML in activity_main.xml with the following:


  • Replace the code in MainActivity.java with the following:


  • Run the app.

  • The objects are as follows:

  • If the the checkbox is checked, it will lowecase the chosen language tag.
  • The spinner lists all dialects available for recognition, and defaults to the default language and country of the system.
  • The text box next to it shows the language code passed to the recognition system, and in parenthesis, what Locale().getLanguage() returns for the selection.
  • The text box between the checkbox and the button shows the first entry from what the recognizer returned.
  • The button starts the recognition. It will also stop it, but there's no need to do so manually, as it will shortly timeout and stop on its own.
  • On the bottom of the screen is a text box showing the most recent error.

  • I have found that lowercasing the tag defaults to English (either because of my system or because that is the ultimate default) and Locale().getLanguage() returns lowercase. This isn't an issue, per se, but i thought using getLanguage would be the appropriate method to use.
     
    Brian Tkatch
    Bartender
    Posts: 567
    25
    Linux Notepad Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I would even like someone (or two or three) to verify this behavior. It's easy to test. Just try a non English word, like Hola (oh-la) in Spanish or Ciao (chow) in Italian.
     
    Brian Tkatch
    Bartender
    Posts: 567
    25
    Linux Notepad Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Figured something out. Although using Locale(lang + "-" + country) does not work, regardless of case. It must have the language part alone. Locale(lang, country) seems to work, regardless of case.

    So, that means, when getting the language tag, it must be split in order to get a Locale:


    Unless i'm missing something, and there's an easier way to go from tag to Locale.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic