コード例 #1
0
        /// <summary>
        /// Asynchronously add constraint in speech recognizer
        /// </summary>
        public async Task <SpeechRecognitionCompilationResult> AddConstraintAsync(ISpeechRecognitionConstraint constraint, bool compile = true)
        {
            if (SpeechRecognizer.State != SpeechRecognizerState.Idle)
            {
                Debug.WriteLine($"STTService Failed to add constraint because of speech recognizer state : {SpeechRecognizer.State}");
                return(null);
            }

            SpeechRecognizer.Constraints.Add(constraint);

            if (!compile)
            {
                return(null);
            }

            return(await SpeechRecognizer.CompileConstraintsAsync());
        }
コード例 #2
0
        async Task StartListeningForConstraintAsync(
            ISpeechRecognitionConstraint constraint)
        {
            if (this.speechRecognizer == null)
            {
                this.speechRecognizer = new SpeechRecognizer();

                this.speechRecognizer.ContinuousRecognitionSession.ResultGenerated
                    += OnSpeechResult;
            }
            else
            {
                await this.speechRecognizer.ContinuousRecognitionSession.StopAsync();
            }
            this.speechRecognizer.Constraints.Clear();

            this.speechRecognizer.Constraints.Add(constraint);

            await this.speechRecognizer.CompileConstraintsAsync();

            await this.speechRecognizer.ContinuousRecognitionSession.StartAsync();
        }
コード例 #3
0
    async Task StartListeningForConstraintAsync(
      ISpeechRecognitionConstraint constraint)
    {
      if (this.speechRecognizer == null)
      {
        this.speechRecognizer = new SpeechRecognizer();

        this.speechRecognizer.ContinuousRecognitionSession.ResultGenerated
          += OnSpeechResult;
      }
      else
      {
        await this.speechRecognizer.ContinuousRecognitionSession.StopAsync();
      }
      this.speechRecognizer.Constraints.Clear();

      this.speechRecognizer.Constraints.Add(constraint);

      await this.speechRecognizer.CompileConstraintsAsync();

      await this.speechRecognizer.ContinuousRecognitionSession.StartAsync();
    }