Click here to Skip to main content
15,886,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all i have getting problem Microsoft Speech Object Library when using SAPI(5.1) in web application(asp.net4.0
and c#)

when i click play its playing continuely.

when i try to stop or pause its not stopped or pause.

it will play until text is over.

how can i stop and pause.
Posted
Updated 30-Oct-21 8:10am
Comments
ZurdoDev 24-Oct-12 8:37am    
Please use the improve question link and post the code you are using.

Then i should say you use SpVoice,but you don't know about it's features.
SpVoice.Speak() method can be called synchronously or asynchronously. When called synchronously, the method does not return until the text has been spoken; when called asynchronously, it returns immediately, and the voice speaks as a background process.
So use asynchronous method instead of synchronous,your problem should be solved.Use SpeechVoiceSpeakFlags.SVSFlagsAsync as like ase..
C#
SpVoice voice = new SpVoice ();
 voice.Speak ("An example of SpVoice.",SpeechVoiceSpeakFlags.SVSFlagsAsync);

Below code is a part of one of my project...
I use SpeechSynthesizer class of System.Speech dll.
Create an instance like..
C#
SpeechSynthesizer synthesis=new SpeechSynthesizer();

Then for speech conversion i use..
C#
synthesis.SpeakAsync(richTextBox1.Text);//speaks the text

To stop speech i use..
C#
synthesis.Dispose();//stops the synthesizer hence the speech!
 
Share this answer
 
v3
Comments
echosound 25-Oct-12 2:08am    
how to stop the speech
ridoy 25-Oct-12 10:43am    
See my updated solution for you.
You can stop speech by using

VB
Voice.Speak("", SpeechVoiceSpeakFlags.purgebeforespeak)



If you choose to do 'Voice.Dispose' or 'Voice = Nothing' then be sure to recreate it before trying to use it again.

VB
If Voice = Nothing then
Voice = New SpVoice
End If
 
Share this answer
 
Comments
Nelek 31-Oct-21 4:10am    
wow... 9 years since the question was done...
A new "better late than never" record ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900