private synchronized void doRecognize(
      final Recognizer.Listener callback,
      int endOfSpeechRecognitionMode,
      boolean isNoStartPrompt,
      boolean isNoStopPrompt) {

    // "singleton" recognition: only one recognition process at a time is allowed
    //							--> ensure all previous processes are stopped.
    if (_currentRecognitionHandler != null && _currentRecognizer != null) {
      _currentRecognizer.cancel();
    }
    _currentRecognitionHandler = callback;

    _currentRecognizer =
        _speechKit.createRecognizer(
            Recognizer.RecognizerType.Dictation,
            endOfSpeechRecognitionMode,
            _currentLanguage,
            _recognitionListener,
            _handler);

    if (isNoStartPrompt) {
      _currentRecognizer.setPrompt(Recognizer.PromptType.RECORDING_START, null);
    }

    if (isNoStopPrompt) {
      _currentRecognizer.setPrompt(Recognizer.PromptType.RECORDING_STOP, null);
    }

    _currentRecognizer.start();
  }
  public void releaseResources() {
    if (_speechKit != null) {

      if (_currentRecognitionHandler != null) {

        // if there is currently a callback-handler set: "simulate" a cancel event, notifying the
        // callback that it
        //												the speech engine is about to release its resources

        _currentRecognitionHandler.onError(
            _currentRecognizer,
            new SpeechError() {
              @Override
              public String getSuggestion() {
                return "Re-initialize the engine and its resources";
              }

              @Override
              public String getErrorDetail() {
                return "Resources are getting released";
              }

              @Override
              public int getErrorCode() {
                // simulate canceled
                return 5;
              }
            });
      }

      _speechKit.release();

      _currentRecognizer = null;
      _currentRecognitionHandler = null;

      _recognitionListener = null;
      _vocalizer = null;
      _speechKit = null;
      _handler = null;
    }

    if (this._defaultStartPrompt != null) {
      this._defaultStartPrompt.release();
      this._defaultStartPrompt = null;
    }

    if (this._defaultStopPrompt != null) {
      this._defaultStopPrompt.release();
      this._defaultStopPrompt = null;
    }
  }
  private Prompt createDefaultStartPrompt() {

    if (this._speechKit != null) {
      int beepResId =
          _context
              .getResources()
              .getIdentifier("rawbeep", "raw", _context.getApplicationInfo().packageName);
      return _speechKit.defineAudioPrompt(beepResId);
    } else {
      Log.e(
          PLUGIN_NAME,
          "Cannot create Start Prompt: SpeechKit not initialized, returning default prompt [NONE]...");
    }
    return null;
  }
  public void initializeResources() {
    if (_speechKit != null) {
      return;
    }

    _speechKit =
        SpeechKit.initialize(
            _context,
            Credentials.getSpeechKitAppId(),
            Credentials.getSpeechKitServer(),
            Credentials.getSpeechKitPort(), // the port number, e.g. 443,
            Credentials.getSpeechKitSsl(), // true if SSL should be used,
            Credentials
                .getSpeechKitCertSummary(), // the summary String (must match the Common Name (CN)
            // of the used certificate-data; as provided by Nuance)
            Credentials.getSpeechKitCertData(), // the certificate data,
            Credentials.getSpeechKitAppKey());

    _speechKit.connect();
    int beepResId =
        _context
            .getResources()
            .getIdentifier("rawbeep", "raw", _context.getApplicationInfo().packageName);

    // TODO: Keep an eye out for audio prompts not-working on the Android 2 or other 2.2 devices.
    this._defaultStartPrompt = _speechKit.defineAudioPrompt(beepResId);
    this._defaultStopPrompt = Prompt.vibration(100);

    _speechKit.setDefaultRecognizerPrompts(
        this._defaultStartPrompt, this._defaultStopPrompt, null, null);

    // Create Vocalizer listener
    Vocalizer.Listener vocalizerListener =
        new Vocalizer.Listener() {
          @Override
          public void onSpeakingBegin(Vocalizer vocalizer, String text, Object context) {
            Log.d(PLUGIN_TTS_NAME, String.format("start speaking: '%s'", text));

            if (context instanceof Vocalizer.Listener) {
              ((Vocalizer.Listener) context).onSpeakingBegin(vocalizer, text, null);
            }
          }

          @Override
          public void onSpeakingDone(
              Vocalizer vocalizer, String text, SpeechError error, Object context) {
            // Use the context to determine if this was the final TTS phrase
            Log.d(PLUGIN_TTS_NAME, String.format("speaking done: '%s'", text));

            if (context instanceof Vocalizer.Listener) {
              ((Vocalizer.Listener) context).onSpeakingDone(vocalizer, text, error, null);
            }
          }
        };

    // Create a single Vocalizer here.
    _vocalizer =
        _speechKit.createVocalizerWithLanguage(_currentLanguage, vocalizerListener, new Handler());
    _recognitionListener = createRecognitionListener();
    _handler = new Handler();
  }