Hi everyone,
I'm using Sphinix for an android project, and I modified the dictionnary and also menu, when I start the application it reconigze the KeyPhrase that i added and then when i say "Menu" it crushs because after that i need to say "Amrane" but it crushs before I can say the word.
and the bug is in the switchSearch's function in the bold line
** else if (text.equals(AMRANE))
** switchSearch(AMRANE);
private void switchSearch(String searchName) {
recognizer.stop();
Log.v("switchSearch", " "+searchName);
// If we are not spotting, start listening with timeout (10000 ms or 10 seconds).
if (searchName.equals(KWS_SEARCH))
recognizer.startListening(searchName);
else
*** recognizer.startListening(searchName, 10000);
*
String caption = getResources().getString(captions.get(searchName));
speechtoText.setText(caption);
}
And one more question how can i display everything that I can say, like if i said a word from the dictionnary it will displayed in the application ?
Thank you,
Here is the log of the crush :
I/SpeechRecognizer: Stop recognition
V/switchSearch: menu
I/SpeechRecognizer: Start recognition "menu"
D/DisplayManager: DisplayManager()
D/SpeechRecognizer: Starting decoding
I/cmusphinx: INFO: pocketsphinx.c(986): Writing raw audio file: /storage/emulated/0/Android/data/fr.amrane.myapplication/files/sync/000000001.raw
I/cmusphinx: INFO: cmn_live.c(120): Update from <
I/cmusphinx: 25.61
I/cmusphinx: 6.32
I/cmusphinx: -8.67
I/cmusphinx: 10.05
I/cmusphinx: 11.28
I/cmusphinx: 4.54
I/cmusphinx: -1.85
I/cmusphinx: 1.64
I/cmusphinx: 2.96
I/cmusphinx: -1.93
I/cmusphinx: -0.33
I/cmusphinx: 2.85
I/cmusphinx: -1.95
I/cmusphinx: >
I/cmusphinx: INFO: cmn_live.c(138): Update to <
I/cmusphinx: 25.01
I/cmusphinx: 6.57
I/cmusphinx: -7.41
I/cmusphinx: 10.23
I/cmusphinx: 11.90
I/cmusphinx: 4.46
I/cmusphinx: -0.61
I/cmusphinx: 2.40
I/cmusphinx: 2.44
I/cmusphinx: -1.99
I/cmusphinx: -0.54
I/cmusphinx: 3.11
I/cmusphinx: -0.99
I/cmusphinx: >
I/cmusphinx: INFO: fsg_search.c(859): 72 frames, 2247 HMMs (31/fr), 6586 senones (91/fr), 141 history entries (1/fr)
I/cmusphinx: INFO: fsg_search.c(869): fsg 0.29 CPU 0.397 xRT
I/cmusphinx: INFO: fsg_search.c(871): fsg 2.41 wall 3.302 xRT
I/SpeechRecognizer: Stop recognition
V/switchSearch: amrane
I/SpeechRecognizer: Start recognition "amrane"
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: fr.amrane.myapplication, PID: 6397
java.lang.RuntimeException: Decoder_setSearch returned -1
at edu.cmu.pocketsphinx.PocketSphinxJNI.Decoder_setSearch(Native Method)
at edu.cmu.pocketsphinx.Decoder.setSearch(Decoder.java:181)
at edu.cmu.pocketsphinx.SpeechRecognizer.startListening(SpeechRecognizer.java:141)
at fr.amrane.myapplication.MainActivity.switchSearch(MainActivity.java:129)
at fr.amrane.myapplication.MainActivity.onPartialResult(MainActivity.java:230)
at edu.cmu.pocketsphinx.SpeechRecognizer$ResultEvent.execute(SpeechRecognizer.java:427)
at edu.cmu.pocketsphinx.SpeechRecognizer$RecognitionEvent.run(SpeechRecognizer.java:391)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5910)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So can you give me like an example for catching words like which function I need to call because i saw in the tutorial but there is some steps I didn't get them.
And thank you,
Here is my source code
publicclassMainActivityextendsAppCompatActivityimplementsRecognitionListener{/*Namedsearchesallowtoquicklyreconfigurethedecoder*/privatestaticfinalStringKWS_SEARCH="wakeup";privatestaticfinalStringAMRANE="amrane";privatestaticfinalStringSOS="sos";privatestaticfinalStringTEST="test";privatestaticfinalStringHELLO="hello";privatestaticfinalStringDIGITS_SEARCH="digits";privatestaticfinalStringMENU_SEARCH="menu";/*Keywordwearelookingfortoactivatemenu*/privatestaticfinalStringKEYPHRASE="android";/*Usedtohandlepermissionrequest*/privatestaticfinalintPERMISSIONS_REQUEST_RECORD_AUDIO=1;privateSpeechRecognizerrecognizer;privateHashMap<String,Integer>captions;privateTextViewspeechtoText;privateImageButtonbtSpeak;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);btSpeak=(ImageButton)findViewById(R.id.btnSpeak);speechtoText=(TextView)findViewById(R.id.speechToText);captions=newHashMap<String,Integer>();captions.put(AMRANE,R.string.amrane);captions.put(KWS_SEARCH,R.string.kws_caption);captions.put(SOS,R.string.sos);captions.put(KEYPHRASE,R.string.myoxy);captions.put(TEST,R.string.test);captions.put(HELLO,R.string.hello);captions.put(MENU_SEARCH,R.string.menu_caption);speechtoText.setText("Preparing the recognizer");//CheckifuserhasgivenpermissiontorecordaudiointpermissionCheck=ContextCompat.checkSelfPermission(getApplicationContext(),Manifest.permission.RECORD_AUDIO);if(permissionCheck==PackageManager.PERMISSION_DENIED){ActivityCompat.requestPermissions(this,newString[]{Manifest.permission.RECORD_AUDIO},PERMISSIONS_REQUEST_RECORD_AUDIO);return;}runRecognizerSetup();}privatevoidrunRecognizerSetup(){//Recognizerinitializationisatime-consuminganditinvolvesIO,//soweexecuteitinasynctasknewAsyncTask<Void,Void,Exception>(){@OverrideprotectedExceptiondoInBackground(Void...params){try{Assetsassets=newAssets(MainActivity.this);FileassetDir=assets.syncAssets();setupRecognizer(assetDir);}catch(IOExceptione){returne;}returnnull;}@OverrideprotectedvoidonPostExecute(Exceptionresult){if(result!=null){speechtoText.setText("Failed to init recognizer "+result);}else{switchSearch(KWS_SEARCH);}}}.execute();}privatevoidswitchSearch14(StringsearchName){recognizer.stop();Log.v("MainActivity"," "+searchName);//Ifwearenotspotting,startlisteningwithtimeout(10000msor10seconds).recognizer.startListening(searchName,100000);Stringcaption=getResources().getString(captions.get(searchName));Log.v("MainActivity"," "+caption);speechtoText.setText(caption);}privatevoidswitchSearch(StringsearchName){recognizer.stop();Log.v("switchSearch"," "+searchName);//Ifwearenotspotting,startlisteningwithtimeout(10000msor10seconds).if(searchName.equals(KWS_SEARCH))recognizer.startListening(searchName);elserecognizer.startListening(searchName,10000);Stringcaption=getResources().getString(captions.get(searchName));speechtoText.setText(caption);}privatevoidsetupRecognizer(FileassetsDir)throwsIOException{//Therecognizercanbeconfiguredtoperformmultiplesearches//ofdifferentkindandswitchbetweenthemrecognizer=SpeechRecognizerSetup.defaultSetup().setAcousticModel(newFile(assetsDir,"en-us-ptm")).setDictionary(newFile(assetsDir,"cmudict-en-us.dict")).setRawLogDir(assetsDir)//Todisableloggingofrawaudiocommentoutthiscall(takesalotofspaceonthedevice).getRecognizer();recognizer.addListener(this);/**Inyourapplicationyoumightnotneedtoaddallthosesearches.*Theyareaddedherefordemonstration.Youcanleavejustone.*///Createkeyword-activationsearch.recognizer.addKeyphraseSearch(KWS_SEARCH,KEYPHRASE);FilemenuGrammar=newFile(assetsDir,"menu.gram");recognizer.addGrammarSearch(MENU_SEARCH,menuGrammar);//NextsearchfordigitsFiledigitsGrammar=newFile(assetsDir,"digits.gram");recognizer.addGrammarSearch(DIGITS_SEARCH,digitsGrammar);/*recognizer.addKeyphraseSearch(AMRANE,KEYPHRASE);recognizer.addKeyphraseSearch(SOS,KEYPHRASE);recognizer.addKeyphraseSearch(TEST,KEYPHRASE);recognizer.addKeyphraseSearch(SOS,KEYPHRASE);*/}@OverridepublicvoidonRequestPermissionsResult(intrequestCode,String[]permissions,int[]grantResults){super.onRequestPermissionsResult(requestCode,permissions,grantResults);if(requestCode==PERMISSIONS_REQUEST_RECORD_AUDIO){if(grantResults.length>0&&grantResults[0]==PackageManager.PERMISSION_GRANTED){runRecognizerSetup();}else{finish();}}}@OverridepublicvoidonDestroy(){super.onDestroy();if(recognizer!=null){recognizer.cancel();recognizer.shutdown();}}/***Receivingspeechinput**/@OverrideprotectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){super.onActivityResult(requestCode,resultCode,data);}@OverridepublicvoidonBeginningOfSpeech(){}@OverridepublicvoidonEndOfSpeech(){if(!recognizer.getSearchName().equals(KWS_SEARCH)){makeText(getApplicationContext(),"onENdofSpeech : "+recognizer.getSearchName(),Toast.LENGTH_SHORT).show();switchSearch(KWS_SEARCH);}}@OverridepublicvoidonPartialResult(Hypothesishypothesis){if(hypothesis==null)return;Stringtext=hypothesis.getHypstr();makeText(getApplicationContext(),"Result : "+text,Toast.LENGTH_SHORT).show();speechtoText.setText(text);if(text.equals(KEYPHRASE))switchSearch(MENU_SEARCH);elseif(text.equals(DIGITS_SEARCH))switchSearch(DIGITS_SEARCH);elseif(text.equals(TEST))switchSearch(TEST);elseif(text.equals(HELLO))switchSearch(HELLO);elseif(text.equals(AMRANE))switchSearch(AMRANE);elseif(text.equals(SOS))switchSearch(SOS);elsespeechtoText.setText(text);}@OverridepublicvoidonResult(Hypothesishypothesis){speechtoText.setText("");if(hypothesis!=null){Stringtext=hypothesis.getHypstr();makeText(getApplicationContext(),text,Toast.LENGTH_SHORT).show();speechtoText.setText(text);}}@OverridepublicvoidonError(Exceptione){speechtoText.setText(e.getMessage());}@OverridepublicvoidonTimeout(){switchSearch(KEYPHRASE);}}
and here is my dictionnary
android AE N DH ER AO IH DH
amrane AE M R EY N
amrane(2) AA M ER AE N
sos S AO S
sos(2) EH OW EH S
test T EH S T
hello HH EH L OW
digits D IH JH AH T S
digits(2) D IH JH IH T S
menu M EH N Y UW
menus M EH N Y UW Z
oh OW
zero Z IH R OW
zero(2) Z IY R OW
one W AH N
one(2) HH W AH N
two T UW
three TH R IY
four F AO R
five F AY V
six S IH K S
seven S EH V AH N
eight EY TH
nine N AY N
wakeup W EY K AH P
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What I want is that the application will hear some words like 8 words and for each word an acitivity will open. so that's why I want to know if there is a way to use your framework only for detecting words not like i need to saythe keyphrase and then i need to say something
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everyone,
I'm using Sphinix for an android project, and I modified the dictionnary and also menu, when I start the application it reconigze the KeyPhrase that i added and then when i say "Menu" it crushs because after that i need to say "Amrane" but it crushs before I can say the word.
and the bug is in the switchSearch's function in the bold line
And one more question how can i display everything that I can say, like if i said a word from the dictionnary it will displayed in the application ?
Thank you,
Here is the log of the crush :
There are earlier errors caused this, you need to provide the full code and data and also the full logcat output.
Most likely error is caused by the missing word in the dictionary.
No, phone is too slow for that.
So can you give me like an example for catching words like which function I need to call because i saw in the tutorial but there is some steps I didn't get them.
And thank you,
Here is my source code
and here is my dictionnary
In your code you never add "AMRANE" search, the relevant part is commented out, so it can not switch to non-existent search.
You first need to decide which searches do you want to have in your application.
What I want is that the application will hear some words like 8 words and for each word an acitivity will open. so that's why I want to know if there is a way to use your framework only for detecting words not like i need to saythe keyphrase and then i need to say something
I would implement an activation keyphrase and then an additional keyphrase search for 8 words you want to detect.