コード例 #1
0
        /// <summary>
        /// Create new Yandex SpeechKit Cloud API client.
        /// </summary>
        /// <param name="speechKitClientOptions">API client options..</param>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public SpeechKitClient(SpeechKitClientOptions speechKitClientOptions)
        {
            if (speechKitClientOptions == null)
            {
                throw new ArgumentNullException(nameof(speechKitClientOptions));
            }

            _apiKey = speechKitClientOptions.ApiKey;
            _userId = speechKitClientOptions.UserId;
        }
        /// <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));
        }