Thursday, September 6, 2012

Started with Speech Recognition


Couldn't finish up with the bluetooth part of the project. Will deal with it on a good day ( hopefully next week). Luckily, I'm gonna have 9 days OFF. Next week, TCS and HCL companies are coming to the college for Campus Selection. A lot of people get selected in that (here, every Btech student's last hope is TCS), so, we were given a week off for preparation. Anyways its not my issue. Coming back to Speech Recognition.

I used the speech recognition API provided by Android - simple, easy and perfect. Works better than what i thought. One drawback is that it uses an Internet (google) service to identify speech and convert it to words. We are planning to use Pocket-Sphinx in the future where the signal processing is done on-board but the drawback in that is that it has high RAM requirements. It takes quite some time to recognize words from speech even when I tested it on my PC (4GB RAM). Lets see about it in the future. For now, this will do.

Some of the images in my app:

 



As you can see above, there is a list of strings returned. Actually the intent returns an ArrayList<String>, which is added to the ListView as ArrayAdapter. I'm planning to store all the possible commands (to be sent from Android->uC) in the database and when the user gives a command through speech, we iterate through the ArrayList returned by the intent using ArrayList.Iterator() and look for a possible match in the database. It requires an efficient algorithm to search the database and find the match. Then, the matched command is sent to the uC. I believe that this idea is better than OK. 

A chunk of code for iterating through the ArrayList and looking for Integers:


  1. protected void onActivityResult(int requestCode, int resultCode, Intent data)
  2. {
  3.         if(requestCode==check && resultCode==RESULT_OK)
  4.         {
  5. ArrayList<String> results=data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
  6.                        
  7.         while(results.iterator().hasNext())
  8.         {
  9.                 String temp=results.iterator().next().toString();
  10.                                
  11.                 if(isInteger(temp))
  12.                 {
  13.                         tvSpeechResult.setText(temp);
  14.                         break;
  15.                 }
  16.         }      
  17.                                
  18.         }
  19.         super.onActivityResult(requestCode, resultCode, data);
  20. }
  21.        
  22. public boolean isInteger(String ip)
  23. {
  24.        
  25. try {
  26.                        
  27.         Integer.parseInt(ip);
  28.        
  29.         return true;
  30. } catch (Exception e) {
  31.         return false;
  32.     }
  33.                
  34.                
  35. }



Hoping to get back to the Bluetooth API soon...


0 comments:

Post a Comment

 

Copyright © Project Athena Design by O Pregador | Blogger Theme by Blogger Template de luxo | Powered by Blogger