private void handleSpeechToText(HttpServletRequest request) {
    String speechContext = request.getParameter("SpeechContext");
    request.setAttribute("mimeData", getMimeData());
    request.getSession().setAttribute("sessionmimeData", getMimeData());

    if (request.getParameter("SpeechToText") == null) {
      if (speechContext != null) {
        request.getSession().setAttribute("sessionContextName", speechContext);
      } else {
        request.getSession().setAttribute("sessionContextName", "GenericHints");
      }
      return;
    }

    try {
      HttpSession session = request.getSession();
      String xarg = cfg.getProperty("xArg");

      session.setAttribute("sessionContextName", speechContext);

      String endpoint = cfg.getFQDN() + cfg.getProperty("contextPath");
      SpeechService srvc = new SpeechService(getRESTConfig(endpoint));

      String fname = request.getParameter("audio_file");
      session.setAttribute("sessionFileName", fname);

      String audioFolder = cfg.getProperty("audioFolder");
      File file = new File(getPath() + audioFolder + "/" + fname);

      String[] attachments = new String[3];
      attachments[0] =
          new File(getPath() + "/" + cfg.getProperty("GenericHints.template")).getAbsolutePath();
      attachments[1] =
          new File(getPath() + "/" + cfg.getProperty("GrammarList.template")).getAbsolutePath();
      attachments[2] = file.getAbsolutePath();

      String mimeData = this.templateContent.get(speechContext);
      session.setAttribute("sessionmimeData", mimeData);

      OAuthToken token = getToken();
      SpeechResponse response =
          srvc.sendRequest(attachments, token.getAccessToken(), speechContext, xarg);

      request.setAttribute("resultSpeech", response.getResult());
    } catch (Exception e) {
      e.printStackTrace();
      request.setAttribute("errorSpeech", e.getMessage());
    }
  }