0

I am testing an app that makes voice recognition, but now I am getting this error:

11-04 16:25:58.249: E/ServerConnectorImpl(13716): Failed to create TCP connection
11-04 16:25:58.249: E/ServerConnectorImpl(13716): com.google.android.voicesearch.speechservice.ConnectionException: Failed to establish connection
11-04 16:25:58.249: E/ServerConnectorImpl(13716):   at com.google.android.voicesearch.tcp.TcpConnectionImpl.<init>(TcpConnectionImpl.java:87)
....

Here is my code:

sr = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());
MyRecognition listener = new MyRecognition();
sr.setRecognitionListener(listener);

Class MyRecognition that implements the methods from RecognitionListener

class MyRecognition implements RecognitionListener{
    public void onBeginningOfSpeech() {

    }
    public void onBufferReceived(byte[] buffer) {

}
    public void onEndOfSpeech() {

}
    public void onError(int error) {
        MediaPlayer mp = new MediaPlayer();
            AssetFileDescriptor asset;
            try {
                asset = getAssets().openFd("error.mp3");
                mp.setDataSource(asset.getFileDescriptor(), asset.getStartOffset(), asset.getLength());
                asset.close();
                mp.prepare();
                mp.start();

                mp.setOnCompletionListener(AddActivity.this);
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
    ....
    public void onResults(Bundle results) {
        ....
    }
    .... 
}

The method that makes the voice recognition

private void reconheceVoz(final MediaPlayer mp){
    try{
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.br.test");
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
        sr.startListening(intent);

        mp.release();
    }
    catch(Exception e){
        Toast.makeText(AdicaoActivity.this, "Erro: " + e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}

This error occurs often? How can I treat it?

Thanks.

Bruno Pardini
  • 55
  • 1
  • 11
  • doesn't sound like an error in your code. The exception sounds like a networking error. Are you on Wifi or cellular data network? How reliable is the network connection you are using? When you get the error, can you browse the web from the device? – Michael Levy Nov 04 '12 at 20:58
  • @MichaelLevy I am getting the same error.I am using wifi and can browse the web from my device but the recognizer is giving me connection error and log cat shows the similar stackTrace. – rahulserver Aug 09 '13 at 14:37
  • http://stackoverflow.com/questions/17821825/detecting-limited-network-connectivity-in-android might be helpful – Michael Levy Aug 09 '13 at 14:59

0 Answers0