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).

!747

import android.app.*;
import android.content.*;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.widget.Button;
import android.widget.TextView;
import android.util.Log;
import android.media.*;

main {
  static Activity androidContext;
  
  static SpeechRecognizer sr;
  static final String TAG = "MyStt3Activity";
  static boolean loop = true;
  static S language = "de-DE";
  static int extraResults = 1;
   
  p {
    androidContext.runOnUiThread(runnable {
      androidMuteAudio(androidContext);
      
      makeNewObject();
    });
    sleep();
  }
  
  static void makeNewObject() {
    sr = SpeechRecognizer.createSpeechRecognizer(androidContext);
    sr.setRecognitionListener(new listener());        
    go();
  }

  static class listener implements RecognitionListener {
            public void onReadyForSpeech(Bundle params)
            {
                     print("SAG WAS.");
            }
            public void onBeginningOfSpeech()
            {
                     //print("LISTENING.");
            }
            public void onRmsChanged(float rmsdB)
            {
                     //print("onRmsChanged");
            }
            public void onBufferReceived(byte[] buffer)
            {
                     print("onBufferReceived");
            }
            public void onEndOfSpeech()
            {
                     //print("RECOGNIZING.");
            }
            public void onError(int error)
            {
                     //print( "error " +  error); // screw the errors!
                     //if (loop) go();
                     try {
                       sr.destroy();
                     } catch (Throwable e) {
                       print(e);
                     }
                     if (loop)
                       makeNewObject();
            }
            public void onResults(Bundle results)                   
            {
                     String str = new String();
                     //print("onResults " + results);
                     ArrayList<S> data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
                     S bestMatch = data.get(0);
                     print("I heard: " + quote(bestMatch));
                     //print("I heard: " +structure(data));
                
                     // TODO: fix the java strings umlaut problem
                     
                     if (match3("goodbye", bestMatch) || match3("bye", bestMatch) || match3("tsch\u00fcss", bestMatch)) {
                       print("\nGOODBYE!");
                       sr.destroy();
                       return;
                     }
                     
                     if (loop) {
                       sr.stopListening();
                       go();
                     }
            }
            public void onPartialResults(Bundle partialResults)
            {
                     print("onPartialResults");
            }
            public void onEvent(int eventType, Bundle params)
            {
                     print("onEvent " + eventType);
            }
   }
   
  static void go() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);        
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");

    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, extraResults); 
    sr.startListening(intent);
    //print("started listening");
  }

}

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: 681 / 693
Referenced in: #1001276 - Unterhaltung
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)