Ejemplo n.º 1
0
 private void listViewPdfs_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         timer.Stop();
         progressBar1.Value = 1;
         buttonPlay.Enabled = true;
         buttonPre.Enabled  = true;
         buttonNext.Enabled = true;
         var current = speech.GetCurrentlySpokenPrompt();
         if (current != null)
         {
             speech.SpeakAsyncCancel(current);
         }
         FileName = listViewPdfs.SelectedItems[currentIndex].Text;
         PdfReader reader1 = new PdfReader(FileName);
         ConvertPDFtoImage(1);
         AllText = PdfTextExtractor.GetTextFromPage(reader1, index);
         reader1.Close();
     }
     catch (Exception)
     {
         try
         {
             FileName = listViewPdfs.SelectedItems[currentIndex].Text;
             PdfReader reader = new PdfReader(FileName);
             ConvertPDFtoImage(1);
             AllText = PdfTextExtractor.GetTextFromPage(reader, index);
             reader.Close();
         }
         catch (Exception)
         {
         }
     }
 }
        static void client_messageReceived(object sender, MqttMsgPublishEventArgs e)
        {
            //For multiple subscribed topics, put an if statement into the message handler to branch based
            //on the incoming messages topic e.Topic.
            //You can write functions to handle the different message types and call these from the message handler
            //and pass the MqttMsgPublishEventArgs object to those functions.

            Console.OutputEncoding = System.Text.Encoding.UTF8;

            // Handle the received message

            string messageText = ((Encoding.UTF8.GetString(e.Message)).Replace("{\"data\": \"", "")).Replace("\"}", "");

            Console.WriteLine("Text to be spoken received => " + messageText);

            //Branch based on the incoming messages topic e.Topic.
            if (e.Topic == "/ttsbg_mqtt/tts_text")
            {
                //Cancel syntesis if currently speaking something else...
                var current = synth.GetCurrentlySpokenPrompt();
                if (current != null)
                {
                    synth.SpeakAsyncCancel(current);
                }
                if (enableSpeaking)
                {
                    // Speak out the string.
                    SpeakAsync(messageText);

                    //TODO refine the command/response scheme

                    mqttClient.Publish("/ttsbg_mqtt/response", Encoding.UTF8.GetBytes("{\"data\": \"" + "speaking" + "\"}"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, true);
                }
            }
            else if (e.Topic == "/ttsbg_mqtt/command")
            {
                if (messageText == "enable")
                {
                    enableSpeaking = true;
                    mqttClient.Publish("/ttsbg_mqtt/response", Encoding.UTF8.GetBytes("{\"data\": \"" + "enabled" + "\"}"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, true);
                }
                else if (messageText == "disable")
                {
                    enableSpeaking = false;
                    cancelSpeaking();
                    mqttClient.Publish("/ttsbg_mqtt/response", Encoding.UTF8.GetBytes("{\"data\": \"" + "disabled" + "\"}"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, true);
                }
                else if (messageText == "cancel")
                {
                    // Cancel if currently speaking
                    cancelSpeaking();
                }
                //else
                //{

                //}
            }
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            var current = synth.GetCurrentlySpokenPrompt();

            if (current != null)
            {
                synth.SpeakAsyncCancel(current);
            }
            if (textBox1.Text.ToString() != "")
            {
                synth.SpeakAsync(textBox1.Text);
            }
            else
            {
                MessageBox.Show("You need to write something in the text box!");
            }
        }
Ejemplo n.º 4
0
        public static void stopSpeech()
        {
            var current = synthesizer.GetCurrentlySpokenPrompt();

            if (current != null)     //это остановка произношения
            {
                synthesizer.SpeakAsyncCancel(current);
            }
        }
Ejemplo n.º 5
0
        public void SpeakStop()
        {
            Prompt p1 = speech.GetCurrentlySpokenPrompt();

            if (p1 != null)
            {
                speech.SpeakAsyncCancel(p1);
            }

            Util.Delay(10);
            speech.SpeakAsyncCancelAll();
            speech.Resume();
        }
        public void speak(string value)
        {
            SpeechSynthesizer speech = new SpeechSynthesizer();

            speech.SelectVoice(MainMenu.accent);
            var current = speech.GetCurrentlySpokenPrompt();

            if (current != null)
            {
                speech.SpeakAsyncCancel(current);
            }
            speech.SpeakAsync(value);
            questionText.Text = value;
        }
Ejemplo n.º 7
0
        private void buttonSpeak_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != null)
            {
                if (voiceBox.State == SynthesizerState.Paused)
                {
                    voiceBox.Resume();
                }
                //else if (voiceBox.GetCurrentlySpokenPrompt() != null)
                else if (voiceBox.GetCurrentlySpokenPrompt() == null)
                {
                    //voiceBox.SpeakAsyncCancel(voiceBox.GetCurrentlySpokenPrompt());
                    text = textBox1.Text;

                    if (checkBoxReverse.Checked)
                    {
                        char[] charSequence = text.ToCharArray();
                        text = new string(charSequence.Reverse().ToArray <char>());
                    }

                    voiceBox.SpeakAsync(text);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Stop speaking.
        /// </summary>
        /// <returns>Return true if the synthesizer speaked and stopped, otherwise return false.</returns>
        public bool StopSpeak()
        {
            if (_speechSynth.State == SynthesizerState.Speaking)
            {
                Prompt prompt = _speechSynth.GetCurrentlySpokenPrompt();

                if (prompt != null)
                {
                    _speechSynth.SpeakAsyncCancel(prompt);
                    return(true);
                }
            }

            return(false);
        }
 private void SpeakSentenceButton_OnClick(object sender, RoutedEventArgs e)
 {
     if (sender is FrameworkElement element && element.DataContext is SentenceModel sentenceModel)
     {
         if (!string.IsNullOrEmpty(sentenceModel.EnglishSentenceUri) && File.Exists(sentenceModel.EnglishSentenceUri))
         {
             (this.DataContext as SearchWordViewModel)?.SpeekCommand.Execute(sentenceModel.EnglishSentenceUri);
         }
         else
         {
             //系统读音
             var currentSpokenPrompt = _speechSyn.GetCurrentlySpokenPrompt();
             if (currentSpokenPrompt != null)
             {
                 _speechSyn.SpeakAsyncCancel(currentSpokenPrompt);
             }
             _speechSyn.SpeakAsync(sentenceModel.EnglishSentence);
         }
     }
 }
Ejemplo n.º 10
0
        public void SpeechSynthesizerEventsAndProperties()
        {
            using (var synth = new SpeechSynthesizer())
            {
                using var ms = new MemoryStream();

                synth.SetOutputToNull();
                synth.SetOutputToAudioStream(ms, new SpeechAudioFormatInfo(16000, AudioBitsPerSample.Sixteen, AudioChannel.Stereo));
                synth.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Adult);
                Assert.True(synth.Volume > 0);
                Assert.NotNull(synth.Voice);
                Assert.NotEmpty(synth.GetInstalledVoices());
                Assert.Null(synth.GetCurrentlySpokenPrompt());

                var builder = new PromptBuilder();
                builder.AppendText("synthesizer");

                int events = 0;
                synth.BookmarkReached += (object o, BookmarkReachedEventArgs e) => events++;
                synth.PhonemeReached  += (object o, PhonemeReachedEventArgs e) => events++;
                synth.SpeakProgress   += (object o, SpeakProgressEventArgs e) => events++;
                synth.SpeakStarted    += (object o, SpeakStartedEventArgs e) => events++;
                synth.VisemeReached   += (object o, VisemeReachedEventArgs e) => events++;
                synth.VoiceChange     += (object o, VoiceChangeEventArgs e) => events++;
                synth.StateChanged    += (object o, System.Speech.Synthesis.StateChangedEventArgs e) => events++;
                synth.SpeakCompleted  += (object o, SpeakCompletedEventArgs e) =>
                {
                    events++;
                    Assert.Equal(34, events++);
                };

                Assert.Equal(SynthesizerState.Ready, synth.State);
                synth.SpeakSsml(builder.ToXml());
                Assert.Equal(SynthesizerState.Ready, synth.State);
                synth.Pause();
                Assert.Equal(SynthesizerState.Paused, synth.State);
                synth.Resume();
                Assert.Equal(SynthesizerState.Ready, synth.State);
            }
        }
Ejemplo n.º 11
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            if (richTextBox1.Text.Trim() != string.Empty)
            {
                //richTextBox2.Text = richTextBox1.Text;

                richTextBox2.Text = LexRequest(richTextBox1.Text);
                var currentSpeaker = _synthesizer.GetCurrentlySpokenPrompt();
                if (currentSpeaker != null)
                {
                    _synthesizer.SpeakAsyncCancel(currentSpeaker);
                }

                speak();
                richTextBox1.Text = string.Empty;
            }
            else
            {
                richTextBox2.Text = "Oh! You forgot to enter text message.";
                speak();
            }
        }
Ejemplo n.º 12
0
        private void productLabeltimer_Tick(object sender, EventArgs e)
        {
            var current = optio.GetCurrentlySpokenPrompt();

            //Login login1 = new Login(this);
            //Admin admin = new Admin(this);

            Form login = Application.OpenForms["Login"];
            Form admin = Application.OpenForms["Admin"];

            //Form admin = Application.OpenForms["Admin"];

            if (current == null && login == null && admin == null)
            {
                refreshForm();
            }
            else
            {
                productLabeltimer.Stop();
                productLabeltimer.Start();
            }
        }
Ejemplo n.º 13
0
 private void play_Click(object sender, EventArgs e)
 {
     if (listView2.SelectedItems.Count > 0)
     {
         using (PdfReader reader = new PdfReader(paths.Find(x => x.Contains(listView2.SelectedItems[0].Text))))
         {
             pageCount             = reader.NumberOfPages;
             PageCountLbl.Text     = $"{currentPage} of {pageCount}";
             bookReaderPnl.Visible = true;
             toSpeach = PdfTextExtractor.GetTextFromPage(reader, currentPage);
             var cur = speech.GetCurrentlySpokenPrompt();
             if (cur != null)
             {
                 speech.SpeakAsyncCancel(cur);
             }
             if (currentPage != lastPage)
             {
                 speech.SpeakAsync(toSpeach);
             }
             lastPage = currentPage;
         }
     }
 }