🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #988

Re: BCB and SAPI v5

#988
From: Darko Miletic
Date: Sat, 24 Nov 2007 21:31
77 lines
3525 bytes
Marc wrote:
> Done...

I sent you the example that works using bccsdk.
Here is just the code for the rest of the folks who might be interested.
I had to make some changes in some sapi headers and add missing guids to 
sapi.lib.
Soon new minor release will be available with this update.

//---------------------------------------------------------------------------
#include <tchar.h>
#include <windows.h>
#include <comdef.h>
#include <sapi.h>           //For ISp definitions - part of SDK
#include <sphelper.h>       //For SPBindToFile

#include <cstdlib>
#include <iostream>

#pragma comment (lib,"comsupp.lib")

//---------------------------------------------------------------------------
struct ole {
   ole(void): init(false) {
     init = SUCCEEDED(::CoInitializeEx (NULL, COINIT_MULTITHREADED));
   }
   ~ole(void){
     if (init) {
       init = false;
       ::CoUninitialize();
     }
   }
   bool isOK() {return init;}
private:
  bool init;

};

_COM_SMARTPTR_TYPEDEF(ISpVoice, __uuidof(ISpVoice));
_COM_SMARTPTR_TYPEDEF(ISpStream, __uuidof(ISpStream));

bool SpeakText(const char *str) {
  //This part with ole class is not needed in standard VCL app
  ole ol;
  if (!ol.isOK()) {
    return false;
  }
  bstr_t textToSpeak(str);
  ISpVoicePtr speaker;
  ISpStream *pStream = NULL;
  ISpStreamPtr stream;
  CSpStreamFormat     cAudioFmt;
  try {
    _com_util::CheckError(speaker.CreateInstance(CLSID_SpVoice));
    _com_util::CheckError(speaker->Speak(textToSpeak,SPF_DEFAULT,NULL));

    _com_util::CheckError(cAudioFmt.AssignFormat(SPSF_22kHz16BitStereo));
    _com_util::CheckError(SPBindToFile(L"e:\\test.wav", 
SPFM_CREATE_ALWAYS, &pStream, &cAudioFmt.FormatId(), 
cAudioFmt.WaveFormatExPtr() ));
    stream.Attach(pStream);
    _com_util::CheckError(speaker->SetOutput(stream,TRUE));
    _com_util::CheckError(speaker->Speak(textToSpeak,SPF_DEFAULT,NULL));
    _com_util::CheckError(stream->Close());

  } catch (_com_error &e) {
   std::cout << e.ErrorMessage() << std::endl;
   return false;
  }
  return true;
}

int main(int , char** )
{
    return SpeakText("Yeah!") ? EXIT_SUCCESS : EXIT_FAILURE;
}
//---------------------------------------------------------------------------
Technical Details
Message-ID: <4748980f$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <47446f75$1@newsgroups.borland.com> <47449cae@newsgroups.borland.com> <4744a4e3$1@newsgroups.borland.com> <4744b412$1@newsgroups.borland.com> <474564ea$1@newsgroups.borland.com> <47457331@newsgroups.borland.com> <474586a2@newsgroups.borland.com> <4745aca9@newsgroups.borland.com> <4745d020@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,67677465280073fd
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Sat, 24 Nov 2007 18:31:03 -0300
From: Darko Miletic <kiklop@fibertel.com.ar>
User-Agent: Thunderbird 2.0.0.9 (Windows/20071031)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: BCB and SAPI v5
References: <47446f75$1@newsgroups.borland.com> <47449cae@newsgroups.borland.com> <4744a4e3$1@newsgroups.borland.com> <4744b412$1@newsgroups.borland.com> <474564ea$1@newsgroups.borland.com> <47457331@newsgroups.borland.com> <474586a2@newsgroups.borland.com> <4745aca9@newsgroups.borland.com> <4745d020@newsgroups.borland.com>
In-Reply-To: <4745d020@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Antivirus: avast! (VPS 071124-0, 24/11/2007), Outbound message
X-Antivirus-Status: Clean
NNTP-Posting-Host: 200.89.185.153
Message-ID: <4748980f$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1195939855 200.89.185.153 (24 Nov 2007 13:30:55 -0700)
Lines: 77
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail