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

116
LINES

< > BotCompany Repo | #1001259 // Android: Direct SpeechRecognizer test with muting & repeat, fixed, german

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

Libraryless. Click here for Pure Java version (330L/3K/9K).

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 = "de-DE";
23  
  static int extraResults = 1;
24  
   
25  
  p {
26  
    androidContext.runOnUiThread(runnable {
27  
      androidMuteAudio(androidContext);
28  
      
29  
      makeNewObject();
30  
    });
31  
    sleep();
32  
  }
33  
  
34  
  static void makeNewObject() {
35  
    sr = SpeechRecognizer.createSpeechRecognizer(androidContext);
36  
    sr.setRecognitionListener(new listener());        
37  
    go();
38  
  }
39  
40  
  static class listener implements RecognitionListener {
41  
            public void onReadyForSpeech(Bundle params)
42  
            {
43  
                     print("SAG WAS.");
44  
            }
45  
            public void onBeginningOfSpeech()
46  
            {
47  
                     //print("LISTENING.");
48  
            }
49  
            public void onRmsChanged(float rmsdB)
50  
            {
51  
                     //print("onRmsChanged");
52  
            }
53  
            public void onBufferReceived(byte[] buffer)
54  
            {
55  
                     print("onBufferReceived");
56  
            }
57  
            public void onEndOfSpeech()
58  
            {
59  
                     //print("RECOGNIZING.");
60  
            }
61  
            public void onError(int error)
62  
            {
63  
                     //print( "error " +  error); // screw the errors!
64  
                     //if (loop) go();
65  
                     try {
66  
                       sr.destroy();
67  
                     } catch (Throwable e) {
68  
                       print(e);
69  
                     }
70  
                     if (loop)
71  
                       makeNewObject();
72  
            }
73  
            public void onResults(Bundle results)                   
74  
            {
75  
                     String str = new String();
76  
                     //print("onResults " + results);
77  
                     ArrayList<S> data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
78  
                     S bestMatch = data.get(0);
79  
                     print("I heard: " + quote(bestMatch));
80  
                     //print("I heard: " +structure(data));
81  
                
82  
                     // TODO: fix the java strings umlaut problem
83  
                     
84  
                     if (match3("goodbye", bestMatch) || match3("bye", bestMatch) || match3("tsch\u00fcss", bestMatch)) {
85  
                       print("\nGOODBYE!");
86  
                       sr.destroy();
87  
                       return;
88  
                     }
89  
                     
90  
                     if (loop) {
91  
                       sr.stopListening();
92  
                       go();
93  
                     }
94  
            }
95  
            public void onPartialResults(Bundle partialResults)
96  
            {
97  
                     print("onPartialResults");
98  
            }
99  
            public void onEvent(int eventType, Bundle params)
100  
            {
101  
                     print("onEvent " + eventType);
102  
            }
103  
   }
104  
   
105  
  static void go() {
106  
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);        
107  
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
108  
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
109  
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");
110  
111  
    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, extraResults); 
112  
    sr.startListening(intent);
113  
    //print("started listening");
114  
  }
115  
116  
}

Author comment

Began life as a copy of #1001252

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001259
Snippet name: Android: Direct SpeechRecognizer test with muting & repeat, fixed, german
Eternal ID of this version: #1001259/1
Text MD5: 5d3502a6d2de37490008b2c434e4ecc9
Transpilation MD5: 8332f4ff3076f370ed907f17a21405ac
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-06 12:59:15
Source code size: 3892 bytes / 116 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 609 / 605
Referenced in: [show references]