/// <summary>
        /// Creates a session and locks recognition requests to that engine. You can use the session for multiple recognition requests so that each request is processed with the same Speech to Text engine. The session expires after 30 seconds of inactivity. For information about avoiding session timeouts, see Timeouts (https://console.bluemix.net/docs/services/speech-to-text/input.html#timeouts).
        ///
        /// The method returns a cookie in the Set-Cookie response header.You must pass this cookie with each request that uses the session. For more information, see Using cookies with sessions (https://console.bluemix.net/docs/services/speech-to-text/http.html#cookies).
        /// </summary>
        /// <param name="model">The identifier of the model that is to be used by the new session.</param>
        /// <param name="customizationId">The GUID of a custom language model that is to be used with the new session. The base model of the specified custom language model must match the model specified with the model parameter. You must make the request with service credentials created for the instance of the service that owns the custom model. By default, no custom language model is used.</param>
        /// <param name="acousticCustomizationId">The GUID of a custom acoustic model that is to be used with the new session. The base model of the specified custom acoustic model must match the model specified with the model parameter. You must make the request with service credentials created for the instance of the service that owns the custom model. By default, no custom acoustic model is used.</param>
        /// <param name="baseModelVersion">The version of the specified base model that is to be used with the new session. Multiple versions of a base model can exist when a model is updated for internal improvements. The parameter is intended primarily for use with custom models that have been upgraded for a new base model. The default value depends on whether the parameter is used with or without a custom model. For more information, see Base model version (https://console.bluemix.net/docs/services/speech-to-text/input.html#version).</param>
        /// <returns>The created session</returns>
        public SpeechSession CreateSession(string model, string customizationId = null, string acousticCustomizationId = null, string baseModelVersion = null)
        {
            SpeechSession result = null;

            try
            {
                if (string.IsNullOrEmpty(model))
                {
                    throw new ArgumentNullException(nameof(model));
                }

                IRequest restRequest = null;
                IClient  client;
                if (_tokenManager == null)
                {
                    client = this.Client.WithAuthentication(this.UserName, this.Password);
                }
                else
                {
                    client = this.Client.WithAuthentication(_tokenManager.GetToken());
                }

                restRequest = client.PostAsync($"{this.Endpoint}/v1/sessions");
                restRequest.WithArgument("model", model);
                if (!string.IsNullOrEmpty(customizationId))
                {
                    restRequest.WithArgument("customization_id", customizationId);
                }
                if (!string.IsNullOrEmpty(acousticCustomizationId))
                {
                    restRequest.WithArgument("acoustic_customization_id", acousticCustomizationId);
                }
                if (!string.IsNullOrEmpty(baseModelVersion))
                {
                    restRequest.WithArgument("base_model_version", baseModelVersion);
                }
                restRequest.WithHeader("accept", HttpMediaType.APPLICATION_JSON);
                result = restRequest.As <SpeechSession>().Result;
            }
            catch (AggregateException ae)
            {
                throw ae.InnerException as ServiceResponseException;
            }

            return(result);
        }
 /// <summary>
 /// Deletes an existing session and its engine. The request must pass the cookie that was returned by the Create a session method. You cannot send requests to a session after it is deleted. By default, a session expires after 30 seconds of inactivity if you do not delete it first.
 /// </summary>
 /// <param name="session">The session to be deleted.</param>
 /// <returns></returns>
 public object DeleteSession(SpeechSession session)
 {
     return(this.DeleteSession(session.SessionId));
 }
 /// <summary>
 /// Checks whether a specified session can accept another recognition request. Concurrent recognition tasks during the same session are not allowed. The method blocks until the session is in the initialized state to indicate that you can send another recognition request. The request must pass the cookie that was returned by the Create a session method.
 /// </summary>
 /// <param name="session">The session to get.</param>
 /// <returns></returns>
 public SessionStatus GetSessionStatus(SpeechSession session)
 {
     return(this.GetSessionStatus(session.SessionId));
 }