示例#1
0
        private async void processData()
        {
            // First, convert our list of audio chunks into a flattened single array
            float[] rawData = flattenList(recordedAudio);

            // Once we've done that, we can clear this out no problem
            recordedAudio.Clear();

            // Next, convert the data into FLAC:
            byte[] flacData = null;
            flacData = lf.compressAudio(rawData, sio.getInputSampleRate(), sio.getInputNumChannels());

            // Upload it to the server and get a response!
            RecognitionResult result = await recognizeSpeech(flacData, sio.getInputSampleRate());

            // Check to make sure everything went okay, if it didn't, check the debug log!
            if (result.result.Count != 0)
            {
                // This is just some fancy code to display each hypothesis as sone text that gets redder
                // as our confidence goes down; note that I've never managed to get multiple hypotheses
                this.textOutTranscript.Inlines.Clear();
                foreach (var alternative in result.result[0].alternative)
                {
                    Run run = new Run();
                    run.Text = alternative.transcript + "\n\n";
                    byte bg = (byte)(alternative.confidence * 255);
                    run.Foreground = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, bg, bg));
                    textOutTranscript.Inlines.Add(run);
                }
            }
            else
            {
                textOutTranscript.Text = "Errored out!";
            }
        }
示例#2
0
        private void startStopButton_Click(object sender, RoutedEventArgs e)
        {
            if (startStopButton.Content.Equals("Start"))
            {
                // Start the audio source running
                sio.start();

                // Output debugging info
                textOutput.Text  = "Sound Parameters:\n";
                textOutput.Text += "Input: " + sio.getInputNumChannels() +
                                   " channels at " + sio.getInputSampleRate() / 1000.0 +
                                   " KHz, " + sio.getInputBitdepth() + " bits per sample\n";
                textOutput.Text += "Output: " + sio.getOutputNumChannels() +
                                   " channels at " + sio.getOutputSampleRate() / 1000.0 +
                                   " KHz, " + sio.getOutputBitdepth() + " bits per sample\n";

                startStopButton.Content = "Stop";
            }
            else
            {
                sio.stop();
                textOutput.Text         = "Sound Stopped";
                startStopButton.Content = "Start";
            }
        }