コード例 #1
0
        private void WAVLocationDialog_FileOk(object sender, CancelEventArgs e)
        {
            s.SetOutputToWaveFile(WAVLocationDialog.FileName);
            s.Speak(SpeechText.Text);

            System.Diagnostics.Process.Start(new System.IO.FileInfo(WAVLocationDialog.FileName).DirectoryName);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: thanatTeay/texttospeechAPG
        public static void setLanguage2()
        {
            var syn = new System.Speech.Synthesis.SpeechSynthesizer();

            syn.SelectVoice("Microsoft Server Speech Text to Speech Voice (ja-JP, Haruka)");
            syn.Speak("こんにちは");
        }
コード例 #3
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);
        }
コード例 #4
0
 public void Asynth()
 {
     try
     {
         aSynth.SpeakAsyncCancelAll();
         pBuilder.ClearContent();
         pBuilder.AppendText(sentence);
         aSynth.Speak(pBuilder);
     }
     catch { return; }
 }
コード例 #5
0
 static void Main(string[] args)
 {
     using (SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer())
     {
         Console.Title = "Blackjack";
         synth.Speak("Please enter your blackjack table's name followed by a comma then the secondary name (AKA table number)");
         string bjtn = Console.ReadLine();
         Console.Clear();
         Console.Title = bjtn;
     }
     Start();
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: ewin66/Lxsh.Project
        /// <summary>
        /// 生成语音文件的方法
        /// </summary>
        /// <param name="text"></param>
        private static void SaveFile(string text)
        {
            using (System.Speech.Synthesis.SpeechSynthesizer speechSyn = new System.Speech.Synthesis.SpeechSynthesizer())
            {
                speechSyn.Volume = 100;
                speechSyn.Rate   = 0;
                string strPath = @"F:\研发一部\5.源代码\6.组件库\Lxsh.Project\Lxsh.Project.SpeechSynthesizer.Demo\bin\Debug\1.mp3";
                speechSyn.SetOutputToWaveFile(strPath);

                speechSyn.Speak(text);
                speechSyn.SetOutputToNull();
            }
        }
コード例 #7
0
 private void speak(bool bAsync, System.Speech.Synthesis.PromptBuilder pb)
 {
     try
     {
         if (bSaveFile)
         {
             ss.SetOutputToNull();
             delOutFile();
             ss.SetOutputToWaveFile(strOutputFile);
         }
         if (bAsync)
         {
             ss.SpeakAsync(pb);
         }
         else
         {
             ss.Speak(pb);
         }
     }
     catch (Exception ex)
     {
         speak("An error occured:" + ex.Message, false);
     }
 }
コード例 #8
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)
            {
                ;
            }
        }
コード例 #9
0
        private void bntConvert_Click(object sender, EventArgs e)
        {
            string age    = cbVoiceAge.SelectedItem.ToString();
            string gender = cbVoiceGender.SelectedItem.ToString();
            string text   = txtTexttoSpeak.Text.ToString();

            System.Speech.Synthesis.SpeechSynthesizer newvoice = Setupvoice(gender, age);



            newvoice.SetOutputToWaveFile(dir + @"\" + filename + ".wav",
                                         new SpeechAudioFormatInfo(8000, AudioBitsPerSample.Eight, AudioChannel.Mono));

            System.Media.SoundPlayer m_SoundPlayer =
                new System.Media.SoundPlayer(dir + @"\" + filename + ".wav");

            newvoice.Speak(text);

            m_SoundPlayer.Play();

            newvoice.Dispose();
        }
コード例 #10
0
        static void PlayAgain()
        {
            string playAgain = "";

            do
            {
                playAgain = Console.ReadLine().ToLower();
            }while (!playAgain.Equals("y") && !playAgain.Equals("n"));
            if (playAgain.Equals("y"))
            {
                Console.WriteLine("\nPress enter to restart the game!");
                Console.ReadLine();
                Console.Clear();
                dealerTotal = 0;
                count       = 1;
                total       = 0;
                Start();
            }
            else if (playAgain.Equals("n"))
            {
                using (SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer())
                {
                    synth.Speak("\nPress enter to close Black jack." + dealerTotal);
                }
                ConsoleKeyInfo info = Console.ReadKey();
                if (info.Key == ConsoleKey.Enter)
                {
                    Environment.Exit(0);
                }
                else
                {
                    Console.Read();
                    Environment.Exit(0);
                }
            }
        }
コード例 #11
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?");
                    }
                }
            }
        }
コード例 #12
0
 public void Speak(string text)
 {
     _synthesizer.Speak(text);
 }
コード例 #13
0
ファイル: Form_Game.cs プロジェクト: koraxos/ProjetCSharp
 // Délégué du thread de lecture du son
 public void thread_lecture()
 {
     synthe.Speak(jeu.getOperateur(operation_en_cours, 0) + " multiplié par " + jeu.getOperateur(operation_en_cours, 1) + ", égal");
     Thread.CurrentThread.Abort();
 }
コード例 #14
0
 static void Main(string[] args)
 {
     using (SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer()) {
         synth.Speak("Joe debono is a f****t");
     }
 }