Libraryless. Click here for Pure Java version (191L/2K/6K).
1 | !747 |
2 | |
3 | import android.app.*; |
4 | import android.widget.*; |
5 | import android.view.*; |
6 | import android.view.View; |
7 | import android.view.KeyEvent; |
8 | import android.view.inputmethod.*; |
9 | import android.text.*; |
10 | import android.content.*; |
11 | import android.speech.*; |
12 | import android.media.*; |
13 | |
14 | m {
|
15 | static Activity androidContext; |
16 | static final int REQUEST_CODE = 1234; |
17 | static boolean loop = true; |
18 | |
19 | p {
|
20 | print("Muting audio (beep sound)");
|
21 | muteAudio(); |
22 | print("Starting voice recog");
|
23 | startVoiceRecognitionActivity(); |
24 | print("Starting done");
|
25 | } |
26 | |
27 | static void startVoiceRecognitionActivity() {
|
28 | Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); |
29 | intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, |
30 | RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); |
31 | intent.putExtra(RecognizerIntent.EXTRA_PROMPT, |
32 | "AndroidBite Voice Recognition..."); |
33 | androidContext.startActivityForResult(intent, REQUEST_CODE); |
34 | } |
35 | |
36 | static void onActivityResult(int requestCode, int resultCode, Intent data) {
|
37 | print("onActivityResult");
|
38 | if (requestCode == REQUEST_CODE) {
|
39 | if (resultCode == Activity.RESULT_OK) {
|
40 | ArrayList<String> matches = data |
41 | .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); |
42 | /*resultList.setAdapter(new ArrayAdapter<string>(this, |
43 | android.R.layout.simple_list_item_1, matches));*/ |
44 | print("Matches: " + structure(matches));
|
45 | } else {
|
46 | print("Result code: " + resultCode);
|
47 | } |
48 | if (loop) |
49 | startVoiceRecognitionActivity(); |
50 | } |
51 | //super.onActivityResult(requestCode, resultCode, data); |
52 | } |
53 | |
54 | static void muteAudio() {
|
55 | AudioManager amanager = (AudioManager) androidContext.getSystemService(Context.AUDIO_SERVICE); |
56 | amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); |
57 | amanager.setStreamMute(AudioManager.STREAM_ALARM, true); |
58 | amanager.setStreamMute(AudioManager.STREAM_MUSIC, true); |
59 | amanager.setStreamMute(AudioManager.STREAM_RING, true); |
60 | amanager.setStreamMute(AudioManager.STREAM_SYSTEM, true); |
61 | } |
62 | |
63 | static void unmuteAudio() {
|
64 | AudioManager amanager = (AudioManager) androidContext.getSystemService(Context.AUDIO_SERVICE); |
65 | amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false); |
66 | amanager.setStreamMute(AudioManager.STREAM_ALARM, false); |
67 | amanager.setStreamMute(AudioManager.STREAM_MUSIC, false); |
68 | amanager.setStreamMute(AudioManager.STREAM_RING, false); |
69 | amanager.setStreamMute(AudioManager.STREAM_SYSTEM, false); |
70 | } |
71 | } |
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: | 1404 / 1442 |
| Referenced in: | [show references] |