![]() |
Multimedia »
Audio and Video »
SAPI
Intermediate
Simple Program for Text to Speech Using SAPI (English Version)By Agus KurniawanMake a program for Text to Speech conversion using SAPI |
VC6Win2K, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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 ISpVoice Component
Object Model (COM) interface. Once an application has created an ISpVoice
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
speaking rate ISpVoice::SetRate, output volume ISpVoice::SetVolume
and changing the current speaking voice ISpVoice::SetVoice.
The project devided into five steps :
First you will create the initial ATL project using the MFC AppWizard.
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
To use SAPI (Speech Application Interface) in our application, we must set
our project. In file StdAfx.h, Add code like this (after "#include
<stdio.h>" but before the "#endif" statement) :
#include <atlbase.h> extern CComModule _Module; #include <atlcom.h>
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):

Figure 4: Add library module Sapi.lib and set path
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:
UpdateData();
ISpVoice * pVoice = NULL;
if (FAILED(CoInitialize(NULL)))
{
AfxMessageBox("Error to intiliaze COM");
return;
}
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL,
CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if( SUCCEEDED( hr ) )
{
hr = pVoice->Speak(m_sText.AllocSysString(), 0, NULL);
pVoice->Release();
pVoice = NULL;
}
CoUninitialize();
Note: m_sText is variable of Edit Box
After that, you can compile and run this project.
Speech SDK 5.1
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 12 Nov 2001 Editor: Nishant Sivakumar |
Copyright 2001 by Agus Kurniawan Everything else Copyright © CodeProject, 1999-2009 Web16 | Advertise on the Code Project |