Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- returnedText = (TextView) findViewById(R.id.textView1);
- progressBar = (ProgressBar) findViewById(R.id.progressBar1);
- toggleButton = (ToggleButton) findViewById(R.id.toggleButton1);
- progressBar.setVisibility(View.INVISIBLE);
- speech = SpeechRecognizer.createSpeechRecognizer(this);
- speech.setRecognitionListener(this);
- recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
- recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,
- "en");
- recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
- this.getPackageName());
- recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
- RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
- recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
- toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView,
- boolean isChecked) {
- if (isChecked) {
- progressBar.setVisibility(View.VISIBLE);
- progressBar.setIndeterminate(true);
- speech.startListening(recognizerIntent);
- } else {
- progressBar.setIndeterminate(false);
- progressBar.setVisibility(View.INVISIBLE);
- speech.stopListening();
- }
- }
- });
- ttsManager = new TTSManager();
- ttsManager.init(this);
- Pause = (Button) findViewById(R.id.pause);
- Stop = (Button) findViewById(R.id.stop);
- Resume = (Button) findViewById(R.id.resume);
- Pause.setVisibility(View.INVISIBLE);
- Resume.setVisibility(View.INVISIBLE);
- Stop.setVisibility(View.INVISIBLE);
- // -------------------------------------
- //----------------------------------------
- handler = new android.os.Handler() {
- public void handleMessage(android.os.Message msg) {
- switch (msg.what) {
- case RECIEVE_MESSAGE: // if receive massage
- byte[] readBuf = (byte[]) msg.obj;
- String strIncom = new String(readBuf, 0, msg.arg1); // create string from bytes array
- sb.append(strIncom); // append string
- int endOfLineIndex = sb.indexOf("rn"); // determine the end-of-line
- if (endOfLineIndex > 0) { // if end-of-line,
- String sbprint = sb.substring(0, endOfLineIndex); // extract string
- sb.delete(0, sb.length()); // and clear
- Log.e("TAG", sbprint);
- if(sbprint.contains("ello")){
- progressBar.setVisibility(View.VISIBLE);
- progressBar.setIndeterminate(true);
- speech.startListening(recognizerIntent);
- toggleButton.setChecked(true);
- }
- }
- //Log.d(TAG, "...String:"+ sb.toString() + "Byte:" + msg.arg1 + "...");
- break;
- }
- };
- };
- btAdapter = BluetoothAdapter.getDefaultAdapter(); // get Bluetooth adapter
- checkBTState();
- //--------------------------------------
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement