Пример #1
0
        internal SpeechRecognitionSession(
            string applicationName,
            string apiKey,
            Guid userId,
            string device,
            SpeechRecognitionSessionOptions options,
            int timeout)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _apiKey = apiKey;
            UserId  = userId;
            Device  = device;

            ConnectionMode     = options.ConnectionMode;
            SpeechModel        = options.SpeechModel;
            AudioFormat        = options.AudioFormat;
            Language           = options.Language;
            BiometryParameters = options.BiometryParameters;
            _applicationName   = applicationName;
            Position           = options.Position;

            _tcpClient = new TcpClient
            {
                Client =
                {
                    SendTimeout    = timeout,
                    ReceiveTimeout = timeout
                }
            };
        }
        /// <summary>
        /// Start new speech recognition session in data streaming mode.
        /// </summary>
        /// <param name="apiOptions">API access options.</param>
        /// <param name="sessionOptions">Recognition settings.</param>
        /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
        /// <returns></returns>
        public static Task <StartSessionResult> CreateNewSpeechRecognitionSessionAsync(
            SpeechKitClientOptions apiOptions,
            SpeechRecognitionSessionOptions sessionOptions,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (apiOptions == null)
            {
                throw new ArgumentNullException(nameof(apiOptions));
            }
            if (sessionOptions == null)
            {
                throw new ArgumentNullException(nameof(sessionOptions));
            }

            var session = new SpeechRecognitionSession(
                apiOptions.ApplicationName,
                apiOptions.ApiKey,
                apiOptions.UserId,
                apiOptions.Device,
                sessionOptions,
                apiOptions.Timeout);

            return(session.StartAsync(cancellationToken));
        }