Click here to Skip to main content
Licence CPOL
First Posted 27 Jun 2007
Views 27,093
Downloads 1,065
Bookmarked 39 times

Simple Text Editor With Speech Abilities

By | 27 Jun 2007 | Article
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:

using SpeechLib;

Then define the following variables:

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:

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

License

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

About the Author

Muneer Safi

Software Developer

Jordan Jordan

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalthanks u very much! i want to known if it can speech in chinese. Pinmemberrsscodevb21:11 9 Nov '07  
GeneralRe: thanks u very much! i want to known if it can speech in chinese. PinmemberMuneer Safi21:17 10 Nov '07  
GeneralRe: thanks u very much! i want to known if it can speech in chinese. Pinmemberrsscodevb16:51 11 Nov '07  
GeneralYou have an Virus in the Zip file PinmemberPawJershauge4:15 27 Jun '07  
GeneralRe: You have an Virus in the Zip file Pinmemberjamief5:25 27 Jun '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 27 Jun 2007
Article Copyright 2007 by Muneer Safi
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid