Libraryless. Click here for Pure Java version (211L/2K/7K).
1 | !747 |
2 | |
3 | import android.app.Activity; |
4 | import android.content.Intent; |
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 | |
15 | main {
|
16 | static Activity androidContext; |
17 | |
18 | static SpeechRecognizer sr; |
19 | static final String TAG = "MyStt3Activity"; |
20 | |
21 | p {
|
22 | androidContext.runOnUiThread(runnable {
|
23 | sr = SpeechRecognizer.createSpeechRecognizer(androidContext); |
24 | sr.setRecognitionListener(new listener()); |
25 | go(); |
26 | }); |
27 | } |
28 | |
29 | static class listener implements RecognitionListener {
|
30 | public void onReadyForSpeech(Bundle params) |
31 | {
|
32 | print("onReadyForSpeech");
|
33 | } |
34 | public void onBeginningOfSpeech() |
35 | {
|
36 | print("onBeginningOfSpeech");
|
37 | } |
38 | public void onRmsChanged(float rmsdB) |
39 | {
|
40 | //print("onRmsChanged");
|
41 | } |
42 | public void onBufferReceived(byte[] buffer) |
43 | {
|
44 | print("onBufferReceived");
|
45 | } |
46 | public void onEndOfSpeech() |
47 | {
|
48 | print("onEndofSpeech");
|
49 | } |
50 | public void onError(int error) |
51 | {
|
52 | print( "error " + error); |
53 | } |
54 | public void onResults(Bundle results) |
55 | {
|
56 | String str = new String(); |
57 | print("onResults " + results);
|
58 | ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); |
59 | print("Results: " + structure(data));
|
60 | } |
61 | public void onPartialResults(Bundle partialResults) |
62 | {
|
63 | print("onPartialResults");
|
64 | } |
65 | public void onEvent(int eventType, Bundle params) |
66 | {
|
67 | print("onEvent " + eventType);
|
68 | } |
69 | } |
70 | |
71 | static void go() {
|
72 | Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); |
73 | intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); |
74 | intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test"); |
75 | |
76 | intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5); |
77 | sr.startListening(intent); |
78 | print("started listening");
|
79 | } |
80 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cahelewubzku, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1001130 |
| Snippet name: | Android: Direct SpeechRecognizer test |
| Eternal ID of this version: | #1001130/1 |
| Text MD5: | 9f422eedd7d752a534b4c233088a215c |
| Transpilation MD5: | 5dc689452679e1147110324904351eb2 |
| Author: | stefan |
| Category: | |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-09-23 17:21:36 |
| Source code size: | 2654 bytes / 80 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 880 / 966 |
| Referenced in: | [show references] |