Libraryless. Click here for Pure Java version (234L/3K/8K).
!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 = "en-US"; p { androidContext.runOnUiThread(runnable { muteAudio(); 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); if (loop) go(); } public void onResults(Bundle results) { String str = new String(); print("onResults " + results); ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); print("Results: " + structure(data)); if (loop) 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,5); sr.startListening(intent); print("started listening"); } static void muteAudio() { AudioManager amanager = (AudioManager) androidContext.getSystemService(Context.AUDIO_SERVICE); amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); amanager.setStreamMute(AudioManager.STREAM_ALARM, true); amanager.setStreamMute(AudioManager.STREAM_MUSIC, true); amanager.setStreamMute(AudioManager.STREAM_RING, true); amanager.setStreamMute(AudioManager.STREAM_SYSTEM, true); } }
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: | 903 / 1281 |
Referenced in: | [show references] |