Exemplo n.º 1
0
        public override bool SynthesizeAsync(string content, string fileName = null)
        {
            if (fileName == null)
            {
                OutputMode = OutputMode.扬声器;
                NativeSynthesizer.SetOutputToDefaultAudioDevice();
            }
            else
            {
                OutputMode = OutputMode.文件;
                NativeSynthesizer.SetOutputToWaveFile(fileName);
            }

            Task.Run(() =>
            {
                SynthesizerState = SynthesizerState.合成;

                NativeSynthesizer.Speak(content);

                SynthesizerState = SynthesizerState.空闲;
            });

            this.Info("合成:" + content);

            return(true);
        }
Exemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();

            // Initialize a new instance of the SpeechSynthesizer.
            _synth = new SpeechSynthesis.SpeechSynthesizer();
            // Configure the audio output.
            _synth.SetOutputToDefaultAudioDevice();

            var installedVoices = _synth.GetInstalledVoices();

            this.AllowDrop  = true;
            this.DragEnter += new DragEventHandler(Form1_DragEnter);
            this.DragDrop  += new DragEventHandler(Form1_DragDrop);

            _voices = new List <string>();
            _voices.AddRange(installedVoices.Select(x =>
                                                    $"{x.VoiceInfo.Name}# {x.VoiceInfo.Gender} {x.VoiceInfo.Culture}"));
            comboBoxVoices.DataSource = _voices;

            var wordVersion = IsWordInteropInstalled();

            if (wordVersion != null)
            {
                toolStripStatusLabel1.Text = $"Word interpop found: {wordVersion}";
            }
            else
            {
                toolStripStatusLabel1.Text = "Warning: Word interop not found";
            }

            Text = $"Test Speech {Assembly.GetExecutingAssembly().GetName().Version.ToString()}";

            // notifyIcon1.ContextMenu = contextMenuStrip1;
        }
        private void SetCurrentText(TextBlock textBlock, string text)
        {
            this.Dispatcher.Invoke(() =>
            {
                textBlock.Text = text;
                if (textBlock.Text == "What's the weather like?")
                {
                    customModelCurrentText.Text = "The weather is hot";
                    // Initialize a new instance of the SpeechSynthesizer.
                    System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer();

                    // Configure the audio output.
                    synth.SetOutputToDefaultAudioDevice();

                    // Speak a string asynchronously.
                    synth.SpeakAsync("The weather is hot");
                }
                else if (textBlock.Text == "What is the best University?")
                {
                    customModelCurrentText.Text = "It's National Central University!";
                    // Initialize a new instance of the SpeechSynthesizer.
                    System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer();

                    // Configure the audio output.
                    synth.SetOutputToDefaultAudioDevice();

                    // Speak a string asynchronously.
                    synth.SpeakAsync("It's National Central University!");
                }
                else if (textBlock.Text == "What is your name?")
                {
                    customModelCurrentText.Text = "My name is Vando";
                    // Initialize a new instance of the SpeechSynthesizer.
                    System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer();

                    // Configure the audio output.
                    synth.SetOutputToDefaultAudioDevice();

                    // Speak a string asynchronously.
                    synth.SpeakAsync("My name is Vando");
                }
                else
                {
                    customModelCurrentText.Text = "....???";
                }
            });
        }
Exemplo n.º 4
0
        public void BeginLoop()
        {
            synth.SetOutputToDefaultAudioDevice();
            Choices commands = new Choices();

            commands.Add("left", "left 45", "right", "right 45", "forward", "reverse", "stop", "turn around");
            GrammarBuilder grammarBuilder = new GrammarBuilder();

            grammarBuilder.Append(commands);

            Grammar g = new Grammar(grammarBuilder);

            recognizer.LoadGrammar(g);

            //recognizer.SpeechRecognized += voiceCommandRecognizedEventHandler.eventSpeechRecognized;

            synth.Speak("Welcome, You may now begin commanding the robot.");
            while (true)
            {
                ;
            }
        }
Exemplo n.º 5
0
 private void PreviewButton_Click(object sender, EventArgs e)
 {
     s.SetOutputToDefaultAudioDevice();
     s.Speak(SpeechText.Text);
 }
Exemplo n.º 6
0
        public static async Task RecognizeOnceSpeechAsync(SpeechTranslationConfig config)
        {
            var allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);

            // Creates a speech recognizer.
            using (var recognizer = new IntentRecognizer(config))
            {
                Console.WriteLine("Say something...");

                var model = LanguageUnderstandingModel.FromAppId(ConfigurationManager.AppSettings.Get("LUISId"));
                recognizer.AddAllIntents(model);

                var result = await recognizer.RecognizeOnceAsync();

                // Checks result.
                if (result.Reason == ResultReason.RecognizedIntent)
                {
                    Console.WriteLine($"RECOGNIZED: Text={result.Text}");
                    Console.WriteLine($"    Intent Id: {result.IntentId}.");
                    Console.WriteLine($"    Language Understanding JSON: {result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult)}.");
                    if (result.IntentId == "Translate")
                    {
                        var    luisJson  = JObject.Parse(result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult));
                        string targetLng = luisJson["entities"].First(x => x["type"].ToString() == "TargetLanguage")["entity"].ToString();
                        string text      = luisJson["entities"].First(x => x["type"].ToString() == "Text")["entity"].ToString();

                        var lng = allCultures.FirstOrDefault(c => c.DisplayName.ToLower() == targetLng.ToLower()) ??
                                  allCultures.FirstOrDefault(c => c.DisplayName.ToLower() == "english");
                        var translated = Translate.TranslateText("de-DE", text);

                        Console.WriteLine("Translation: " + translated);

                        var synth = new System.Speech.Synthesis.SpeechSynthesizer();

                        // Configure the audio output.
                        synth.SetOutputToDefaultAudioDevice();

                        // Speak a string.
                        synth.SelectVoice(synth.GetInstalledVoices().First(x => x.VoiceInfo.Culture.TwoLetterISOLanguageName == lng.TwoLetterISOLanguageName).VoiceInfo.Name);
                        synth.Speak(translated);
                    }
                }
                else if (result.Reason == ResultReason.RecognizedSpeech)
                {
                    Console.WriteLine($"RECOGNIZED: Text={result.Text}");
                    Console.WriteLine($"    Intent not recognized.");
                }
                else if (result.Reason == ResultReason.NoMatch)
                {
                    Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                }
                else if (result.Reason == ResultReason.Canceled)
                {
                    var cancellation = CancellationDetails.FromResult(result);
                    Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");

                    if (cancellation.Reason == CancellationReason.Error)
                    {
                        Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
                        Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }
                }
            }
        }