Click here to Skip to main content
15,394,645 members
Articles / Desktop Programming / MFC
Posted 3 Oct 2004


75 bookmarked

A Simple Speech Application Using SAPI 5.1 SDK

Rate me:
Please Sign up or sign in to vote.
3.24/5 (24 votes)
3 Oct 20042 min read
A simple speech application using SAPI 5.1 SDK.


This small speech application converts text to speech and speech to text. If you choose the "Speak" option, whatever you type in the textbox is is converted to speech and you can hear the Microsoft's default voice speaking it out!

This application also converts speech to text. Just connect your microphone and do the "Microphone Setup" to set up your microphone and speak. You will be able to see the words get typed in the textbox as you speak!

For best results please do try the Voice Training Wizard before speaking out anything, it helps in setting your grammar.

Using the Code

The application is a dialog based application written in MFC. It uses only one dialog class CSpeechDlg.

The steps involved are as follows:

  1. Initialize COM.
  2. Initialize the Recognizer (to recognize that a speech is being invoked).
  3. Initialize the RecoEngine (the Speech engine).
  4. Initialize the RecoContext (the context in which we are going to write the speech application).
  5. Set a user-defined message that will grab whenever something is spoken, to our window (here dialog).
  6. Set the speech record interest in RECOGNITION Status.
  7. Create the default audio input.
  8. Set the Input to the speech engine.
  9. Specify the Grammar that we want to use (here we use Dictation Grammar).
  10. Load the Dictation Tool.

Speech To Text

The CallBack function for our user defined message will perform the following for the speech to text conversion:

  • It will process all the speech events.
  • Check for the event ID generated to identify the speech event that has occurred.
  • If it is the speech recognition event, then get the text and display it in the text area.

Text to Speech

This is a simple process, you just have to pass the text to a function Speak(text) and now the function will take care of its processing .


  • Microsoft Speech SDK 5.1.


  • Microsoft Speech SDK 5.1 onwards.

My contact


  • SAPI - Speech Application Programmer Interface.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer
New Zealand New Zealand
Chakkaradeep, known as Chaks to his friends, hails from the Indian subcontinent.Having done his Masters in Software Engineering, he knows his way around a computer and has sound knowledge of Microsoft technologies.

Chaks is currently working as a Microsoft Developer @ New Zealand.

You can reach him via his blog -

Comments and Discussions

GeneralRe: voice recognition Pin
soumyasantadas29-Sep-07 16:59
Membersoumyasantadas29-Sep-07 16:59 
GeneralRe: voice recognition Pin
TassadaqHussain29-Sep-07 23:08
MemberTassadaqHussain29-Sep-07 23:08 
Generalspeech to text Pin
Cheeeeema17-Aug-05 10:13
sussCheeeeema17-Aug-05 10:13 
GeneralRe: speech to text Pin
chakkaradeepcc25-Aug-05 2:53
Memberchakkaradeepcc25-Aug-05 2:53 
GeneralRegarding "sphelper.h' Pin
chakkaradeepcc23-May-05 2:34
Memberchakkaradeepcc23-May-05 2:34 
GeneralRe: Regarding "sphelper.h' Pin
mikkojay23-Feb-09 14:38
Membermikkojay23-Feb-09 14:38 
GeneralRe: Regarding "sphelper.h' Pin
khairul7863-May-11 17:42
Memberkhairul7863-May-11 17:42 
GeneralRelease Build Crashes Pin
Spoodles29-Nov-04 3:05
MemberSpoodles29-Nov-04 3:05 
No problem with Debug build. But when I run a Release build of the sample, speak (let it display the text), then speak again, I get the typical Application Error, instruction at ... referenced ... The memory could not be read.

I found this code useful for adding speech recognition quickly to an app, and would like to continue. Any ideas why the Release would crash when the Debug seems fine?

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.