Introduction
This program serves mainly as a text editor, but with extended capabilities such as inserting an image and speaking the text you write. The most important part is how to make speech out of the written text. I did this using the Microsoft Text-to-Speech SDK.
Using the code
You must first install the Microsoft Text-to-Speech SDK. Then you can use all of the Text-to-Speech features in this program. Include the Speech Library into the program as follows:
using SpeechLib;
Then define the following variables:
string voice="name=Microsoft Sam";
int volume=50;
int rate=3;
This piece of code is responsible for speaking the text you write. To speak the given text string synchronously, we must use:
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
Other values are:
SVSFPurgeBeforeSpeak
: Purges all pending speak requests prior to this speak call. SVSFIsFilename
: The string passed to the Speak method is a file name rather than text. As a result, the string itself is not spoken, but rather the file the path that it points to. SVSFIsXML
: The input text will be parsed for XML markup. SVSFIsNotXML
: The input text will not be parsed for XML markup. SVSFPersistXML
: Global state changes in the XML markup will persist across speak calls. SVSFNLPSpeakPunc
: Punctuation characters should be expanded into words, e.g. "This is it." would become "This is it period" SVSFNLPMask
: Flags handled by SAPI -- as opposed to the text-to-speech engine -- are set in this mask. SVSFVoiceMask
: This mask has every flag bit set. SVSFUnusedFlags
: This mask has every unused bit set.
TextArea ta;
ta=(TextArea)this.ActiveMdiChild;
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice Vr = new SpVoice();
Vr.Rate=rate;
Vr.Volume=volume;
SpeechLib.SpObjectToken tok;
tok=Vr.Voice;
Vr.Voice=Vr.GetVoices(voice,"").Item(0);
try
{
Vr.Speak(ta.richTextBox1.SelectedText, SpFlags);
}
catch
{
MessageBox.Show(
"Nothing To Read\nPlease Open A Document And Write Some Text First",
"Error");
}
History
- 27 June, 2007 -- Original version posted
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.