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

80
LINES

< > BotCompany Repo | #1001130 // Android: Direct SpeechRecognizer test

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

Libraryless. Click here for Pure Java version (211L/2K/7K).

!747

import android.app.Activity;
import android.content.Intent;
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;

main {
  static Activity androidContext;
  
  static SpeechRecognizer sr;
  static final String TAG = "MyStt3Activity";
   
  p {
    androidContext.runOnUiThread(runnable {
      sr = SpeechRecognizer.createSpeechRecognizer(androidContext);       
      sr.setRecognitionListener(new listener());        
      go();
    });
  }

  static class listener implements RecognitionListener {
            public void onReadyForSpeech(Bundle params)
            {
                     print("onReadyForSpeech");
            }
            public void onBeginningOfSpeech()
            {
                     print("onBeginningOfSpeech");
            }
            public void onRmsChanged(float rmsdB)
            {
                     //print("onRmsChanged");
            }
            public void onBufferReceived(byte[] buffer)
            {
                     print("onBufferReceived");
            }
            public void onEndOfSpeech()
            {
                     print("onEndofSpeech");
            }
            public void onError(int error)
            {
                     print( "error " +  error);
            }
            public void onResults(Bundle results)                   
            {
                     String str = new String();
                     print("onResults " + results);
                     ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
                     print("Results: " + structure(data));
            }
            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_CALLING_PACKAGE,"voice.recognition.test");

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

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: 602 / 614
Referenced in: [show references]