Click here to Skip to main content
16,016,527 members
Articles / Web Development / ASP.NET
Article

Simple Text Editor With Speech Abilities

Rate me:
Please Sign up or sign in to vote.
3.75/5 (9 votes)
27 Jun 2007CPOL1 min read 49.2K   2.9K   40   5
An article on using the Microsoft Speech SDK to make a simple text-to-speech application

Screenshot - capture.jpg

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:

C#
using SpeechLib;

Then define the following variables:

C#
string voice="name=Microsoft Sam";  // default
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:

C#
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.
C#
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

License

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


Written By
Software Developer Al mouakhah lil khadamat al logesteih wa al itisal
Jordan Jordan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalthanks u very much! i want to known if it can speech in chinese. Pin
rsscodevb9-Nov-07 21:11
rsscodevb9-Nov-07 21:11 
GeneralRe: thanks u very much! i want to known if it can speech in chinese. Pin
Muneer Safi10-Nov-07 21:17
Muneer Safi10-Nov-07 21:17 
The Text-to-Speech engine supports (English and Simplified Chinese)

you can change it to speak Chinese

please follow these steps:

1.Click Start, click Control Panel, click Sounds, Speech, and Audio Devices, and then click Speech.
2.Click the Speech Recognition tab. The name that appears in the Language box

visit this link for more information

http://www.microsoft.com/speech/speech2007/speechdevarticle.mspx

GeneralRe: thanks u very much! i want to known if it can speech in chinese. Pin
rsscodevb11-Nov-07 16:51
rsscodevb11-Nov-07 16:51 
GeneralYou have an Virus in the Zip file Pin
Paw Jershauge27-Jun-07 4:15
Paw Jershauge27-Jun-07 4:15 
GeneralRe: You have an Virus in the Zip file Pin
jamief27-Jun-07 5:25
jamief27-Jun-07 5:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.