Example #1
0
 public static void Main(string[] args)
 {
     using (var p = Pipeline.Create())
     {
         //var myConsumer = new MyConsumer(p);
         var myConsumer = new SocketStringConsumer(p, "localhost", 9000, 8099);
         var s = Generators.Repeat(p, "Test", 10);
         s.PipeTo(myConsumer.In);
         p.Run();
         Console.ReadKey(true);
     }
 }
        /// <summary>
        /// Builds and runs a speech recognition pipeline using the .NET System.Speech recognizer and a set of fixed grammars.
        /// </summary>
        /// <param name="outputLogPath">The path under which to write log data.</param>
        /// <param name="inputLogPath">The path from which to read audio input data.</param>
        /// <param name="showLiveVisualization">A flag indicating whether to display live data in PsiStudio as the pipeline is running.</param>
        public static void RunSystemSpeech(string outputLogPath = null, string inputLogPath        = null, bool showLiveVisualization = true,
                                           string facilitatorIP = "localhost", int facilitatorPort = 9000, int localPort              = 8090)
        {
            // Create the pipeline object.
            using (Pipeline pipeline = Pipeline.Create())
            {
                // Needed only for live visualization
                DateTime startTime = DateTime.Now;

                // Use either live audio from the microphone or audio from a previously saved log
                IProducer <AudioBuffer> audioInput = null;
                if (inputLogPath != null)
                {
                    // Open the MicrophoneAudio stream from the last saved log
                    var store = Store.Open(pipeline, Program.AppName, inputLogPath);
                    audioInput = store.OpenStream <AudioBuffer>($"{Program.AppName}.MicrophoneAudio");

                    // Get the originating time of the start of the data in the store. We will use this
                    // to set the correct start time in the visualizer (if live visualization is on).
                    startTime = store.OriginatingTimeInterval.Left;
                }
                else
                {
                    // Create the AudioSource component to capture audio from the default device in 16 kHz 1-channel
                    // PCM format as required by both the voice activity detector and speech recognition components.
                    audioInput = new AudioSource(pipeline, new AudioSourceConfiguration()
                    {
                        OutputFormat = WaveFormat.Create16kHz1Channel16BitPcm()
                    });
                }

                // Create System.Speech recognizer component
                var recognizer = CreateSpeechRecognizer(pipeline);

                // Subscribe the recognizer to the input audio
                audioInput.PipeTo(recognizer);

                // Partial and final speech recognition results are posted on the same stream. Here
                // we use Psi's Where() operator to filter out only the final recognition results.
                var finalResults = recognizer.Out.Where(result => result.IsFinal);
                finalResults.Do(x => Console.WriteLine(x));
                //KioskUI.KioskUI ui = new KioskUI.KioskUI(pipeline);
                //SystemSpeechSynthesizer speechSynth = CreateSpeechSynthesizer(pipeline);
                KioskInputTextPreProcessor preproc = new NU.Kqml.KioskInputTextPreProcessor(pipeline, (SystemSpeechRecognizer)recognizer);

                finalResults.PipeTo(preproc.In);
                preproc.Out.Do(x => Console.WriteLine($"Processed: {x}"));

                //preproc.Out.PipeTo(ui.UserInput);
                if (facilitatorIP != "none")
                {
                    python = new SocketStringConsumer(pipeline, facilitatorIP, facilitatorPort, localPort);
                    //preproc.Out.PipeTo(ui.UserInput);
                    //python.Out.PipeTo(ui.CompResponse);
                    //python.Out.PipeTo(speechSynth);
                }
                else
                {
                    //preproc.Out.PipeTo(ui.CompResponse);
                    //preproc.Out.PipeTo(speechSynth);
                }
                //speechSynth.SpeakCompleted.Do(x => preproc.setAccepting());

                // Create a data store to log the data to if necessary. A data store is necessary
                // only if output logging or live visualization are enabled.
                var dataStore = CreateDataStore(pipeline, outputLogPath, showLiveVisualization);

                // For disk logging or live visualization only
                if (dataStore != null)
                {
                    // Log the microphone audio and recognition results
                    audioInput.Write($"{Program.AppName}.MicrophoneAudio", dataStore);
                    finalResults.Write($"{Program.AppName}.FinalRecognitionResults", dataStore);
                }

                // Register an event handler to catch pipeline errors
                pipeline.PipelineCompletionEvent += PipelineCompletionEvent;

                // Run the pipeline
                pipeline.RunAsync();

                Console.WriteLine("Press any key to exit...");
                Console.ReadKey(true);
            }
        }