🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: BCB and SAPI v5

#989
From: Michael Harris
Date: Sun, 25 Nov 2007 17:02
79 lines
3901 bytes
"Darko Miletic" wrote in message
> 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.
>

Thanks Darko. Your sample is similar to what I have using typelib.
The below allows for hearing whatever goes into the file.
the file writing is fast enough you cannot detect any delay.

Not included is a wave class to append each new 'speak file' into one file.

typedefs needed.
    typedef CComPtr<ISpStream         > _id_SpStream;
    typedef CComPtr<ISpeechVoice      > _id_SpeechVoice;
    typedef CComPtr<ISpeechBaseStream > _id_ISpeechBaseStream;
    typedef CComPtr<ISpeechFileStream > _id_ISpeechFileStream;
    typedef CComPtr<ISpeechObjectToken> _id_ISpeechObjectToken;

// other
SpeechVoiceSpeakFlags eSpeechVoiceSpeakFlags = SVSFDefault;
...
VoicePtr.CoCreateInstance(CLSID_SpVoice);
...
::Button2Click(TObject *Sender)
{
    if(fSpeafToFile) // indicates 'save to file'
    {Button2->Caption =  "Voice Output";
    }
    else {  Button2->Caption =  "File And Voice  Output";
    }
    fSpeafToFile = !fSpeafToFile;
}

Button1Click(TObject *Sender)
{
if(fSpeafToFile)
{
    BCB_SPBindToFile( wsFile, WideString( Edit1->Text ),  VoicePtr);
}
VoicePtr->Speak(WideString( Edit1->Text ), eSpeechVoiceSpeakFlags);
}

// save speach voice output pointer (object token), restore when done
HRESULT BCB_SPBindToFile( BSTR bstrFile, BSTR bstrTextToSpeak, 
_id_SpeechVoice Voice)
{
HRESULT hr = E_FAIL; // assume failed..
_id_ISpeechObjectToken pSpeechObjectToken = 0;
hr = Voice->get_AudioOutput((ISpeechObjectTokenPtr*)&pSpeechObjectToken);
BCB_WriteToFile(bstrFile, bstrTextToSpeak, Voice);
Voice->WaitUntilDone( INFINITE );
hr = Voice->_set_AudioOutput((ISpeechObjectTokenPtr)pSpeechObjectToken);
return (hr);
}

// set audio output to a file stream and write to file
HRESULT BCB_WriteToFile( BSTR bstrFile, BSTR bstrTextToSpeak, 
_id_SpeechVoice Voice)
{
HRESULT hr = E_FAIL; // assume failed..
_id_ISpeechFileStream  pFileStream = 0;
pFileStream.CoCreateInstance(CLSID_SpFileStream);
 if(pFileStream->Open( bstrFile, SSFMCreateForWrite, VARIANT_TRUE) == S_OK)
{
    hr = Voice->_set_AudioOutputStream((ISpeechBaseStreamPtr)pFileStream);
    hr = Voice->Speak (bstrTextToSpeak, SVSFPurgeBeforeSpeak );
    Voice->WaitUntilDone( INFINITE );
     pFileStream->Close();
     pFileStream = 0;            // forces 'flush buffer' on the file
}
return (hr);
}
Technical Details
Message-ID: <4749aa8a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!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> <4748980f$1@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
Reply-To: "Michael Harris" <techonos-NO-SPAM-@attbi.com>
From: "Michael Harris" <techonos-NO-SPAM-@attbi.com>
Newsgroups: borland.public.cppbuilder.nativeapi
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> <4748980f$1@newsgroups.borland.com>
Subject: Re: BCB and SAPI v5
Date: Sun, 25 Nov 2007 11:02:05 -0600
Lines: 83
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 76.187.54.201
Message-ID: <4749aa8a$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1196010122 76.187.54.201 (25 Nov 2007 09:02:02 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail