Problem:
Below is only the part. But, I have attached the zip file for the complete source code. And you can test in on your computer.
Now, here's my problem:
Why is it only the onCreate and onDestroy will executed ? But the rest of the functions are NOT executed. I need those functions to be executed specially the function that are under this class VoiceResultsListener .
And get the result on this procedure : public void onResults(Bundle results).
Please help...
public class SimpleVoiceService extends RecognitionService {
private SpeechRecognizer m_EngineSR;
@Override
public void onCreate() {
super.onCreate();
Log.i("SimpleVoiceService", "Service started");
Toast.makeText(this, "Simple Voice Service Started..", Toast.LENGTH_SHORT).show();
}
@Override
public void onDestroy() {
super.onDestroy();
Log.i("SimpleVoiceService", "Service stopped");
Toast.makeText(this, "Simple Voice Service end..", Toast.LENGTH_SHORT).show();
}
@Override
protected void onCancel(Callback listener) {
m_EngineSR.cancel();
}
@Override
protected void onStartListening(Intent recognizerIntent, Callback listener) {
Toast.makeText(this, "On Start Listening..", Toast.LENGTH_SHORT).show();
m_EngineSR.setRecognitionListener(new VoiceResultsListener(listener));
m_EngineSR.startListening(recognizerIntent);
}
@Override
protected void onStopListening(Callback listener) {
Toast.makeText(this, "On Stop Listening..", Toast.LENGTH_SHORT).show();
m_EngineSR.stopListening();
}
private class VoiceResultsListener implements RecognitionListener
{
private Callback m_UserSpecifiedListener;
/**
*
* @param userSpecifiedListener
*/
public VoiceResultsListener(Callback userSpecifiedListener) {
m_UserSpecifiedListener = userSpecifiedListener;
}
public void onBeginningOfSpeech() {
try {
m_UserSpecifiedListener.beginningOfSpeech();
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onBufferReceived(byte[] buffer) {
try {
m_UserSpecifiedListener.bufferReceived(buffer);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onEndOfSpeech() {
try {
m_UserSpecifiedListener.endOfSpeech();
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onError(int error) {
try {
m_UserSpecifiedListener.error(error);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onEvent(int eventType, Bundle params) { ; }
//@Override
public void onPartialResults(Bundle partialResults) {
try {
m_UserSpecifiedListener.partialResults(partialResults);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onReadyForSpeech(Bundle params) {
try {
m_UserSpecifiedListener.readyForSpeech(params);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onResults(Bundle results) {
try {
m_UserSpecifiedListener.results(results);
ArrayList<String> matches = results.getStringArrayList(
SpeechRecognizer.RESULTS_RECOGNITION);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onRmsChanged(float rmsdB) {
try {
m_UserSpecifiedListener.rmsChanged(rmsdB);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
}
Thanks,
Cris
Below is only the part. But, I have attached the zip file for the complete source code. And you can test in on your computer.
Now, here's my problem:
Why is it only the onCreate and onDestroy will executed ? But the rest of the functions are NOT executed. I need those functions to be executed specially the function that are under this class VoiceResultsListener .
And get the result on this procedure : public void onResults(Bundle results).
Please help...
public class SimpleVoiceService extends RecognitionService {
private SpeechRecognizer m_EngineSR;
@Override
public void onCreate() {
super.onCreate();
Log.i("SimpleVoiceService", "Service started");
Toast.makeText(this, "Simple Voice Service Started..", Toast.LENGTH_SHORT).show();
}
@Override
public void onDestroy() {
super.onDestroy();
Log.i("SimpleVoiceService", "Service stopped");
Toast.makeText(this, "Simple Voice Service end..", Toast.LENGTH_SHORT).show();
}
@Override
protected void onCancel(Callback listener) {
m_EngineSR.cancel();
}
@Override
protected void onStartListening(Intent recognizerIntent, Callback listener) {
Toast.makeText(this, "On Start Listening..", Toast.LENGTH_SHORT).show();
m_EngineSR.setRecognitionListener(new VoiceResultsListener(listener));
m_EngineSR.startListening(recognizerIntent);
}
@Override
protected void onStopListening(Callback listener) {
Toast.makeText(this, "On Stop Listening..", Toast.LENGTH_SHORT).show();
m_EngineSR.stopListening();
}
private class VoiceResultsListener implements RecognitionListener
{
private Callback m_UserSpecifiedListener;
/**
*
* @param userSpecifiedListener
*/
public VoiceResultsListener(Callback userSpecifiedListener) {
m_UserSpecifiedListener = userSpecifiedListener;
}
public void onBeginningOfSpeech() {
try {
m_UserSpecifiedListener.beginningOfSpeech();
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onBufferReceived(byte[] buffer) {
try {
m_UserSpecifiedListener.bufferReceived(buffer);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onEndOfSpeech() {
try {
m_UserSpecifiedListener.endOfSpeech();
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onError(int error) {
try {
m_UserSpecifiedListener.error(error);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onEvent(int eventType, Bundle params) { ; }
//@Override
public void onPartialResults(Bundle partialResults) {
try {
m_UserSpecifiedListener.partialResults(partialResults);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onReadyForSpeech(Bundle params) {
try {
m_UserSpecifiedListener.readyForSpeech(params);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onResults(Bundle results) {
try {
m_UserSpecifiedListener.results(results);
ArrayList<String> matches = results.getStringArrayList(
SpeechRecognizer.RESULTS_RECOGNITION);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onRmsChanged(float rmsdB) {
try {
m_UserSpecifiedListener.rmsChanged(rmsdB);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
}
Thanks,
Cris
