Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to read (like text to speech of Microsoft) a text in textbox?

How to read (like text to speech of Microsoft) a text in textbox?

Scheduled Pinned Locked Moved C#
tutorialquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    largs
    wrote on last edited by
    #1

    I have a form with 2 controls a textbox and a button.When i press the button i'd like it says the text in the textbox.It likes text to speech of Microsoft.How to do it?

    E 1 Reply Last reply
    0
    • L largs

      I have a form with 2 controls a textbox and a button.When i press the button i'd like it says the text in the textbox.It likes text to speech of Microsoft.How to do it?

      E Offline
      E Offline
      emran834
      wrote on last edited by
      #2

      Hi, Ok, according to my knowledge, you have two choices, one is using SAPI class, another is using Microsoft Agent. Microsoft Agent is more tempting and attractive, but in order to explain easily, I am showing you using SAPI way. Add reference from COM tab: Microsoft Speech Object library then use these statements at the top of your class, using SpeechLib; using System.Threading; Then use background Worker named "backgroundWorkerLetterTalker" , You can proceed without background worker but then your controls will be held frozen until speak method is finished. Say your speak button name is "btnSpeakLetter" and textbox name is "bodyRichTextBox" Add event handler for Background worker DoWork named "speakLetter" Add event handler for background worker Completed named "skeapLetter_Completed" Add event handler for button btnSpeakLetter named "btnSpeakLetter_Click" Now add these following code // ///////////////////////////// SPEAK Method // ////////////////////////////////////// private void btnSpeakLetter_Click(object sender, EventArgs e) { btnSpeakLetter.Enabled = false; backgroundWorkerLetterTalker.RunWorkerAsync(bodyRichTextBox.Text); } private void speakLetter(object sender, DoWorkEventArgs e) { string arg = (string)e.Argument; SpVoice objSpeech = new SpVoice(); objSpeech.Speak(arg, SpeechVoiceSpeakFlags.SVSFlagsAsync); objSpeech.WaitUntilDone(Timeout.Infinite); } private void skeapLetter_Completed(object sender, RunWorkerCompletedEventArgs e) { btnSpeakLetter.Enabled = true; } // ///////////////////////////////////////// X /////////////////////////////////////// Nicely working in .NET 2.0 C# Express 2005. I did not test in the previous version. EMRAN -- modified at 8:12 Saturday 25th February, 2006

      L 1 Reply Last reply
      0
      • E emran834

        Hi, Ok, according to my knowledge, you have two choices, one is using SAPI class, another is using Microsoft Agent. Microsoft Agent is more tempting and attractive, but in order to explain easily, I am showing you using SAPI way. Add reference from COM tab: Microsoft Speech Object library then use these statements at the top of your class, using SpeechLib; using System.Threading; Then use background Worker named "backgroundWorkerLetterTalker" , You can proceed without background worker but then your controls will be held frozen until speak method is finished. Say your speak button name is "btnSpeakLetter" and textbox name is "bodyRichTextBox" Add event handler for Background worker DoWork named "speakLetter" Add event handler for background worker Completed named "skeapLetter_Completed" Add event handler for button btnSpeakLetter named "btnSpeakLetter_Click" Now add these following code // ///////////////////////////// SPEAK Method // ////////////////////////////////////// private void btnSpeakLetter_Click(object sender, EventArgs e) { btnSpeakLetter.Enabled = false; backgroundWorkerLetterTalker.RunWorkerAsync(bodyRichTextBox.Text); } private void speakLetter(object sender, DoWorkEventArgs e) { string arg = (string)e.Argument; SpVoice objSpeech = new SpVoice(); objSpeech.Speak(arg, SpeechVoiceSpeakFlags.SVSFlagsAsync); objSpeech.WaitUntilDone(Timeout.Infinite); } private void skeapLetter_Completed(object sender, RunWorkerCompletedEventArgs e) { btnSpeakLetter.Enabled = true; } // ///////////////////////////////////////// X /////////////////////////////////////// Nicely working in .NET 2.0 C# Express 2005. I did not test in the previous version. EMRAN -- modified at 8:12 Saturday 25th February, 2006

        L Offline
        L Offline
        largs
        wrote on last edited by
        #3

        I used using SpeechLib; using System.Threading; and copy your code but when i debug it generated an error.It does not understand DoWorkEventArgs and RunWorkerCompletedEventArgs.By the way could you tell me which class that the object backgroundWorkerLetterTalker belongs to?How to create this object? Regards.

        E 1 Reply Last reply
        0
        • L largs

          I used using SpeechLib; using System.Threading; and copy your code but when i debug it generated an error.It does not understand DoWorkEventArgs and RunWorkerCompletedEventArgs.By the way could you tell me which class that the object backgroundWorkerLetterTalker belongs to?How to create this object? Regards.

          E Offline
          E Offline
          emran834
          wrote on last edited by
          #4

          Hello, Ok, The code file where I am using BackgroundWorker i have following using statements, you can just copy all of them for the time being for debugging purpose. using System; using System.Collections.Generic; using System.ComponentModel; using SpeechLib; using System.Threading; Moreover Backgroundworker is a control available in your C# ToolBox. It is a new component in .NET 2.0 (2005 Express Editition). So, if you are using .Net 1.1 (Visual Studio 2003) then dont use this code. "By the way could you tell me which class that the object backgroundWorkerLetterTalker belongs to ?" :: backgroundWorkerLetterTalker was an instance variable name of BackgroundWorker Control, not any standard .net class name. OK, If you have too much trouble about Background worker, then forget about backgroundWorker. For simplicity, just to test Text to Speech, put this code without background worker. At least you will hear voice from machine. private void btnSpeak_Click(object sender, EventArgs e) { /////////////////////////////////////////////////////////// string arg = "HEllo I am speaking"; SpVoice objSpeech = new SpVoice(); objSpeech.Speak(arg, SpeechVoiceSpeakFlags.SVSFlagsAsync); objSpeech.WaitUntilDone(Timeout.Infinite); /////////////////////////////////////////////////////////// } -- modified at 13:30 Monday 27th February, 2006

          L 1 Reply Last reply
          0
          • E emran834

            Hello, Ok, The code file where I am using BackgroundWorker i have following using statements, you can just copy all of them for the time being for debugging purpose. using System; using System.Collections.Generic; using System.ComponentModel; using SpeechLib; using System.Threading; Moreover Backgroundworker is a control available in your C# ToolBox. It is a new component in .NET 2.0 (2005 Express Editition). So, if you are using .Net 1.1 (Visual Studio 2003) then dont use this code. "By the way could you tell me which class that the object backgroundWorkerLetterTalker belongs to ?" :: backgroundWorkerLetterTalker was an instance variable name of BackgroundWorker Control, not any standard .net class name. OK, If you have too much trouble about Background worker, then forget about backgroundWorker. For simplicity, just to test Text to Speech, put this code without background worker. At least you will hear voice from machine. private void btnSpeak_Click(object sender, EventArgs e) { /////////////////////////////////////////////////////////// string arg = "HEllo I am speaking"; SpVoice objSpeech = new SpVoice(); objSpeech.Speak(arg, SpeechVoiceSpeakFlags.SVSFlagsAsync); objSpeech.WaitUntilDone(Timeout.Infinite); /////////////////////////////////////////////////////////// } -- modified at 13:30 Monday 27th February, 2006

            L Offline
            L Offline
            largs
            wrote on last edited by
            #5

            HI,thanks for your reply I've tried your code.It had no error but nothing happened either.I can not hear anything.

            E 1 Reply Last reply
            0
            • L largs

              HI,thanks for your reply I've tried your code.It had no error but nothing happened either.I can not hear anything.

              E Offline
              E Offline
              emran834
              wrote on last edited by
              #6

              Hi I have built a project for you and sent you email with an zip file attachment. This project is working perfectly in my PC. If it is not working in your pc, then may be your pc is not equipped with microsoft speech features or may be something else wrong. And this project is built in .NET 2.0 (C# express 2005). If you have the previous version, then just open the file form1.cs and see the code and then use in your previous version IDE.

              L 1 Reply Last reply
              0
              • E emran834

                Hi I have built a project for you and sent you email with an zip file attachment. This project is working perfectly in my PC. If it is not working in your pc, then may be your pc is not equipped with microsoft speech features or may be something else wrong. And this project is built in .NET 2.0 (C# express 2005). If you have the previous version, then just open the file form1.cs and see the code and then use in your previous version IDE.

                L Offline
                L Offline
                largs
                wrote on last edited by
                #7

                HI my email address is khoilvthu@yahoo.com.Please send the zip file to this address.Thanks lots

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups