I've encountered this bug while trying to design an application which can record voice and convert speech to text at the same time. I have used Google API for the speech recognition part and audioRecorder object for recording purpose. It didn't work out and hence I shifted to using onBufferReceived() to retrieve the bytes(while the user speaks) in the process. The Google API code is now in onResults() part of my code, which does the voice recognition without the UI.
Here's the code
class listener implements RecognitionListener
{
public void onBufferReceived(byte[] buffer)
{
bufferBytes = buffer;
// capturing the buffer into bufferBytes static variable as the user speaks
try {
bos = new BufferedOutputStream(fos);
bos.write(buffer);
} catch (Exception e) {
e.printStackTrace();
}
finally{
if(bos != null){
try{
bos.flush();
bos.close();
}catch(Exception e){}
}
}
}
public void onEndOfSpeech()
{
speakButton.setText(getString(R.string.Speak));
Log.d(TAG, "onEndofSpeech");
}
public void onError(int error)
{
Log.d(TAG, "error " + error);
mSendText.setVisibility(View.VISIBLE);
mSendText.setText("error retriving text, please once check your Data Connection ");
}
public void onResults(Bundle results)
{
String str = new String();
Log.d(TAG, "onResults " + results);
ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
for (int i = 0; i < data.size(); i++)
{
Log.d(TAG, "result " + data.get(i));
str += data.get(i);
}
mSendText.setVisibility(View.VISIBLE);
mSendText.setText(data.get(0)+"");
}
}