Pracuję nad aplikacją na Androida, używając RecognizerIntent.ACTION_RECOGNIZE_SPEECH ,,, moim problemem jest to, że nie wiem, w jaki sposób utworzyć bufor, który przechwyci głos wprowadzany przez użytkownika. i czytaj dużo na przepełnieniu stosu, ale ja po prostu nie rozumiem, w jaki sposób zawieram bufor i wywołanie usługi rozpoznawania z powrotem do mojego kodu. I JAK BĘDZIEMY ZAGRAĆ DLA TREŚCI, KTÓRE ZOSTAŁY ZBAWIONE W BUFORZE.jak zbudować BufferReceived(), aby przechwycić głos za pomocą RecognizerIntent?
to mój kod:
public class Voice extends Activity implements OnClickListener {
byte[] sig = new byte[500000] ;
int sigPos = 0 ;
ListView lv;
static final int check =0;
protected static final String TAG = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.voice);
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.domain.app");
SpeechRecognizer recognizer = SpeechRecognizer
.createSpeechRecognizer(this.getApplicationContext());
RecognitionListener listener = new RecognitionListener() {
@Override
public void onResults(Bundle results) {
ArrayList<String> voiceResults = results
.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if (voiceResults == null) {
Log.e(TAG, "No voice results");
} else {
Log.d(TAG, "Printing matches: ");
for (String match : voiceResults) {
Log.d(TAG, match);
}
}
}
@Override
public void onReadyForSpeech(Bundle params) {
Log.d(TAG, "Ready for speech");
}
@Override
public void onError(int error) {
Log.d(TAG,
"Error listening for speech: " + error);
}
@Override
public void onBeginningOfSpeech() {
Log.d(TAG, "Speech starting");
}
@Override
public void onBufferReceived(byte[] buffer) {
// TODO Auto-generated method stub
TextView display=(TextView)findViewById (R.id.Text1);
display.setText("True");
System.arraycopy(buffer, 0, sig, sigPos, buffer.length) ;
sigPos += buffer.length ;
}
@Override
public void onEndOfSpeech() {
// TODO Auto-generated method stub
}
@Override
public void onEvent(int eventType, Bundle params) {
// TODO Auto-generated method stub
}
@Override
public void onPartialResults(Bundle partialResults) {
// TODO Auto-generated method stub
}
@Override
public void onRmsChanged(float rmsdB) {
// TODO Auto-generated method stub
}
};
recognizer.setRecognitionListener(listener);
recognizer.startListening(intent);
startActivityForResult(intent,check);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}
Nie potrzebujesz 'startActivityForResult' +' onActivityResult', gdy używasz 'SpeechRecognizer' ... – Kaarel
Ponieważ ICS, onBufferReceived nie jest już wywoływany.Nie można korzystać z rozpoznawania mowy i odbierania dźwięku w tym samym czasie. –