Click here to Skip to main content
6,595,854 members and growing! (17,347 online)
Email Password   helpLost your password?
Multimedia » Audio and Video » SAPI     Intermediate

Simple Program for Text to Speech Using SAPI (English Version)

By Agus Kurniawan

Make a program for Text to Speech conversion using SAPI
VC6Win2K, MFC, Dev
Posted:12 Nov 2001
Views:247,983
Bookmarked:63 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
39 votes for this article.
Popularity: 5.86 Rating: 3.68 out of 5
3 votes, 11.1%
1
1 vote, 3.7%
2
3 votes, 11.1%
3
6 votes, 22.2%
4
14 votes, 51.9%
5

Introduction

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 :

  1. Creating New Project
  2. Setting Project
  3. Building GUI 
  4. Coding

1. Creating New Project

First you will create the initial ATL project using the MFC AppWizard.

  1. In the Visual C++ environment, click New on the File menu, then choose the Projects tab.

  2. Select the MFC AppWizard (exe).

  3. 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 "#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):

  1. Select the Link tab from the Same Settings dialog box.
  2. Choose Input from the Category drop-down list.
  3. 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.
  4. Also add "sapi.lib" to the "Object/library modules" line. 

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

4. Coding

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.

Reference

Speech SDK 5.1

License

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

Agus Kurniawan


Member
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 consultant and architect for People Enterprise (www.PeopleEnterprise.com). He's currently based in Depok, Indonesia. His blog is http://geeks.netindonesia.net/blogs/agus
Occupation: Web Developer
Location: Indonesia Indonesia

Other popular Audio and Video articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 98 (Total in Forum: 98) (Refresh)FirstPrevNext
GeneralText to Speech -Audio File German Version Pinmembersmilechill5:25 21 Sep '09  
GeneralGetTranscript PinmemberDanilo Queiroz16:30 13 Apr '09  
Generalcreating wav file in TTS PinmemberMember 28284520:21 13 Apr '09  
Generalproblem getting software for speech to text recognition Pinmembershashi.er.kant8:07 18 Jun '08  
QuestionSAPI text to speech looping problem! Pinmembercesarpachon16:31 9 Apr '08  
GeneralSTDAfx.h HELP! PinmemberSebcity7:30 5 Feb '07  
GeneralRe: STDAfx.h HELP! Pinmembercristitomi6:27 23 Sep '07  
GeneralHow to generate music from text characters? Pinmemberakks_39:11 8 Nov '06  
Generalurgent : automation of engine Pinmembernehasingh8:50 20 Jan '06  
Generalspeech recognition Pinmembermanikandanek1:55 29 Oct '05  
GeneralText To Speech Convertor Pinmembermanikandanek1:49 29 Oct '05  
GeneralRe: Text To Speech Convertor Pinmembersen_raj2218:53 30 Jan '06  
GeneralChanging voice ! Pinmemberspirit198314:43 6 Aug '05  
GeneralGerman Output?! PinmemberHansa4Ever3:23 24 Jun '05  
Generalis it possible not to use sdk Pinmemberkaamsha11:41 8 Apr '05  
GeneralIntergrating TTS with direct sound Pinmemberwtatters12:48 5 Apr '05  
Generalnice but too simple. PinsussAnonymous4:18 30 Mar '05  
GeneralRe: nice but too simple. Pinmembercristitomi6:33 23 Sep '07  
Generalhow to do speech to text using VB PinmemberCOOLBHUSHU19:51 29 Jan '05  
GeneralTTS to read web page PinsussAnonymous6:08 3 Nov '04  
GeneralRe: TTS to read web page PinsussAnonymous5:06 30 Mar '05  
GeneralTTS application that accept inpur frm command prompt and generate .wav file Pinmembersunil choudhary1:28 17 Sep '04  
GeneralRe: TTS application that accept inpur frm command prompt and generate .wav file PinsussAnonymous5:03 30 Mar '05  
Generalabout speech events in speech sdk 5.1 Pinmemberxunan2:53 31 Aug '04  
GeneralDeciding download PinmemberRJSoft7:54 20 Jul '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin 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