SpeechRecognizerActivity.java
Dosyayı İndir
package com.godoro.androidmedia;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;
import java.util.ArrayList;
public class SpeechRecognizerActivity extends AppCompatActivity implements RecognitionListener {
private TextView recognizedView;
private SpeechRecognizer recognizer;
private Intent recognizerIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_speech_recognizer);
recognizedView=findViewById(R.id.recognizedView);
recognizedView.setText("Tanınan konuşma ");
//muteSystemAudio();
initializeRecognizer();
}
private void initializeRecognizer(){
recognizer = SpeechRecognizer.createSpeechRecognizer(this);
Log.i("GodoroAndroid","Ses tanıyıcı yaratıldı");
recognizer.setRecognitionListener(this);
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
//recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "tr");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "tr-TR");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE,"tr");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.godoro.androidmedia");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
recognizer.startListening(recognizerIntent);
}
@Override
public void onReadyForSpeech(Bundle bundle) {
recognizedView.append("Anık ");
}
@Override
public void onBeginningOfSpeech() {
recognizedView.append("Başladı ");
}
@Override
public void onRmsChanged(float v) {
}
@Override
public void onBufferReceived(byte[] bytes) {
}
@Override
public void onEndOfSpeech() {
recognizedView.append("Bitti ");
}
@Override
public void onError(int i) {
recognizedView.append("Yanlışlık ");
initializeRecognizer();
}
@Override
public void onResults(Bundle bundle) {
ArrayList<String> results = bundle.getStringArrayList(
SpeechRecognizer.RESULTS_RECOGNITION);
recognizedView.append(results.toString() + " ");
recognizer.startListening(recognizerIntent);
}
@Override
public void onPartialResults(Bundle bundle) {
ArrayList<String> results = bundle.getStringArrayList(
SpeechRecognizer.RESULTS_RECOGNITION);
recognizedView.append("-"+results.toString() + " ");
}
@Override
public void onEvent(int i, Bundle bundle) {
}
public void muteSystemAudio(){
AudioManager audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
}
}
Dosyayı İndir