Exemplo n.º 1
0
        /// <summary>
        /// Capture intent and entities from a text string
        /// </summary>
        /// <param name="text">Text string to capture from</param>
        /// <returns>Captured data</returns>
        public async Task <WitResponse> CaptureTextIntent(string text)
        {
            WitMessageRequestTask witMessageRequestTask = new WitMessageRequestTask(accessToken, text);

            string result = await witMessageRequestTask.GetAsync();

            if (result != null)
            {
                WitResponse witResponse = JsonConvert.DeserializeObject <WitResponse>(result);

                return(witResponse);
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Streams raw audio data and returns captured intent and entities
        /// </summary>
        /// <param name="witPipedStream">Audio stream</param>
        /// <param name="type">Type</param>
        /// <param name="encoding">Encoding</param>
        /// <param name="bits">Bits per sample</param>
        /// <param name="rate">Samples per second</param>
        /// <param name="order">Bytes order</param>
        /// <returns>Captured data</returns>
        public async Task <WitResponse> StreamRawAudio(WitPipedStream witPipedStream, string type, string encoding, int bits, int rate, ByteOrder order)
        {
            WitSpeechRequestTask witSpeechRequestTask = new WitSpeechRequestTask(accessToken, witPipedStream, type, encoding, bits, rate, order);

            string result = await witSpeechRequestTask.UploadAsync();

            if (result != null)
            {
                WitResponse witResponse = JsonConvert.DeserializeObject <WitResponse>(result);

                return(witResponse);
            }

            return(null);
        }
        private async void MicButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (AccessToken == null)
            {
                WitLog.Log("WitMicButton", "Did you set your AccessToken propeply?");

                return;
            }

            IsToggled = !IsToggled;

            if (IsToggled)
            {
                if (CaptureVoiceIntentStarted != null)
                {
                    CaptureVoiceIntentStarted(this, EventArgs.Empty);
                }

                wit = new Wit(AccessToken, DetectSpeechStop);

                WitResponse witResponse = await wit.CaptureVoiceIntent();

                IsToggled = false;

                if (CaptureVoiceIntentCompleted != null)
                {
                    CaptureVoiceIntentCompleted(this, witResponse);
                }
            }
            else
            {
                if (wit != null)
                {
                    wit.StopCaptureVoiceIntent();
                }

                if (CaptureVoiceIntentStopped != null)
                {
                    CaptureVoiceIntentStopped(this, EventArgs.Empty);
                }
            }
        }