Vote count:
0
I have created an activity for voice recognition by implements RecognitionListener that does not require internet permission in manifest.xml file but RECORD_AUDIO permission only. On button click, it starts listening and onEndOfSpeech() it should toast as well as display the results in the edittext. I have used only three methods of RecognitionListener i.e.onBeginningOfSpeech(), onResults(), and onEndOfSpeech(). Since i am new to Android so i am facing problem resolving this issue. Kindly help! My java file is this: `
public class VoiceMainActivity extends Activity implements RecognitionListener{
SpeechRecognizer sr;
Button btn;
ArrayList<String> resultlist = new ArrayList<String>();
ProgressDialog pd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_voice_main);
sr=SpeechRecognizer.createSpeechRecognizer(this);
sr.setRecognitionListener(this);
pd=new ProgressDialog(this);
pd.setTitle("Speak");
pd.setMessage("Listening......");
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
btn=(Button)findViewById(R.id.button1speak);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
sr.startListening(RecognizerIntent.getVoiceDetailsIntent(VoiceMainActivity.this));
}
});
}
@Override
public void onBeginningOfSpeech() {
// TODO Auto-generated method stub
pd.show();
}
@Override
public void onEndOfSpeech() {
// TODO Auto-generated method stub
pd.dismiss();
}
@Override
public void onResults(Bundle results) {
resultlist=results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
for(String s : resultlist){
Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
EditText t=(EditText)findViewById(R.id.editvoiceresults);
t.setText(s);
}
}
}
`
asked 7 secs ago
Aucun commentaire:
Enregistrer un commentaire