Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

71
LINES

< > BotCompany Repo | #1001129 // Android: Speech recognition test, trying muting the beep sound & endless looping

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (191L/2K/6K).

!747

import android.app.*;
import android.widget.*;
import android.view.*;
import android.view.View;
import android.view.KeyEvent;
import android.view.inputmethod.*;
import android.text.*;
import android.content.*;
import android.speech.*;
import android.media.*;

m {
  static Activity androidContext;
  static final int REQUEST_CODE = 1234;  
  static boolean loop = true;
 
  p {
    print("Muting audio (beep sound)");
    muteAudio();
    print("Starting voice recog");
    startVoiceRecognitionActivity();
    print("Starting done");
  }
  
  static void startVoiceRecognitionActivity() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
      RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
      "AndroidBite Voice Recognition...");
    androidContext.startActivityForResult(intent, REQUEST_CODE);
  }
 
  static void onActivityResult(int requestCode, int resultCode, Intent data) {
    print("onActivityResult");
    if (requestCode == REQUEST_CODE) {
      if (resultCode == Activity.RESULT_OK) {
        ArrayList<String> matches = data
          .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        /*resultList.setAdapter(new ArrayAdapter<string>(this,
         android.R.layout.simple_list_item_1, matches));*/
        print("Matches: " + structure(matches));
      } else {
        print("Result code: " + resultCode);
      }
      if (loop)
        startVoiceRecognitionActivity();
    }
    //super.onActivityResult(requestCode, resultCode, data);
  }
  
  static void muteAudio() {
    AudioManager amanager = (AudioManager) androidContext.getSystemService(Context.AUDIO_SERVICE);
    amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
    amanager.setStreamMute(AudioManager.STREAM_ALARM, true);
    amanager.setStreamMute(AudioManager.STREAM_MUSIC, true);
    amanager.setStreamMute(AudioManager.STREAM_RING, true);
    amanager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
  }
  
  static void unmuteAudio() {
    AudioManager amanager = (AudioManager) androidContext.getSystemService(Context.AUDIO_SERVICE);
    amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
    amanager.setStreamMute(AudioManager.STREAM_ALARM, false);
    amanager.setStreamMute(AudioManager.STREAM_MUSIC, false);
    amanager.setStreamMute(AudioManager.STREAM_RING, false);
    amanager.setStreamMute(AudioManager.STREAM_SYSTEM, false);
  }
}

Author comment

Began life as a copy of #1001128

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, nbgitpuheiab, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001129
Snippet name: Android: Speech recognition test, trying muting the beep sound & endless looping
Eternal ID of this version: #1001129/1
Text MD5: c6c241295caa3a35c0ae4d6577cf6ef8
Transpilation MD5: 0c0d453e4a6b6bbbf45d7363483cda7a
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-23 16:54:09
Source code size: 2585 bytes / 71 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1094 / 1076
Referenced in: [show references]