0

音声認識を行うアプリをテストしていますが、次のエラーが発生しています:

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)
....

これが私のコードです:

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

RecognitionListener のメソッドを実装するクラス MyRecognition

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) {
        ....
    }
    .... 
}

音声認識を行う方法

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();
    }
}

このエラーは頻繁に発生しますか? どうすれば治療できますか?

ありがとう。

4

0 に答える 0