Libraryless. Click here for Pure Java version (234L/3K/8K).
1 | !747 |
2 | |
3 | import android.app.*; |
4 | import android.content.*; |
5 | import android.os.Bundle; |
6 | import android.view.View; |
7 | import android.view.View.OnClickListener; |
8 | import android.speech.RecognitionListener; |
9 | import android.speech.RecognizerIntent; |
10 | import android.speech.SpeechRecognizer; |
11 | import android.widget.Button; |
12 | import android.widget.TextView; |
13 | import android.util.Log; |
14 | import android.media.*; |
15 | |
16 | main { |
17 | static Activity androidContext; |
18 | |
19 | static SpeechRecognizer sr; |
20 | static final String TAG = "MyStt3Activity"; |
21 | static boolean loop = true; |
22 | static S language = "en-US"; |
23 | |
24 | p { |
25 | androidContext.runOnUiThread(runnable { |
26 | muteAudio(); |
27 | |
28 | sr = SpeechRecognizer.createSpeechRecognizer(androidContext); |
29 | sr.setRecognitionListener(new listener()); |
30 | go(); |
31 | }); |
32 | } |
33 | |
34 | static class listener implements RecognitionListener { |
35 | public void onReadyForSpeech(Bundle params) |
36 | { |
37 | print("onReadyForSpeech"); |
38 | } |
39 | public void onBeginningOfSpeech() |
40 | { |
41 | print("onBeginningOfSpeech"); |
42 | } |
43 | public void onRmsChanged(float rmsdB) |
44 | { |
45 | //print("onRmsChanged"); |
46 | } |
47 | public void onBufferReceived(byte[] buffer) |
48 | { |
49 | print("onBufferReceived"); |
50 | } |
51 | public void onEndOfSpeech() |
52 | { |
53 | print("onEndofSpeech"); |
54 | } |
55 | public void onError(int error) |
56 | { |
57 | print( "error " + error); |
58 | if (loop) go(); |
59 | } |
60 | public void onResults(Bundle results) |
61 | { |
62 | String str = new String(); |
63 | print("onResults " + results); |
64 | ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); |
65 | print("Results: " + structure(data)); |
66 | if (loop) go(); |
67 | } |
68 | public void onPartialResults(Bundle partialResults) |
69 | { |
70 | print("onPartialResults"); |
71 | } |
72 | public void onEvent(int eventType, Bundle params) |
73 | { |
74 | print("onEvent " + eventType); |
75 | } |
76 | } |
77 | |
78 | static void go() { |
79 | Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); |
80 | intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); |
81 | intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language); |
82 | intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test"); |
83 | |
84 | intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5); |
85 | sr.startListening(intent); |
86 | print("started listening"); |
87 | } |
88 | |
89 | static void muteAudio() { |
90 | AudioManager amanager = (AudioManager) androidContext.getSystemService(Context.AUDIO_SERVICE); |
91 | amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); |
92 | amanager.setStreamMute(AudioManager.STREAM_ALARM, true); |
93 | amanager.setStreamMute(AudioManager.STREAM_MUSIC, true); |
94 | amanager.setStreamMute(AudioManager.STREAM_RING, true); |
95 | amanager.setStreamMute(AudioManager.STREAM_SYSTEM, true); |
96 | } |
97 | } |
Began life as a copy of #1001130
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, ufhdzwgrioxs, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001131 |
Snippet name: | Android: Direct SpeechRecognizer test with muting & repeat, english (with error 8...) |
Eternal ID of this version: | #1001131/1 |
Text MD5: | afb21b68f0b57fa63d953e0e8e1619a8 |
Transpilation MD5: | 2b03627a5d38fac5226d3dcafa4824c5 |
Author: | stefan |
Category: | |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-10-05 14:32:37 |
Source code size: | 3354 bytes / 97 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 904 / 1283 |
Referenced in: | [show references] |