Android: Create Activity
in
Android Processing
•
10 months ago
Just curious if anyone has had any luck creating a separate activity in their Processing sketch. I'm trying to implement a library (the Nuance Speech SDK, in case you're curious) and it seems to require that their library be in an Activity. I've tried to implement it in a Thread and this didn't work (if anyone understands why this might be, I, Android newb, would love to hear more about it).
For reference, here's my Thread:
- class LooperThread extends Thread {
- public Handler mHandler;
- public Recognizer _currentRecognizer;
- Recognizer.Listener _listener;
- public LooperThread() {
- super();
- _listener = createListener();
- Looper.prepare();
- //_listener = createListener();
- //_currentRecognizer = null;
- //_listeningDialog = null;
- }
- public void run(SpeechKit sk)
- {
- println(" run ");
- mHandler = new Handler();
- _currentRecognizer = sk.createRecognizer(Recognizer.RecognizerType.Dictation, Recognizer.EndOfSpeechDetection.Short, "en_US", _listener, mHandler);
- _currentRecognizer.start();
- Looper.loop();
- }
- Recognizer.Listener createListener()
- {
- return new Recognizer.Listener()
- {
- @Override
- public void onRecordingBegin(Recognizer recognizer)
- {
- println("Recording...");
- // Create a repeating task to update the audio level
- Runnable r = new Runnable()
- {
- public void run()
- {
- if (_currentRecognizer != null)
- {
- //_listeningDialog.setLevel(Float.toString(_currentRecognizer.getAudioLevel()));
- mHandler.postDelayed(this, 500);
- }
- }
- };
- r.run();
- }
- @Override
- public void onRecordingDone(Recognizer recognizer)
- {
- println("Processing...");
- }
- @Override
- public void onError(Recognizer recognizer, SpeechError error)
- {
- if (recognizer != _currentRecognizer) return;
- //if (_listeningDialog.isShowing()) dismissDialog(LISTENING_DIALOG);
- _currentRecognizer = null;
- //_listeningDialog.setRecording(false);
- // Display the error + suggestion in the edit box
- String detail = error.getErrorDetail();
- String suggestion = error.getSuggestion();
- int code = error.getErrorCode();
- if (suggestion == null) {
- suggestion = "";
- }
- println(detail + " " + suggestion + " " + code);
- // for debugging purpose: printing out the speechkit session id
- println("Nuance SampleVoiceApp Recognizer.Listener.onError: session id [" + _speechKit.getSessionId() + "]");
- recognizer.stopRecording();
- }
- @Override
- public void onResults(Recognizer recognizer, Recognition results) {
- //if (_listeningDialog.isShowing()) dismissDialog(LISTENING_DIALOG);
- _currentRecognizer = null;
- //_listeningDialog.setRecording(false);
- int count = results.getResultCount();
- Recognition.Result [] rs = new Recognition.Result[count];
- for (int i = 0; i < count; i++)
- {
- rs[i] = results.getResult(i);
- }
- println(rs);
- // for debugging purpose: printing out the speechkit session id
- println("Nuance SampleVoiceApp Recognizer.Listener.onResults: session id [" + _speechKit.getSessionId() + "]");
- recognizer.stopRecording();
- }
- };
- }
- }
1