Androidのウェブサイトの例に基づいて完全に機能する音声認識を備えたプログラムを開発しました。Androidの音声認識がすぐに聴解を停止する
コードに変更を加えず、突然停止しました。それは聴き始めます(あなたは騒音を聞くことができます)。そしてすぐに停止します(あなたは騒音を聞きます)。
他に誰かがこの問題を抱えているか、それを解決する方法がありますか?ここではコードがあります。実行時にエラーが出力されることはなく、リスナーはリスンを開始するとすぐに停止します。
/**
* This method is called when the Speech Recognizer starts to listen for speech input
*/
@Override
public void onBeginningOfSpeech() {
Log.i("SRL", "onBeginningOfSpeech");
}
@Override
public void onBufferReceived(byte[] buffer) {
Log.i("SRL", "onBufferReceived: " + buffer);
}
/**
* This method is called after the speech input has been completed.
*/
@Override
public void onEndOfSpeech() {
Log.i("SRL", "onEndOfSpeech");
}
/**
* This method is called if there has been an error during speech input
* @param errorCode
*/
@Override
public void onError(int errorCode) {
String errorMessage = getErrorText(errorCode);
Log.d("SRL", "FAILED " + errorMessage);
m_speech = SpeechRecognizer.createSpeechRecognizer(this);
m_speech.setRecognitionListener(this);
m_speech.startListening(getIntent());
}
@Override
public void onEvent(int arg0, Bundle arg1) {
Log.i("SRL", "onEvent");
}
/**
* This method is called if the speech recognizer thinks only partial speech was
* input/recognized
* @param arg0
*/
@Override
public void onPartialResults(Bundle arg0) {
Log.i("SRL", "onPartialResults");
}
/**
* This method is called when the speech recognizer is ready for input
* @param arg0
*/
@Override
public void onReadyForSpeech(Bundle arg0) {
Log.i("SRL", "onReadyForSpeech");
}
/**
* This method is called when the speech recognizer has recieved input and recognized it.
* It updates the recognized speech text view on the screen to show users what they have input.
* @param results the text that has been input
*/
@Override
public void onResults(Bundle results) {
recognizedSpeech = (TextView) findViewById(R.id.recognizedSpeech);
Log.i("SRL", "onResults");
ArrayList<String> matches = results
.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
String text = "";
for (String result : matches)
text += result + "\n";
recognizedSpeech.setText(text);
if (recognizedSpeech.getText().toString().contains("yes")) {
PropertySquare square = (PropertySquare) (m_board.getSquare(
players.get(m_currentTurn).getCurrentPosition()));
square.setOwnedBy(players.get(m_currentTurn).getName());
convertTextToSpeech("You now own" + square.getName());
Log.d("buyProperty yes", square.getOwnedBy());
if(manageFunds) {
players.get(m_currentTurn).subtractMoney(square.getPrice());
Log.d("buyProperty yes", players.get(m_currentTurn).getName() +
String.valueOf(players.get(m_currentTurn).getMoney()));
funds.setText(String.valueOf(players.get(m_currentTurn).getMoney()));
}
}
nextTurnRoll();
}
@Override
public void onRmsChanged(float rmsdB) {
Log.i("SRL", "onRmsChanged: " + rmsdB);
}
/**
* This method returns what error was caused if the speech recgonizer throws an error code
* @param errorCode int representing the error thrown
* @return log message including error details
*/
public static String getErrorText(int errorCode) {
String message;
switch (errorCode) {
case SpeechRecognizer.ERROR_AUDIO:
message = "Audio recording error";
break;
case SpeechRecognizer.ERROR_CLIENT:
message = "Client side error";
break;
case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
message = "Insufficient permissions";
break;
case SpeechRecognizer.ERROR_NETWORK:
message = "Network error";
break;
case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
message = "Network timeout";
break;
case SpeechRecognizer.ERROR_NO_MATCH:
message = "No match";
break;
case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
message = "RecognitionService busy";
break;
case SpeechRecognizer.ERROR_SERVER:
message = "error from server";
break;
case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
message = "No speech input";
break;
default:
message = "Didn't understand, please try again.";
break;
}
return message;
}
UPDATE:
onRMSChangedが継続的に実行されていることを私が発見したアプリケーションのログを探しています。これは、音声認識が継続的に実行されていることを意味するので、私のアプリケーションは発言を取り上げません。
"リスナーが停止" =対応する関数が返されますか?エラーコード/例外はどうですか? –
リスナーが@ivan_pozdeevを停止すると、onEndOfSpeechまたはonErrorというonResultsメソッドがなくなり、デバッグコンソールではレプリケートされませんが、開始リッスンサウンドとストップリッスンサウンドのすぐ後ろを聞くことができます。コンソールでは、リスナーがリッスンを開始することがわかりますが、停止リスニング音が与えられても、onRmsChangedがその後も常に呼び出されるため停止しません。 不思議なことに、私はインターネットのアクセス許可を追加し、すべてのユーザーのアクセス許可とやり取りしています。どうやってそれに影響を与えたのか分かりません。 – caseylouisee
セキュリティモデルが変更される可能性があります。任意の(自動)アップデートがインストールされていますか? –