In this project I made an application program for Text-to-Speech Conversion.
To build this application, we must install the SDK speech from Microsoft on our
computer. You can download Speech SDK (it's free) from http://www.microsoft.comm/speech
The SAPI API provides a high-level interface between an application and
speech engines. SAPI implements all the low-level details needed to control and
manage the real-time operations of various speech engines.
Applications can control text-to-speech (TTS) using the
Object Model (COM) interface. Once an application has created an
object, the application only needs to call
ISpVoice::Speak to generate
speech output from some text data. In addition, the
IspVoice interface also
provides several methods for changing voice and synthesis properties such as
ISpVoice::SetRate, output volume
and changing the current speaking voice
The project devided into five steps :
- Creating New Project
- Setting Project
- Building GUI
1. Creating New Project
First you will create the initial ATL project using the MFC AppWizard.
- In the Visual C++ environment, click New on the File menu,
then choose the Projects tab.
- Select the MFC AppWizard (exe).
- Type TxtToSpeech as the project name.
Your dialog box should look like this:
Figure 1: New Project
Click OK and the MFC AppWizard presents a dialog box offering
several choices to configure the type of MFC project (figure 2), choose Dialog
based. After that,
click Finish button
Figure 2: MFC AppWizard Step 1, choose Dialog based
2. Setting Project
To use SAPI (Speech Application Interface) in our application, we must set
our project. In file StdAfx.h, Add code like this (after "
" but before the "
" statement) :
extern CComModule _Module;
Change the project settings to reflect the paths. Using the Project->Settings.
menu item, set the SAPI.h path. Click the C/C++ tab and select Preprocessor
from the Category drop-down list. Enter the following in the "Additional
include directories": with directory that Speech SDK available , such as
D:\Program Files\Microsoft Speech SDK 5.1\Include. (see figure 3)
Figure 3: Setting path
To set the SAPI.lib path (see figure 4):
- Select the Link tab from the Same Settings dialog box.
- Choose Input from the Category drop-down list.
- Add the following path to the "Additional library path"
(directory that Speech SDK available), example :
D:\Program Files\Microsoft Speech SDK 5.1\Lib\i386.
- Also add "sapi.lib" to the "Object/library
Figure 4: Add library module Sapi.lib and set path
3. Building GUI
Model of GUI in this project like figure 5 :
Figure 5: GUI project
In GUI, double click Button, type
OnSpeak as name of method. This code:
ISpVoice * pVoice = NULL;
AfxMessageBox("Error to intiliaze COM");
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL,
CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if( SUCCEEDED( hr ) )
hr = pVoice->Speak(m_sText.AllocSysString(), 0, NULL);
pVoice = NULL;
m_sText is variable of Edit Box
After that, you can compile and run this project.
Speech SDK 5.1
He gradueted from Sepuluh Nopember Institute of Technology (ITS) in Department of Electrical Engineering, Indonesia. His programming interest is VC++, C#, VB, VB.NET, .NET, VBScript, Delphi, C++ Builder, Assembly,and ASP/ASP.NET. He's founder for PE College(www.pecollege.net), free video tutorial about programming, infrastructure, and computer science. He's currently based in Depok, Indonesia. His blog is http://geeks.netindonesia.net/blogs/agus and http://blog.aguskurniawan.net