eclipse - Unable To Run Speechrecognizer Android -
i seem not able run speech recognizer on phone. app instals , button returning needs returning actual voice recognizer isn't returning onbeginning of speech , etc... here code, it's easy fix. running on galaxy s3 displays erros (trace: can't open, no such directory) , activitymanager: warning: activity not started, current task has been brought front. may problem permissions. great!
public class mainactivity extends activity implements onclicklistener { listview lv; private speechrecognizer mspeechrecognizer; private intent mspeechrecognizerintent; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); lv = (listview)findviewbyid(r.id.lvvoicereturn); button b= (button)findviewbyid(r.id.bvoice); b.setonclicklistener(this); boolean available = speechrecognizer.isrecognitionavailable(this); log.d("speech", "available = " + available); mspeechrecognizer = speechrecognizer.createspeechrecognizer(this); mspeechrecognizer.setrecognitionlistener(new speechlistener()); mspeechrecognizerintent = new intent(recognizerintent.action_recognize_speech); mspeechrecognizerintent.putextra(recognizerintent.extra_language_model, recognizerintent.language_model_free_form); mspeechrecognizerintent.putextra(recognizerintent.extra_calling_package, this.getpackagename()); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public void onclick(view v) { // todo auto-generated method stub log.d("speech", "button active"); mspeechrecognizer.startlistening(mspeechrecognizerintent); } private class speechlistener implements recognitionlistener { @override public void onbeginningofspeech() { log.d("speech", "onbeginningofspeech"); } @override public void onbufferreceived(byte[] buffer) { log.d("speech", "onbufferreceived"); } @override public void onendofspeech() { log.d("speech", "onendofspeech"); } @override public void onerror(int error) { log.d("speech", "onerror"); } @override public void onevent(int eventtype, bundle params) { log.d("speech", "onevent"); } @override public void onpartialresults(bundle partialresults) { log.d("speech", "onpartialresults"); } @override public void onreadyforspeech(bundle params) { log.d("speech", "onreadyforspeech"); } @override public void onresults(bundle results) { log.d("speech", "results"); } @override public void onrmschanged(float rmsdb) { //log.d("speech", "onrmschanged"); } }
}
here manifest
<uses-sdk android:minsdkversion="8" android:targetsdkversion="17" /> <uses-permission android:name="android.permission.record_audio"/> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.speech.mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
you need following permission
<uses-permission android:name="android.permission.record_audio"/>
and fix following error instead of
protected class mspeechrecognizerintent implements recognitionlistener
it should
private class speechlistener implements recognitionlistener
and add following in oncreate
after line
boolean available = speechrecognizer.isrecognitionavailable(); log.d("speech", "available = " + available); mspeechrecognizer = speechrecognizer.createspeechrecognizer(this); mspeechrecognizer.setrecognitionlistener(new speechlistener());
Comments
Post a Comment