How to read (like text to speech of Microsoft) a text in textbox?
-
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?
-
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?
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
-
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
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.
-
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.
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
-
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
-
HI,thanks for your reply I've tried your code.It had no error but nothing happened either.I can not hear anything.
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.
-
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.