Thread View: borland.public.cppbuilder.nativeapi
21 messages
21 total messages
Started by Marc
Wed, 21 Nov 2007 17:47
BCB and SAPI v5
Author: Marc
Date: Wed, 21 Nov 2007 17:47
Date: Wed, 21 Nov 2007 17:47
112 lines
3496 bytes
3496 bytes
Hi all
So here is what I did so far:
I spent the last three days trying to use the MS SAPI SDK 5.1. It installed
all right and the samples in VB work OK.
Using the code snipped of my last post I was able to let it speak through my
speaker.
But since then I am hitting one problem after the other.
When I include the "sphelper.h" needed for the SPBindToFile function, I get
plenty of errors in the *.h files.
IE if I set the _DEBUG option I get the error _CRTDBG_MODE_DEBUG not defined
in the sebug.h and many more errors complaining about missing definitions
?!?!?
When I disable the debugger (not really a solution in the long term) I am
able to compile (after a couple of adaptations to the sphelper.h)
Now I used the attached code and tried to write the TTS to a file.
Unfortunately it fails every time with the call to SPBindToFile (Error =
E_INVALIDARG).
I had a look through all of www.deja.com, did Google searches and played
around myself with the parameters => no success.
Therefore my questions:
1)Has anyone ever successfully used SAPI v5 with BCB6 and was able to
compile the sphelper.h in _DEBUG mode ?
2)Has anyone ever successfully used the SPBindToFile function ?
I was also looking at using the MS OCXs, but Microsoft does not ship them in
SAPI v5 anymore and I do not really want to go back to SAP v4.
Rds
Marc
******************************************************
void TSpeech::SpeakToFile(String Words, String sFileName)
{
HRESULT hr = S_OK;
ISpVoice *cpVoice;
ISpStream *cpStream;
CSpStreamFormat *cAudioFmt;
//Create a SAPI Voice
hr = cpVoice.CoCreateInstance( CLSID_SpVoice );
//Set the audio format
if(SUCCEEDED(hr))
{
hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono);
}
//Call SPBindToFile, a SAPI helper method, to bind the audio stream to the
file
if(SUCCEEDED(hr))
{
hr = SPBindToFile( L"c:\\ttstemp.wav", SPFM_CREATE_ALWAYS,
&cpStream, & cAudioFmt.FormatId(),cAudioFmt.WaveFormatExPtr() );
}
//=> FAILS HERE WITH INVALIARG ****************************
//set the output to cpStream so that the output audio data will be stored
in cpStream
if(SUCCEEDED(hr))
{
hr = cpVoice->SetOutput( cpStream, TRUE );
}
//Speak the text "hello world" synchronously
if(SUCCEEDED(hr))
{
hr = cpVoice->Speak( L"Hello World", SPF_DEFAULT, NULL );
}
//close the stream
if(SUCCEEDED(hr))
{
hr = cpStream->Close();
}
//Release the stream and voice object
cpStream.Release ();
cpVoice.Release();
}
Re: BCB and SAPI v5
Author: Bob Gonder
Date: Wed, 21 Nov 2007 20:53
Date: Wed, 21 Nov 2007 20:53
23 lines
1524 bytes
1524 bytes
Marc wrote: > ISpStream *cpStream; > hr = SPBindToFile( L"c:\\ttstemp.wav", SPFM_CREATE_ALWAYS, > &cpStream, I don't see where cpStream exists. It is an Input variable as well as Output. > & cAudioFmt.FormatId(),cAudioFmt.WaveFormatExPtr() ); > } http://msdn2.microsoft.com/en-us/library/aa911860.aspx inline HRESULT SPBindToFile( LPCWSTR pFileName, SPFILEMODE eMode, ISpStream** ppStream, const GUID* pFormatId = NULL, const WAVEFORMATEX* pWaveFormatEx = NULL, ULONGLONG* ullEventInterest = SPFEI_ALL_EVENTS );
Re: BCB and SAPI v5
Author: Remy Lebeau (TeamB)
Date: Wed, 21 Nov 2007 21:00
Date: Wed, 21 Nov 2007 21:00
37 lines
2169 bytes
2169 bytes
"Marc" <info@mawnet.com> wrote in message news:47446f75$1@newsgroups.borland.com... > When I include the "sphelper.h" needed for the SPBindToFile function, > I get plenty of errors in the *.h files. Such as? Please provide the actual errors, and the conditions you do to reproduce them. > Now I used the attached code and tried to write the TTS to a file. > > Unfortunately it fails every time with the call to SPBindToFile > (Error = E_INVALIDARG). That is because you really are passing invalid parameters to SPBindToFile(). > Has anyone ever successfully used SAPI v5 with BCB6 Yes. > CSpStreamFormat *cAudioFmt; <snip> > hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono); cAudioFmt is declared as a pointer. You need to use the '->' operator to access it. Also, you are not assigning anything to the pointer before trying to use it. > hr = SPBindToFile( L"c:\\ttstemp.wav", SPFM_CREATE_ALWAYS, > &cpStream, & cAudioFmt.FormatId(),cAudioFmt.WaveFormatExPtr() ); cpStream and cAudioFmt are still unintialized when passed in as input. You need to assign NULL to cpStream, and allocate something for cAudioFmt. Gambit
Re: BCB and SAPI v5
Author: Marc
Date: Wed, 21 Nov 2007 21:35
Date: Wed, 21 Nov 2007 21:35
110 lines
4843 bytes
4843 bytes
Gambit
> > Has anyone ever successfully used SAPI v5 with BCB6
>
> Yes.
At least this is comforting :-)
As for the code:
You are right, I made a mistake when I pasted my sample as I cleaned it for
display purposes.
I attached it again, cAudioFmt is not declared as pointer and should be
initialized, cpStream is now set to Null. (I tried to implement the sample
at
http://msdn2.microsoft.com/en-us/library/ms717065.aspx)
I still get the same problem though....
As for the compile errors, here they are (in German sorry):
[C++ Fehler] crtdbg.h(52): E2268 Aufruf der undefinierten Funktion '_T'
[C++ Fehler] crtdbg.h(52): E2034 Konvertierung von 'int' nach 'const char *'
nicht m�glich
[C++ Fehler] crtdbg.h(52): E2340 Keine �bereinstimmung des Typs beim
Parameter 2 ('const char *' erwartet, 'int' erhalten)
[C++ Fehler] SPDebug.h(337): E2303 Typname erwartet
[C++ Fehler] SPDebug.h(337): E2139 In Deklaration fehlt ;
[C++ Fehler] SPDebug.h(47): E2451 Undefiniertes Symbol 'm_hfilePrev'
[C++ Fehler] SPDebug.h(62): E2451 Undefiniertes Symbol '_CRT_WARN'
[C++ Fehler] SPDebug.h(69): E2451 Undefiniertes Symbol '_CRT_WARN'
[C++ Fehler] SPDebug.h(76): E2451 Undefiniertes Symbol '_CRT_WARN'
[C++ Fehler] SPDebug.h(86): E2451 Undefiniertes Symbol '_CRT_ASSERT'
[C++ Fehler] SPDebug.h(93): E2451 Undefiniertes Symbol '_CRT_WARN'
[C++ Fehler] SPDebug.h(177): E2451 Undefiniertes Symbol '_CRTDBG_MODE_DEBUG'
[C++ Fehler] SPDebug.h(185): E2451 Undefiniertes Symbol '_CRTDBG_MODE_WNDW'
[C++ Fehler] SPDebug.h(297): E2268 Aufruf der undefinierten Funktion
'_CrtSetReportMode'
[C++ Fehler] SPDebug.h(298): E2451 Undefiniertes Symbol '_CRTDBG_MODE_FILE'
[C++ Fehler] SPDebug.h(309): E2451 Undefiniertes Symbol 'm_hfilePrev'
[C++ Fehler] SPDebug.h(309): E2379 In Anweisung fehlt ;
[C++ Fehler] SPDebug.h(320): E2268 Aufruf der undefinierten Funktion
'_CrtSetReportMode'
[C++ Fehler] SPDebug.h(321): E2451 Undefiniertes Symbol '_CRTDBG_MODE_FILE'
[C++ Fehler] SPDebug.h(323): E2121 ) fehlt beim Funktionsaufruf
[C++ Fehler] SPDebug.h(371): E2268 Aufruf der undefinierten Funktion '_RPT1'
[C++ Fehler] SPDebug.h(371): E2451 Undefiniertes Symbol '_CRT_WARN'
[C++ Fehler] SPDebug.h(380): E2451 Undefiniertes Symbol '_CRT_WARN'
[C++ Fehler] SPDebug.h(380): E2268 Aufruf der undefinierten Funktion '_RPT1'
[C++ Fehler] sphelper.h(446): E2268 Aufruf der undefinierten Funktion
'_RPT3'
[C++ Fehler] sphelper.h(446): E2228 Zu viele Fehlermeldungen oder Warnungen
What puzzels me is that when I search for _CRTDBG_MODE_DEBUG on my PC I
never get actually a definition of it, hence I am wondering if I am missing
some files...
Rds
Marc
//*******************************************************************
void TSpeech::SpeakToFile(String Words, String sFileName)
{
HRESULT hr = S_OK;
ISpStream *cpStream=NULL;
ISpVoice *cpVoice;
CSpStreamFormat cAudioFmt;
//Create a SAPI Voice
hr = CoCreateInstance( CLSID_SpVoice,NULL,CLSCTX_ALL,IID_ISpVoice,
(void**)&cpVoice);
//Set the audio format
if(SUCCEEDED(hr))
hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono);
//Call SPBindToFile, a SAPI helper method, to bind the audio stream to the
file
if(SUCCEEDED(hr))
hr = SPBindToFile( L"c:\\ttstemp.wav", SPFM_CREATE_ALWAYS, &cpStream,
&cAudioFmt.FormatId(),cAudioFmt.WaveFormatExPtr());
if (hr == E_INVALIDARG)
MessageBox(NULL,"E_INVALIDARG","Error",MB_OK);
//set the output to cpStream so that the output audio data will be stored
in cpStream
if(SUCCEEDED(hr))
hr = cpVoice->SetOutput( cpStream, TRUE );
//Speak the text �hello world� synchronously
if(SUCCEEDED(hr))
hr = cpVoice->Speak( L"Hello World", SPF_DEFAULT, NULL );
//close the stream
if(SUCCEEDED(hr))
hr = cpStream->Close();
//Release the stream
cpStream->Release ();
cpVoice->Release();
}
Re: BCB and SAPI v5
Author: Marc
Date: Wed, 21 Nov 2007 21:41
Date: Wed, 21 Nov 2007 21:41
43 lines
2113 bytes
2113 bytes
Bob >> ppStream [in, out] Address of a pointer to an object implementing ISpStream. On input, this object represents the audio stream to bind to the file. On output, If the function succeeds, this parameter indicates the bound stream object. << The SPBindToFile should return the stream through this variable for the later use is cpVoice->SetOutput. Rds Marc "Bob Gonder" <notbg@notmindspring.invalid> schrieb im Newsbeitrag news:6h59k35g5gtir23uc0evqfrenb3tgp0g2c@4ax.com... > Marc wrote: > >> ISpStream *cpStream; > >> hr = SPBindToFile( L"c:\\ttstemp.wav", SPFM_CREATE_ALWAYS, >> &cpStream, > > I don't see where cpStream exists. > It is an Input variable as well as Output. > >> & cAudioFmt.FormatId(),cAudioFmt.WaveFormatExPtr() ); >> } > > http://msdn2.microsoft.com/en-us/library/aa911860.aspx > > inline HRESULT SPBindToFile( > LPCWSTR pFileName, > SPFILEMODE eMode, > ISpStream** ppStream, > const GUID* pFormatId = NULL, > const WAVEFORMATEX* pWaveFormatEx = NULL, > ULONGLONG* ullEventInterest = SPFEI_ALL_EVENTS > ); > >
Re: BCB and SAPI v5
Author: Remy Lebeau (TeamB)
Date: Wed, 21 Nov 2007 22:40
Date: Wed, 21 Nov 2007 22:40
176 lines
6694 bytes
6694 bytes
"Marc" <info@mawnet.com> wrote in message
news:4744a4e3$1@newsgroups.borland.com...
> You are right, I made a mistake when I pasted my sample as I
> cleaned it for display purposes.
Always copy/paste your actual code. It reduces confusion and errors.
> I tried to implement the sample at
> http://msdn2.microsoft.com/en-us/library/ms717065.aspx
You are not using the example exactly as it is provided. For instance, you
are not making use of the CComPtr class to manage your pointers. That in
itself would not be causing your error, though.
Try this:
void TSpeech::SpeakToFile(const WideString &sWords, const WideString
&sFileName)
{
HRESULT hr;
CComPtr<ISpStream> cpStream;
CComPtr<ISpVoice> cpVoice;
CSpStreamFormat cAudioFmt;
//Create a SAPI Voice
hr = CoCreateInstance( CLSID_SpVoice, NULL, CLSCTX_LOCAL_SERVER,
IID_ISpVoice, (void**)&cpVoice);
//Set the audio format
if( SUCCEEDED(hr) )
hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono);
//Call SPBindToFile, a SAPI helper method, to bind the audio stream
to the file
if( SUCCEEDED(hr) )
{
hr = SPBindToFile(sFileName, SPFM_CREATE_ALWAYS, &cpStream,
&cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr());
}
if( hr == E_INVALIDARG )
MessageBox(NULL, "E_INVALIDARG", "Error", MB_OK);
//set the output to cpStream so that the output audio data will be
stored in cpStream
if( SUCCEEDED(hr) )
hr = cpVoice->SetOutput(cpStream, TRUE);
//Speak the text "hello world" synchronously
if( SUCCEEDED(hr) )
hr = cpVoice->Speak(sWords, SPF_DEFAULT, NULL);
//close the stream
if( SUCCEEDED(hr) )
hr = cpStream->Close();
}
> As for the compile errors, here they are (in German sorry):
There are plenty of online translators available ;-)
> [C++ Fehler] crtdbg.h(52): E2268 Aufruf der undefinierten Funktion '_T'
Call of undefined function '_ T'
_T is a macro defined in tchar.h. It operates the same as the TEXT() macro
in winnt.h - it takes a character/string literal as input and compiles it as
either char* or wchar_t* depending on whether UNICODE is defined. Try
including tchar.h in your source code before other the affected header
files.
> [C++ Fehler] crtdbg.h(52): E2034 Konvertierung von 'int' nach 'const char
> *' nicht m�glich
Cannot convert 'int' to 'const char *'
That is pretty self-explanatory. That particular line is calling wsprintf()
using the TEXT() macro:
::wsprintf(msg, TEXT("%s failed - %s/%d"), expr, file, line);
That is probably just an issue with TEXT() not being defined before being
used, or it is being re-defined somewhere else.
> [C++ Fehler] crtdbg.h(52): E2340 Keine �bereinstimmung des Typs beim
> Parameter 2 ('const char *' erwartet, 'int' erhalten)
Type mismatch in parameter 2 (expected 'const char *', got 'int')
That is a side-effect of the previous error.
> [C++ Fehler] SPDebug.h(337): E2303 Typname erwartet
Typename expected
That particular line is trying to declare a variable of type _HFILE:
_HFILE m_hfilePrev;
I don't see _HFILE begin defined in any header files I have, though. So it
makes sense for that to be reported as an unknown type. You'll just have to
define it manually in your code before including SPDebug.h until you can
figure out where it is supposed to come from:
#define _HFILE HANDLE
> [C++ Fehler] SPDebug.h(337): E2139 In Deklaration fehlt ;
Declaration is missing ;
That is a side-effect of the previous error.
> [C++ Fehler] SPDebug.h(47): E2451 Undefiniertes Symbol 'm_hfilePrev'
Undefined Symbol 'm_hfilePrev'
Another side-effect. Since __HFILE is not defined anywhere, m_hfilePrev is
not fully declared, either.
> [C++ Fehler] SPDebug.h(62): E2451 Undefiniertes Symbol '_CRT_WARN'
> [C++ Fehler] SPDebug.h(69): E2451 Undefiniertes Symbol '_CRT_WARN'
> [C++ Fehler] SPDebug.h(76): E2451 Undefiniertes Symbol '_CRT_WARN'
> [C++ Fehler] SPDebug.h(86): E2451 Undefiniertes Symbol '_CRT_ASSERT'
> [C++ Fehler] SPDebug.h(93): E2451 Undefiniertes Symbol '_CRT_WARN'
> [C++ Fehler] SPDebug.h(177): E2451 Undefiniertes Symbol
> '_CRTDBG_MODE_DEBUG'
> [C++ Fehler] SPDebug.h(185): E2451 Undefiniertes Symbol
> '_CRTDBG_MODE_WNDW'
> [C++ Fehler] SPDebug.h(298): E2451 Undefiniertes Symbol
> '_CRTDBG_MODE_FILE'
Those are also not defined in any header files I have. It looks like they
are supposed to come from CRTDBG.H, but Borland appears to have edited that
file for their own purposes.
> [C++ Fehler] SPDebug.h(297): E2268 Aufruf der undefinierten Funktion
> '_CrtSetReportMode'
Call of undefined function '_CrtSetReportMode'
Self-explanatory. I believe that was also supposed to come from CRTDBG.H.
> [C++ Fehler] SPDebug.h(309): E2379 In Anweisung fehlt ;
Instruction is missing ;
That is a side-effect of the previous error.
> [C++ Fehler] SPDebug.h(323): E2121 ) fehlt beim Funktionsaufruf
) is missing in function call
Another side effect.
> [C++ Fehler] SPDebug.h(371): E2268 Aufruf der undefinierten Funktion
> '_RPT1'
> [C++ Fehler] sphelper.h(446): E2268 Aufruf der undefinierten Funktion
> '_RPT3'
Call of undefined function '_RPT1'
Call of undefined function '_RPT3'
More macros missing from CRTDBG.H
> [C++ Fehler] sphelper.h(446): E2228 Zu viele Fehlermeldungen oder
> Warnungen
Too many error messages or warnings
Enough said.
Gambit
Re: BCB and SAPI v5
Author: Marc
Date: Thu, 22 Nov 2007 11:14
Date: Thu, 22 Nov 2007 11:14
351 lines
12647 bytes
12647 bytes
Gambit
First of all thank you for your time and effort trying to sort this thing
out.
I used your sample (The complete code is attached here) but still no joy
(Same error E_INVALIDARG).
I needed to modify the voice creation from CLSCTX_LOCAL_SERVER to CLSCTX_ALL
as otherwise it would not work. Now it plays though the speaker but then
fails with E_INVALIDARG in the SPBindToFile.
As for the compile errors:
As you can see I already had to define the two GUID SPDFID_Text and
SPDFID_WaveFormatEx with some bogus values. Those GUID are declared as
EXTERN_C in sapi.h and I have no idea where (and with what) they should be
declared.
> You'll just have to define it manually in your code before including
> SPDebug.h
Sure I could go now through all *.h files and complete the missing
declarations, some of them are variables, some of them are functions (IE
_RPT1).
But to do so I would need to understand the whole code and to be quite
honest this is beyond my competence. All I wanted is to use (not redevelop)
SAPI im my application.
If I have to modify half of the provided Borland *.h files then this is not
worth it and I go back to the OCX. This is rather disappointing.
OK I am exagerating a little here, but this is why I asked the question if
someone has successfully implemented SAPI (all functions, not only
Speak("Hello world")) and BCB.
I can not imagine that everybody had to rewrite half of the provided *.h
files (again exagerating).
Rds
Marc
//---------------------------------------------------------------------------
//Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#include <sapi.h> //For ISp definitions - part of SDK
#include <sphelper.h> //For SPBindToFile
#pragma hdrstop
#include "Unit1.h"
//I needed to define those GUID as they are declared as EXTERN_C in sapi.h
//No idea what GUID to use here
const GUID SPDFID_Text =
StringToGUID("{CFDF4A60-6FFC-11D1-BE46-00A0C95A6A5C}");
const GUID SPDFID_WaveFormatEx =
StringToGUID("{CFDF4A60-6FFC-11D1-BE46-00A0C95A6A5C}");
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TForm1::Test()
{
HRESULT hr = S_OK;
CComPtr<ISpStream> cpStream;
CComPtr<ISpVoice> cpVoice;
CSpStreamFormat cAudioFmt;
cpVoice = NULL;
::CoInitialize(NULL);
//Create a SAPI voice:
//Using CLSCTX_LOCAL_SERVER fails here...
hr = CoCreateInstance( CLSID_SpVoice,NULL,CLSCTX_ALL,IID_ISpVoice,
(void**)&cpVoice);
if( hr != S_OK )
MessageBox(NULL, "CAN NOT CREATE VOICE", "ERROR", MB_OK);
if(SUCCEEDED(hr))
cpVoice->Speak(L"Hello world",SPF_DEFAULT,NULL);
if( hr != S_OK )
MessageBox(NULL, "CAN NOT SPEAK", "Error", MB_OK);
//Set the audio format
if( SUCCEEDED(hr) )
hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono);
if( hr != S_OK )
MessageBox(NULL, "CAN NOT SET FORMAT", "Error", MB_OK);
//Call SPBindToFile, a SAPI helper method, to bind the audio stream to
the file
if( SUCCEEDED(hr) )
hr = SPBindToFile(L"c:\\test.wav", SPFM_CREATE_ALWAYS, &cpStream,
&cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr());
if( hr == E_INVALIDARG )
MessageBox(NULL, "E_INVALIDARG", "Error", MB_OK);
//set the output to cpStream so that the output audio data will be
stored in cpStream
if( SUCCEEDED(hr) )
hr = cpVoice->SetOutput(cpStream, TRUE);
if( hr != S_OK )
MessageBox(NULL, "CAN NOT SetOutput", "Error", MB_OK);
//Speak the text "hello world" synchronously
if( SUCCEEDED(hr) )
cpVoice->Speak(L"Hello world",SPF_DEFAULT,NULL);
if( hr != S_OK )
MessageBox(NULL, "CAN NOT SPEAK TO FILE", "Error", MB_OK);
//close the stream
if( SUCCEEDED(hr) )
hr = cpStream->Close();
if(SUCCEEDED(hr))
cpVoice = NULL;
::CoUninitialize();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Test();
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//Unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // Von der IDE verwaltete Komponenten
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // Anwender-Deklarationen
void Test();
public: // Anwender-Deklarationen
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> schrieb im Newsbeitrag
news:4744b412$1@newsgroups.borland.com...
>
> "Marc" <info@mawnet.com> wrote in message
> news:4744a4e3$1@newsgroups.borland.com...
>
>> You are right, I made a mistake when I pasted my sample as I
>> cleaned it for display purposes.
>
> Always copy/paste your actual code. It reduces confusion and errors.
>
>> I tried to implement the sample at
>> http://msdn2.microsoft.com/en-us/library/ms717065.aspx
>
> You are not using the example exactly as it is provided. For instance,
> you are not making use of the CComPtr class to manage your pointers. That
> in itself would not be causing your error, though.
>
> Try this:
>
> void TSpeech::SpeakToFile(const WideString &sWords, const WideString
> &sFileName)
> {
> HRESULT hr;
> CComPtr<ISpStream> cpStream;
> CComPtr<ISpVoice> cpVoice;
> CSpStreamFormat cAudioFmt;
>
>
> //Create a SAPI Voice
> hr = CoCreateInstance( CLSID_SpVoice, NULL, CLSCTX_LOCAL_SERVER,
> IID_ISpVoice, (void**)&cpVoice);
>
> //Set the audio format
> if( SUCCEEDED(hr) )
> hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono);
>
> //Call SPBindToFile, a SAPI helper method, to bind the audio
> stream to the file
> if( SUCCEEDED(hr) )
> {
> hr = SPBindToFile(sFileName, SPFM_CREATE_ALWAYS, &cpStream,
> &cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr());
> }
>
> if( hr == E_INVALIDARG )
> MessageBox(NULL, "E_INVALIDARG", "Error", MB_OK);
>
> //set the output to cpStream so that the output audio data will be
> stored in cpStream
> if( SUCCEEDED(hr) )
> hr = cpVoice->SetOutput(cpStream, TRUE);
>
> //Speak the text "hello world" synchronously
> if( SUCCEEDED(hr) )
> hr = cpVoice->Speak(sWords, SPF_DEFAULT, NULL);
>
> //close the stream
> if( SUCCEEDED(hr) )
> hr = cpStream->Close();
> }
>
>> As for the compile errors, here they are (in German sorry):
>
> There are plenty of online translators available ;-)
>
>> [C++ Fehler] crtdbg.h(52): E2268 Aufruf der undefinierten Funktion '_T'
>
> Call of undefined function '_ T'
>
> _T is a macro defined in tchar.h. It operates the same as the TEXT()
> macro in winnt.h - it takes a character/string literal as input and
> compiles it as either char* or wchar_t* depending on whether UNICODE is
> defined. Try including tchar.h in your source code before other the
> affected header files.
>
>> [C++ Fehler] crtdbg.h(52): E2034 Konvertierung von 'int' nach 'const char
>> *' nicht m�glich
>
> Cannot convert 'int' to 'const char *'
>
> That is pretty self-explanatory. That particular line is calling
> wsprintf() using the TEXT() macro:
>
> ::wsprintf(msg, TEXT("%s failed - %s/%d"), expr, file, line);
>
> That is probably just an issue with TEXT() not being defined before being
> used, or it is being re-defined somewhere else.
>
>> [C++ Fehler] crtdbg.h(52): E2340 Keine �bereinstimmung des Typs beim
>> Parameter 2 ('const char *' erwartet, 'int' erhalten)
>
> Type mismatch in parameter 2 (expected 'const char *', got 'int')
>
> That is a side-effect of the previous error.
>
>> [C++ Fehler] SPDebug.h(337): E2303 Typname erwartet
>
> Typename expected
>
> That particular line is trying to declare a variable of type _HFILE:
>
> _HFILE m_hfilePrev;
>
> I don't see _HFILE begin defined in any header files I have, though. So
> it makes sense for that to be reported as an unknown type. You'll just
> have to define it manually in your code before including SPDebug.h until
> you can figure out where it is supposed to come from:
>
> #define _HFILE HANDLE
>
>> [C++ Fehler] SPDebug.h(337): E2139 In Deklaration fehlt ;
>
> Declaration is missing ;
>
> That is a side-effect of the previous error.
>
>> [C++ Fehler] SPDebug.h(47): E2451 Undefiniertes Symbol 'm_hfilePrev'
>
> Undefined Symbol 'm_hfilePrev'
>
> Another side-effect. Since __HFILE is not defined anywhere, m_hfilePrev
> is not fully declared, either.
>
>> [C++ Fehler] SPDebug.h(62): E2451 Undefiniertes Symbol '_CRT_WARN'
>> [C++ Fehler] SPDebug.h(69): E2451 Undefiniertes Symbol '_CRT_WARN'
>> [C++ Fehler] SPDebug.h(76): E2451 Undefiniertes Symbol '_CRT_WARN'
>> [C++ Fehler] SPDebug.h(86): E2451 Undefiniertes Symbol '_CRT_ASSERT'
>> [C++ Fehler] SPDebug.h(93): E2451 Undefiniertes Symbol '_CRT_WARN'
>> [C++ Fehler] SPDebug.h(177): E2451 Undefiniertes Symbol
>> '_CRTDBG_MODE_DEBUG'
>> [C++ Fehler] SPDebug.h(185): E2451 Undefiniertes Symbol
>> '_CRTDBG_MODE_WNDW'
>> [C++ Fehler] SPDebug.h(298): E2451 Undefiniertes Symbol
>> '_CRTDBG_MODE_FILE'
>
> Those are also not defined in any header files I have. It looks like they
> are supposed to come from CRTDBG.H, but Borland appears to have edited
> that file for their own purposes.
>
>> [C++ Fehler] SPDebug.h(297): E2268 Aufruf der undefinierten Funktion
>> '_CrtSetReportMode'
>
> Call of undefined function '_CrtSetReportMode'
>
> Self-explanatory. I believe that was also supposed to come from CRTDBG.H.
>
>> [C++ Fehler] SPDebug.h(309): E2379 In Anweisung fehlt ;
>
> Instruction is missing ;
>
> That is a side-effect of the previous error.
>
>> [C++ Fehler] SPDebug.h(323): E2121 ) fehlt beim Funktionsaufruf
>
> ) is missing in function call
>
> Another side effect.
>
>> [C++ Fehler] SPDebug.h(371): E2268 Aufruf der undefinierten Funktion
>> '_RPT1'
>> [C++ Fehler] sphelper.h(446): E2268 Aufruf der undefinierten Funktion
>> '_RPT3'
>
> Call of undefined function '_RPT1'
> Call of undefined function '_RPT3'
>
> More macros missing from CRTDBG.H
>
>> [C++ Fehler] sphelper.h(446): E2228 Zu viele Fehlermeldungen oder
>> Warnungen
>
> Too many error messages or warnings
>
> Enough said.
>
>
> Gambit
>
Re: BCB and SAPI v5
Author: Marc
Date: Thu, 22 Nov 2007 12:15
Date: Thu, 22 Nov 2007 12:15
434 lines
15216 bytes
15216 bytes
I think I may have made a step further...
In the definition of SPBindToFile (sphelper.h) there is a call to
HRESULT hr = ::CoCreateInstance(CLSID_SpStream, NULL, CLSCTX_ALL,
__uuidof(*ppStream), (void **)ppStream);
as this returned an error "E2496 Invalid call to uuidof(struct type |
variable)"
I replaced it with
HRESULT hr = ::CoCreateInstance(CLSID_SpStream, NULL, CLSCTX_ALL,
CLSID_SpStream, (void **)ppStream);
May this be the reason for the E_INVALIDARG ? What is the correct syntax for
__uuidof(*ppStream) ?
As for the compile errors:
I added the debugging macros below and defined
int _CrtSetReportMode(
int reportType,
int reportMode
);
_HFILE _CrtSetReportFile(
int reportType,
_HFILE reportFile
);
im SPDebug.h, this helped.
Rds
Marc
//*************************************************************
/* Define some debugging macros */
#if (defined(WIN32) && !defined(_WIN32_WCE)) /**[10]**/
#include <crtdbg.h>
#else
#define _CRT_WARN 1
#define _CRT_ASSERT 2
#define _CRTDBG_MODE_DEBUG 3
#define _CRTDBG_MODE_WNDW 4
#define _CRTDBG_MODE_FILE 5
#if !defined(_DEBUG) && !defined(DEBUG)
#ifndef _ASSERT
#define _ASSERT(a)
#endif
#define _RPT0(a, b)
#define _RPT1(a, b, a1)
#define _RPT2(a, b, a1, a2)
#define _RPT3(a, b, a1, a2, a3)
#define _RPT4(a, b, a1, a2, a3, a4)
#else /* _DEBUG */
#ifndef _ASSERT
#define _ASSERT(a)
#endif
#define _RPT0(a, b) fprintf(stderr, b)
#define _RPT1(a, b, a1) fprintf(stderr, b, a1)
#define _RPT2(a, b, a1, a2) fprintf(stderr, b, a1, a2)
#define _RPT3(a, b, a1, a2, a3) fprintf(stderr, b, a1, a2, a3)
#define _RPT4(a, b, a1, a2, a3, a4) fprintf(stderr, b, a1, a2, a3, a4)
#endif /* _DEBUG */
#endif /* WIN32 */
"Marc" <info@mawnet.com> schrieb im Newsbeitrag
news:474564ea$1@newsgroups.borland.com...
> Gambit
>
> First of all thank you for your time and effort trying to sort this thing
> out.
> I used your sample (The complete code is attached here) but still no joy
> (Same error E_INVALIDARG).
> I needed to modify the voice creation from CLSCTX_LOCAL_SERVER to
> CLSCTX_ALL as otherwise it would not work. Now it plays though the speaker
> but then fails with E_INVALIDARG in the SPBindToFile.
>
>
> As for the compile errors:
> As you can see I already had to define the two GUID SPDFID_Text and
> SPDFID_WaveFormatEx with some bogus values. Those GUID are declared as
> EXTERN_C in sapi.h and I have no idea where (and with what) they should be
> declared.
>
>> You'll just have to define it manually in your code before including
>> SPDebug.h
>
> Sure I could go now through all *.h files and complete the missing
> declarations, some of them are variables, some of them are functions (IE
> _RPT1).
>
> But to do so I would need to understand the whole code and to be quite
> honest this is beyond my competence. All I wanted is to use (not
> redevelop) SAPI im my application.
> If I have to modify half of the provided Borland *.h files then this is
> not worth it and I go back to the OCX. This is rather disappointing.
> OK I am exagerating a little here, but this is why I asked the question if
> someone has successfully implemented SAPI (all functions, not only
> Speak("Hello world")) and BCB.
> I can not imagine that everybody had to rewrite half of the provided *.h
> files (again exagerating).
>
> Rds
> Marc
>
>
>
>
> //---------------------------------------------------------------------------
> //Unit1.cpp
> //---------------------------------------------------------------------------
> #include <vcl.h>
> #include <sapi.h> //For ISp definitions - part of SDK
> #include <sphelper.h> //For SPBindToFile
> #pragma hdrstop
>
> #include "Unit1.h"
>
> //I needed to define those GUID as they are declared as EXTERN_C in sapi.h
> //No idea what GUID to use here
> const GUID SPDFID_Text =
> StringToGUID("{CFDF4A60-6FFC-11D1-BE46-00A0C95A6A5C}");
> const GUID SPDFID_WaveFormatEx =
> StringToGUID("{CFDF4A60-6FFC-11D1-BE46-00A0C95A6A5C}");
>
> //---------------------------------------------------------------------------
> #pragma package(smart_init)
> #pragma resource "*.dfm"
> TForm1 *Form1;
> //---------------------------------------------------------------------------
> __fastcall TForm1::TForm1(TComponent* Owner)
> : TForm(Owner)
> {
> }
> //---------------------------------------------------------------------------
> void TForm1::Test()
> {
> HRESULT hr = S_OK;
> CComPtr<ISpStream> cpStream;
> CComPtr<ISpVoice> cpVoice;
> CSpStreamFormat cAudioFmt;
>
> cpVoice = NULL;
> ::CoInitialize(NULL);
>
> //Create a SAPI voice:
> //Using CLSCTX_LOCAL_SERVER fails here...
>
> hr = CoCreateInstance( CLSID_SpVoice,NULL,CLSCTX_ALL,IID_ISpVoice,
> (void**)&cpVoice);
> if( hr != S_OK )
> MessageBox(NULL, "CAN NOT CREATE VOICE", "ERROR", MB_OK);
>
> if(SUCCEEDED(hr))
> cpVoice->Speak(L"Hello world",SPF_DEFAULT,NULL);
> if( hr != S_OK )
> MessageBox(NULL, "CAN NOT SPEAK", "Error", MB_OK);
>
> //Set the audio format
> if( SUCCEEDED(hr) )
> hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono);
> if( hr != S_OK )
> MessageBox(NULL, "CAN NOT SET FORMAT", "Error", MB_OK);
>
> //Call SPBindToFile, a SAPI helper method, to bind the audio stream
> to the file
> if( SUCCEEDED(hr) )
> hr = SPBindToFile(L"c:\\test.wav", SPFM_CREATE_ALWAYS,
> &cpStream, &cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr());
> if( hr == E_INVALIDARG )
> MessageBox(NULL, "E_INVALIDARG", "Error", MB_OK);
>
> //set the output to cpStream so that the output audio data will be
> stored in cpStream
> if( SUCCEEDED(hr) )
> hr = cpVoice->SetOutput(cpStream, TRUE);
> if( hr != S_OK )
> MessageBox(NULL, "CAN NOT SetOutput", "Error", MB_OK);
>
> //Speak the text "hello world" synchronously
> if( SUCCEEDED(hr) )
> cpVoice->Speak(L"Hello world",SPF_DEFAULT,NULL);
> if( hr != S_OK )
> MessageBox(NULL, "CAN NOT SPEAK TO FILE", "Error", MB_OK);
>
> //close the stream
> if( SUCCEEDED(hr) )
> hr = cpStream->Close();
>
> if(SUCCEEDED(hr))
> cpVoice = NULL;
>
> ::CoUninitialize();
> }
> //---------------------------------------------------------------------------
> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
> Test();
> }
> //---------------------------------------------------------------------------
>
>
>
>
> //---------------------------------------------------------------------------
> //Unit1.h
> //---------------------------------------------------------------------------
> #ifndef Unit1H
> #define Unit1H
> //---------------------------------------------------------------------------
> #include <Classes.hpp>
> #include <Controls.hpp>
> #include <StdCtrls.hpp>
> #include <Forms.hpp>
> //---------------------------------------------------------------------------
> class TForm1 : public TForm
> {
> __published: // Von der IDE verwaltete Komponenten
> TButton *Button1;
> void __fastcall Button1Click(TObject *Sender);
> private: // Anwender-Deklarationen
> void Test();
> public: // Anwender-Deklarationen
> __fastcall TForm1(TComponent* Owner);
> };
> //---------------------------------------------------------------------------
> extern PACKAGE TForm1 *Form1;
> //---------------------------------------------------------------------------
> #endif
>
>
>
>
>
>
>
>
>
>
> "Remy Lebeau (TeamB)" <no.spam@no.spam.com> schrieb im Newsbeitrag
> news:4744b412$1@newsgroups.borland.com...
>>
>> "Marc" <info@mawnet.com> wrote in message
>> news:4744a4e3$1@newsgroups.borland.com...
>>
>>> You are right, I made a mistake when I pasted my sample as I
>>> cleaned it for display purposes.
>>
>> Always copy/paste your actual code. It reduces confusion and errors.
>>
>>> I tried to implement the sample at
>>> http://msdn2.microsoft.com/en-us/library/ms717065.aspx
>>
>> You are not using the example exactly as it is provided. For instance,
>> you are not making use of the CComPtr class to manage your pointers.
>> That in itself would not be causing your error, though.
>>
>> Try this:
>>
>> void TSpeech::SpeakToFile(const WideString &sWords, const WideString
>> &sFileName)
>> {
>> HRESULT hr;
>> CComPtr<ISpStream> cpStream;
>> CComPtr<ISpVoice> cpVoice;
>> CSpStreamFormat cAudioFmt;
>>
>>
>> //Create a SAPI Voice
>> hr = CoCreateInstance( CLSID_SpVoice, NULL, CLSCTX_LOCAL_SERVER,
>> IID_ISpVoice, (void**)&cpVoice);
>>
>> //Set the audio format
>> if( SUCCEEDED(hr) )
>> hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono);
>>
>> //Call SPBindToFile, a SAPI helper method, to bind the audio
>> stream to the file
>> if( SUCCEEDED(hr) )
>> {
>> hr = SPBindToFile(sFileName, SPFM_CREATE_ALWAYS, &cpStream,
>> &cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr());
>> }
>>
>> if( hr == E_INVALIDARG )
>> MessageBox(NULL, "E_INVALIDARG", "Error", MB_OK);
>>
>> //set the output to cpStream so that the output audio data will be
>> stored in cpStream
>> if( SUCCEEDED(hr) )
>> hr = cpVoice->SetOutput(cpStream, TRUE);
>>
>> //Speak the text "hello world" synchronously
>> if( SUCCEEDED(hr) )
>> hr = cpVoice->Speak(sWords, SPF_DEFAULT, NULL);
>>
>> //close the stream
>> if( SUCCEEDED(hr) )
>> hr = cpStream->Close();
>> }
>>
>>> As for the compile errors, here they are (in German sorry):
>>
>> There are plenty of online translators available ;-)
>>
>>> [C++ Fehler] crtdbg.h(52): E2268 Aufruf der undefinierten Funktion '_T'
>>
>> Call of undefined function '_ T'
>>
>> _T is a macro defined in tchar.h. It operates the same as the TEXT()
>> macro in winnt.h - it takes a character/string literal as input and
>> compiles it as either char* or wchar_t* depending on whether UNICODE is
>> defined. Try including tchar.h in your source code before other the
>> affected header files.
>>
>>> [C++ Fehler] crtdbg.h(52): E2034 Konvertierung von 'int' nach 'const
>>> char *' nicht m�glich
>>
>> Cannot convert 'int' to 'const char *'
>>
>> That is pretty self-explanatory. That particular line is calling
>> wsprintf() using the TEXT() macro:
>>
>> ::wsprintf(msg, TEXT("%s failed - %s/%d"), expr, file, line);
>>
>> That is probably just an issue with TEXT() not being defined before being
>> used, or it is being re-defined somewhere else.
>>
>>> [C++ Fehler] crtdbg.h(52): E2340 Keine �bereinstimmung des Typs beim
>>> Parameter 2 ('const char *' erwartet, 'int' erhalten)
>>
>> Type mismatch in parameter 2 (expected 'const char *', got 'int')
>>
>> That is a side-effect of the previous error.
>>
>>> [C++ Fehler] SPDebug.h(337): E2303 Typname erwartet
>>
>> Typename expected
>>
>> That particular line is trying to declare a variable of type _HFILE:
>>
>> _HFILE m_hfilePrev;
>>
>> I don't see _HFILE begin defined in any header files I have, though. So
>> it makes sense for that to be reported as an unknown type. You'll just
>> have to define it manually in your code before including SPDebug.h until
>> you can figure out where it is supposed to come from:
>>
>> #define _HFILE HANDLE
>>
>>> [C++ Fehler] SPDebug.h(337): E2139 In Deklaration fehlt ;
>>
>> Declaration is missing ;
>>
>> That is a side-effect of the previous error.
>>
>>> [C++ Fehler] SPDebug.h(47): E2451 Undefiniertes Symbol 'm_hfilePrev'
>>
>> Undefined Symbol 'm_hfilePrev'
>>
>> Another side-effect. Since __HFILE is not defined anywhere, m_hfilePrev
>> is not fully declared, either.
>>
>>> [C++ Fehler] SPDebug.h(62): E2451 Undefiniertes Symbol '_CRT_WARN'
>>> [C++ Fehler] SPDebug.h(69): E2451 Undefiniertes Symbol '_CRT_WARN'
>>> [C++ Fehler] SPDebug.h(76): E2451 Undefiniertes Symbol '_CRT_WARN'
>>> [C++ Fehler] SPDebug.h(86): E2451 Undefiniertes Symbol '_CRT_ASSERT'
>>> [C++ Fehler] SPDebug.h(93): E2451 Undefiniertes Symbol '_CRT_WARN'
>>> [C++ Fehler] SPDebug.h(177): E2451 Undefiniertes Symbol
>>> '_CRTDBG_MODE_DEBUG'
>>> [C++ Fehler] SPDebug.h(185): E2451 Undefiniertes Symbol
>>> '_CRTDBG_MODE_WNDW'
>>> [C++ Fehler] SPDebug.h(298): E2451 Undefiniertes Symbol
>>> '_CRTDBG_MODE_FILE'
>>
>> Those are also not defined in any header files I have. It looks like
>> they are supposed to come from CRTDBG.H, but Borland appears to have
>> edited that file for their own purposes.
>>
>>> [C++ Fehler] SPDebug.h(297): E2268 Aufruf der undefinierten Funktion
>>> '_CrtSetReportMode'
>>
>> Call of undefined function '_CrtSetReportMode'
>>
>> Self-explanatory. I believe that was also supposed to come from
>> CRTDBG.H.
>>
>>> [C++ Fehler] SPDebug.h(309): E2379 In Anweisung fehlt ;
>>
>> Instruction is missing ;
>>
>> That is a side-effect of the previous error.
>>
>>> [C++ Fehler] SPDebug.h(323): E2121 ) fehlt beim Funktionsaufruf
>>
>> ) is missing in function call
>>
>> Another side effect.
>>
>>> [C++ Fehler] SPDebug.h(371): E2268 Aufruf der undefinierten Funktion
>>> '_RPT1'
>>> [C++ Fehler] sphelper.h(446): E2268 Aufruf der undefinierten Funktion
>>> '_RPT3'
>>
>> Call of undefined function '_RPT1'
>> Call of undefined function '_RPT3'
>>
>> More macros missing from CRTDBG.H
>>
>>> [C++ Fehler] sphelper.h(446): E2228 Zu viele Fehlermeldungen oder
>>> Warnungen
>>
>> Too many error messages or warnings
>>
>> Enough said.
>>
>>
>> Gambit
>>
>
>
Re: BCB and SAPI v5
Author: Marc
Date: Thu, 22 Nov 2007 13:38
Date: Thu, 22 Nov 2007 13:38
465 lines
16476 bytes
16476 bytes
In order to reduce compelexity I took the code out of the SPBindToFile
function and put it directly into my code:
hr = CoCreateInstance( CLSID_SpStream, NULL, CLSCTX_ALL, IID_ISpStream,
(void **)&cpStream);
if (SUCCEEDED(hr))
{
hr = cpStream->BindToFile(WideString("c:\\test.wav"), SPFM_CREATE_ALWAYS,
&cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr(), SPFEI_ALL_EVENTS);
if (FAILED(hr))
{
cpStream->Release();
cpStream = NULL;
}
}
Now I am sure that the cpStream is created, but the call to
cpStream->BindToFile still fails with E_INVALIDARG.
So the problem must be with the cAudioFmt...
Rds
Marc
"Marc" <info@mawnet.com> schrieb im Newsbeitrag
news:47457331@newsgroups.borland.com...
>I think I may have made a step further...
>
> In the definition of SPBindToFile (sphelper.h) there is a call to
>
> HRESULT hr = ::CoCreateInstance(CLSID_SpStream, NULL, CLSCTX_ALL,
> __uuidof(*ppStream), (void **)ppStream);
>
> as this returned an error "E2496 Invalid call to uuidof(struct type |
> variable)"
>
> I replaced it with
>
> HRESULT hr = ::CoCreateInstance(CLSID_SpStream, NULL, CLSCTX_ALL,
> CLSID_SpStream, (void **)ppStream);
>
> May this be the reason for the E_INVALIDARG ? What is the correct syntax
> for __uuidof(*ppStream) ?
>
>
> As for the compile errors:
> I added the debugging macros below and defined
>
> int _CrtSetReportMode(
> int reportType,
> int reportMode
> );
> _HFILE _CrtSetReportFile(
> int reportType,
> _HFILE reportFile
> );
>
> im SPDebug.h, this helped.
>
>
> Rds
> Marc
>
>
>
> //*************************************************************
> /* Define some debugging macros */
> #if (defined(WIN32) && !defined(_WIN32_WCE)) /**[10]**/
> #include <crtdbg.h>
> #else
> #define _CRT_WARN 1
> #define _CRT_ASSERT 2
> #define _CRTDBG_MODE_DEBUG 3
> #define _CRTDBG_MODE_WNDW 4
> #define _CRTDBG_MODE_FILE 5
> #if !defined(_DEBUG) && !defined(DEBUG)
> #ifndef _ASSERT
> #define _ASSERT(a)
> #endif
> #define _RPT0(a, b)
> #define _RPT1(a, b, a1)
> #define _RPT2(a, b, a1, a2)
> #define _RPT3(a, b, a1, a2, a3)
> #define _RPT4(a, b, a1, a2, a3, a4)
> #else /* _DEBUG */
> #ifndef _ASSERT
> #define _ASSERT(a)
> #endif
> #define _RPT0(a, b) fprintf(stderr, b)
> #define _RPT1(a, b, a1) fprintf(stderr, b, a1)
> #define _RPT2(a, b, a1, a2) fprintf(stderr, b, a1, a2)
> #define _RPT3(a, b, a1, a2, a3) fprintf(stderr, b, a1, a2, a3)
> #define _RPT4(a, b, a1, a2, a3, a4) fprintf(stderr, b, a1, a2, a3, a4)
> #endif /* _DEBUG */
> #endif /* WIN32 */
>
>
>
>
>
>
>
>
>
> "Marc" <info@mawnet.com> schrieb im Newsbeitrag
> news:474564ea$1@newsgroups.borland.com...
>> Gambit
>>
>> First of all thank you for your time and effort trying to sort this thing
>> out.
>> I used your sample (The complete code is attached here) but still no joy
>> (Same error E_INVALIDARG).
>> I needed to modify the voice creation from CLSCTX_LOCAL_SERVER to
>> CLSCTX_ALL as otherwise it would not work. Now it plays though the
>> speaker but then fails with E_INVALIDARG in the SPBindToFile.
>>
>>
>> As for the compile errors:
>> As you can see I already had to define the two GUID SPDFID_Text and
>> SPDFID_WaveFormatEx with some bogus values. Those GUID are declared as
>> EXTERN_C in sapi.h and I have no idea where (and with what) they should
>> be declared.
>>
>>> You'll just have to define it manually in your code before including
>>> SPDebug.h
>>
>> Sure I could go now through all *.h files and complete the missing
>> declarations, some of them are variables, some of them are functions (IE
>> _RPT1).
>>
>> But to do so I would need to understand the whole code and to be quite
>> honest this is beyond my competence. All I wanted is to use (not
>> redevelop) SAPI im my application.
>> If I have to modify half of the provided Borland *.h files then this is
>> not worth it and I go back to the OCX. This is rather disappointing.
>> OK I am exagerating a little here, but this is why I asked the question
>> if someone has successfully implemented SAPI (all functions, not only
>> Speak("Hello world")) and BCB.
>> I can not imagine that everybody had to rewrite half of the provided *.h
>> files (again exagerating).
>>
>> Rds
>> Marc
>>
>>
>>
>>
>> //---------------------------------------------------------------------------
>> //Unit1.cpp
>> //---------------------------------------------------------------------------
>> #include <vcl.h>
>> #include <sapi.h> //For ISp definitions - part of SDK
>> #include <sphelper.h> //For SPBindToFile
>> #pragma hdrstop
>>
>> #include "Unit1.h"
>>
>> //I needed to define those GUID as they are declared as EXTERN_C in
>> sapi.h
>> //No idea what GUID to use here
>> const GUID SPDFID_Text =
>> StringToGUID("{CFDF4A60-6FFC-11D1-BE46-00A0C95A6A5C}");
>> const GUID SPDFID_WaveFormatEx =
>> StringToGUID("{CFDF4A60-6FFC-11D1-BE46-00A0C95A6A5C}");
>>
>> //---------------------------------------------------------------------------
>> #pragma package(smart_init)
>> #pragma resource "*.dfm"
>> TForm1 *Form1;
>> //---------------------------------------------------------------------------
>> __fastcall TForm1::TForm1(TComponent* Owner)
>> : TForm(Owner)
>> {
>> }
>> //---------------------------------------------------------------------------
>> void TForm1::Test()
>> {
>> HRESULT hr = S_OK;
>> CComPtr<ISpStream> cpStream;
>> CComPtr<ISpVoice> cpVoice;
>> CSpStreamFormat cAudioFmt;
>>
>> cpVoice = NULL;
>> ::CoInitialize(NULL);
>>
>> //Create a SAPI voice:
>> //Using CLSCTX_LOCAL_SERVER fails here...
>>
>> hr = CoCreateInstance( CLSID_SpVoice,NULL,CLSCTX_ALL,IID_ISpVoice,
>> (void**)&cpVoice);
>> if( hr != S_OK )
>> MessageBox(NULL, "CAN NOT CREATE VOICE", "ERROR", MB_OK);
>>
>> if(SUCCEEDED(hr))
>> cpVoice->Speak(L"Hello world",SPF_DEFAULT,NULL);
>> if( hr != S_OK )
>> MessageBox(NULL, "CAN NOT SPEAK", "Error", MB_OK);
>>
>> //Set the audio format
>> if( SUCCEEDED(hr) )
>> hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono);
>> if( hr != S_OK )
>> MessageBox(NULL, "CAN NOT SET FORMAT", "Error", MB_OK);
>>
>> //Call SPBindToFile, a SAPI helper method, to bind the audio stream
>> to the file
>> if( SUCCEEDED(hr) )
>> hr = SPBindToFile(L"c:\\test.wav", SPFM_CREATE_ALWAYS,
>> &cpStream, &cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr());
>> if( hr == E_INVALIDARG )
>> MessageBox(NULL, "E_INVALIDARG", "Error", MB_OK);
>>
>> //set the output to cpStream so that the output audio data will be
>> stored in cpStream
>> if( SUCCEEDED(hr) )
>> hr = cpVoice->SetOutput(cpStream, TRUE);
>> if( hr != S_OK )
>> MessageBox(NULL, "CAN NOT SetOutput", "Error", MB_OK);
>>
>> //Speak the text "hello world" synchronously
>> if( SUCCEEDED(hr) )
>> cpVoice->Speak(L"Hello world",SPF_DEFAULT,NULL);
>> if( hr != S_OK )
>> MessageBox(NULL, "CAN NOT SPEAK TO FILE", "Error", MB_OK);
>>
>> //close the stream
>> if( SUCCEEDED(hr) )
>> hr = cpStream->Close();
>>
>> if(SUCCEEDED(hr))
>> cpVoice = NULL;
>>
>> ::CoUninitialize();
>> }
>> //---------------------------------------------------------------------------
>> void __fastcall TForm1::Button1Click(TObject *Sender)
>> {
>> Test();
>> }
>> //---------------------------------------------------------------------------
>>
>>
>>
>>
>> //---------------------------------------------------------------------------
>> //Unit1.h
>> //---------------------------------------------------------------------------
>> #ifndef Unit1H
>> #define Unit1H
>> //---------------------------------------------------------------------------
>> #include <Classes.hpp>
>> #include <Controls.hpp>
>> #include <StdCtrls.hpp>
>> #include <Forms.hpp>
>> //---------------------------------------------------------------------------
>> class TForm1 : public TForm
>> {
>> __published: // Von der IDE verwaltete Komponenten
>> TButton *Button1;
>> void __fastcall Button1Click(TObject *Sender);
>> private: // Anwender-Deklarationen
>> void Test();
>> public: // Anwender-Deklarationen
>> __fastcall TForm1(TComponent* Owner);
>> };
>> //---------------------------------------------------------------------------
>> extern PACKAGE TForm1 *Form1;
>> //---------------------------------------------------------------------------
>> #endif
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> "Remy Lebeau (TeamB)" <no.spam@no.spam.com> schrieb im Newsbeitrag
>> news:4744b412$1@newsgroups.borland.com...
>>>
>>> "Marc" <info@mawnet.com> wrote in message
>>> news:4744a4e3$1@newsgroups.borland.com...
>>>
>>>> You are right, I made a mistake when I pasted my sample as I
>>>> cleaned it for display purposes.
>>>
>>> Always copy/paste your actual code. It reduces confusion and errors.
>>>
>>>> I tried to implement the sample at
>>>> http://msdn2.microsoft.com/en-us/library/ms717065.aspx
>>>
>>> You are not using the example exactly as it is provided. For instance,
>>> you are not making use of the CComPtr class to manage your pointers.
>>> That in itself would not be causing your error, though.
>>>
>>> Try this:
>>>
>>> void TSpeech::SpeakToFile(const WideString &sWords, const WideString
>>> &sFileName)
>>> {
>>> HRESULT hr;
>>> CComPtr<ISpStream> cpStream;
>>> CComPtr<ISpVoice> cpVoice;
>>> CSpStreamFormat cAudioFmt;
>>>
>>>
>>> //Create a SAPI Voice
>>> hr = CoCreateInstance( CLSID_SpVoice, NULL, CLSCTX_LOCAL_SERVER,
>>> IID_ISpVoice, (void**)&cpVoice);
>>>
>>> //Set the audio format
>>> if( SUCCEEDED(hr) )
>>> hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono);
>>>
>>> //Call SPBindToFile, a SAPI helper method, to bind the audio
>>> stream to the file
>>> if( SUCCEEDED(hr) )
>>> {
>>> hr = SPBindToFile(sFileName, SPFM_CREATE_ALWAYS, &cpStream,
>>> &cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr());
>>> }
>>>
>>> if( hr == E_INVALIDARG )
>>> MessageBox(NULL, "E_INVALIDARG", "Error", MB_OK);
>>>
>>> //set the output to cpStream so that the output audio data will
>>> be stored in cpStream
>>> if( SUCCEEDED(hr) )
>>> hr = cpVoice->SetOutput(cpStream, TRUE);
>>>
>>> //Speak the text "hello world" synchronously
>>> if( SUCCEEDED(hr) )
>>> hr = cpVoice->Speak(sWords, SPF_DEFAULT, NULL);
>>>
>>> //close the stream
>>> if( SUCCEEDED(hr) )
>>> hr = cpStream->Close();
>>> }
>>>
>>>> As for the compile errors, here they are (in German sorry):
>>>
>>> There are plenty of online translators available ;-)
>>>
>>>> [C++ Fehler] crtdbg.h(52): E2268 Aufruf der undefinierten Funktion '_T'
>>>
>>> Call of undefined function '_ T'
>>>
>>> _T is a macro defined in tchar.h. It operates the same as the TEXT()
>>> macro in winnt.h - it takes a character/string literal as input and
>>> compiles it as either char* or wchar_t* depending on whether UNICODE is
>>> defined. Try including tchar.h in your source code before other the
>>> affected header files.
>>>
>>>> [C++ Fehler] crtdbg.h(52): E2034 Konvertierung von 'int' nach 'const
>>>> char *' nicht m�glich
>>>
>>> Cannot convert 'int' to 'const char *'
>>>
>>> That is pretty self-explanatory. That particular line is calling
>>> wsprintf() using the TEXT() macro:
>>>
>>> ::wsprintf(msg, TEXT("%s failed - %s/%d"), expr, file, line);
>>>
>>> That is probably just an issue with TEXT() not being defined before
>>> being used, or it is being re-defined somewhere else.
>>>
>>>> [C++ Fehler] crtdbg.h(52): E2340 Keine �bereinstimmung des Typs beim
>>>> Parameter 2 ('const char *' erwartet, 'int' erhalten)
>>>
>>> Type mismatch in parameter 2 (expected 'const char *', got 'int')
>>>
>>> That is a side-effect of the previous error.
>>>
>>>> [C++ Fehler] SPDebug.h(337): E2303 Typname erwartet
>>>
>>> Typename expected
>>>
>>> That particular line is trying to declare a variable of type _HFILE:
>>>
>>> _HFILE m_hfilePrev;
>>>
>>> I don't see _HFILE begin defined in any header files I have, though. So
>>> it makes sense for that to be reported as an unknown type. You'll just
>>> have to define it manually in your code before including SPDebug.h until
>>> you can figure out where it is supposed to come from:
>>>
>>> #define _HFILE HANDLE
>>>
>>>> [C++ Fehler] SPDebug.h(337): E2139 In Deklaration fehlt ;
>>>
>>> Declaration is missing ;
>>>
>>> That is a side-effect of the previous error.
>>>
>>>> [C++ Fehler] SPDebug.h(47): E2451 Undefiniertes Symbol 'm_hfilePrev'
>>>
>>> Undefined Symbol 'm_hfilePrev'
>>>
>>> Another side-effect. Since __HFILE is not defined anywhere, m_hfilePrev
>>> is not fully declared, either.
>>>
>>>> [C++ Fehler] SPDebug.h(62): E2451 Undefiniertes Symbol '_CRT_WARN'
>>>> [C++ Fehler] SPDebug.h(69): E2451 Undefiniertes Symbol '_CRT_WARN'
>>>> [C++ Fehler] SPDebug.h(76): E2451 Undefiniertes Symbol '_CRT_WARN'
>>>> [C++ Fehler] SPDebug.h(86): E2451 Undefiniertes Symbol '_CRT_ASSERT'
>>>> [C++ Fehler] SPDebug.h(93): E2451 Undefiniertes Symbol '_CRT_WARN'
>>>> [C++ Fehler] SPDebug.h(177): E2451 Undefiniertes Symbol
>>>> '_CRTDBG_MODE_DEBUG'
>>>> [C++ Fehler] SPDebug.h(185): E2451 Undefiniertes Symbol
>>>> '_CRTDBG_MODE_WNDW'
>>>> [C++ Fehler] SPDebug.h(298): E2451 Undefiniertes Symbol
>>>> '_CRTDBG_MODE_FILE'
>>>
>>> Those are also not defined in any header files I have. It looks like
>>> they are supposed to come from CRTDBG.H, but Borland appears to have
>>> edited that file for their own purposes.
>>>
>>>> [C++ Fehler] SPDebug.h(297): E2268 Aufruf der undefinierten Funktion
>>>> '_CrtSetReportMode'
>>>
>>> Call of undefined function '_CrtSetReportMode'
>>>
>>> Self-explanatory. I believe that was also supposed to come from
>>> CRTDBG.H.
>>>
>>>> [C++ Fehler] SPDebug.h(309): E2379 In Anweisung fehlt ;
>>>
>>> Instruction is missing ;
>>>
>>> That is a side-effect of the previous error.
>>>
>>>> [C++ Fehler] SPDebug.h(323): E2121 ) fehlt beim Funktionsaufruf
>>>
>>> ) is missing in function call
>>>
>>> Another side effect.
>>>
>>>> [C++ Fehler] SPDebug.h(371): E2268 Aufruf der undefinierten Funktion
>>>> '_RPT1'
>>>> [C++ Fehler] sphelper.h(446): E2268 Aufruf der undefinierten Funktion
>>>> '_RPT3'
>>>
>>> Call of undefined function '_RPT1'
>>> Call of undefined function '_RPT3'
>>>
>>> More macros missing from CRTDBG.H
>>>
>>>> [C++ Fehler] sphelper.h(446): E2228 Zu viele Fehlermeldungen oder
>>>> Warnungen
>>>
>>> Too many error messages or warnings
>>>
>>> Enough said.
>>>
>>>
>>> Gambit
>>>
>>
>>
>
>
Re: BCB and SAPI v5
Author: Darko Miletic
Date: Thu, 22 Nov 2007 16:22
Date: Thu, 22 Nov 2007 16:22
27 lines
2117 bytes
2117 bytes
Marc wrote:
> In order to reduce compelexity I took the code out of the SPBindToFile
> function and put it directly into my code:
>
> hr = CoCreateInstance( CLSID_SpStream, NULL, CLSCTX_ALL, IID_ISpStream,
> (void **)&cpStream);
> if (SUCCEEDED(hr))
> {
> hr = cpStream->BindToFile(WideString("c:\\test.wav"), SPFM_CREATE_ALWAYS,
> &cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr(), SPFEI_ALL_EVENTS);
> if (FAILED(hr))
> {
> cpStream->Release();
> cpStream = NULL;
> }
> }
>
> Now I am sure that the cpStream is created, but the call to
> cpStream->BindToFile still fails with E_INVALIDARG.
> So the problem must be with the cAudioFmt...
Could you send me your project files using mail address from this
message. I'm interested in checking this out and updating accordingly
bccsdk. We can continue discussion over mail.
Thanks,
Darko
Re: BCB and SAPI v5
Author: Marc
Date: Thu, 22 Nov 2007 18:52
Date: Thu, 22 Nov 2007 18:52
32 lines
2160 bytes
2160 bytes
Done...
"Darko Miletic" <kiklop@fibertel.com.ar> schrieb im Newsbeitrag
news:4745aca9@newsgroups.borland.com...
> Marc wrote:
>> In order to reduce compelexity I took the code out of the SPBindToFile
>> function and put it directly into my code:
>>
>> hr = CoCreateInstance( CLSID_SpStream, NULL, CLSCTX_ALL, IID_ISpStream,
>> (void **)&cpStream);
>> if (SUCCEEDED(hr))
>> {
>> hr = cpStream->BindToFile(WideString("c:\\test.wav"),
>> SPFM_CREATE_ALWAYS, &cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr(),
>> SPFEI_ALL_EVENTS);
>> if (FAILED(hr))
>> {
>> cpStream->Release();
>> cpStream = NULL;
>> }
>> }
>>
>> Now I am sure that the cpStream is created, but the call to
>> cpStream->BindToFile still fails with E_INVALIDARG.
>> So the problem must be with the cAudioFmt...
>
> Could you send me your project files using mail address from this message.
> I'm interested in checking this out and updating accordingly bccsdk. We
> can continue discussion over mail.
>
> Thanks,
> Darko
Re: BCB and SAPI v5
Author: Remy Lebeau (TeamB)
Date: Thu, 22 Nov 2007 20:50
Date: Thu, 22 Nov 2007 20:50
15 lines
1441 bytes
1441 bytes
"Marc" <info@mawnet.com> wrote in message
news:47457331@newsgroups.borland.com...
> I replaced it with
<snip>
That is not the correct replacement. You need to use the IID of the
interface, not its CLSID, ie:
HRESULT hr = ::CoCreateInstance(CLSID_SpStream, NULL, CLSCTX_ALL,
IID_ISpStream, (void **)ppStream);
Gambit
Re: BCB and SAPI v5
Author: Remy Lebeau (TeamB)
Date: Thu, 22 Nov 2007 20:55
Date: Thu, 22 Nov 2007 20:55
13 lines
1455 bytes
1455 bytes
"Marc" <info@mawnet.com> wrote in message news:474586a2@newsgroups.borland.com... > Now I am sure that the cpStream is created, but the call > to cpStream->BindToFile still fails with E_INVALIDARG. > So the problem must be with the cAudioFmt... Did you verify that FormatId() is not returning GUID_NULL and WaveFormatExPtr() is not returning NULL? Gambit
Re: BCB and SAPI v5
Author: Marc
Date: Thu, 22 Nov 2007 22:26
Date: Thu, 22 Nov 2007 22:26
65 lines
2797 bytes
2797 bytes
Hi Remy
>> You need to use the IID of the interface, not its CLSID
I did that (See my post 19:52)
>>
Did you verify that FormatId() is not returning GUID_NULL and
WaveFormatExPtr() is not returning NULL?
<<
cAudioFmt.FormatId() = {3487517280, 28668, 4561, "�F\0 �Zj\\"}
cAudioFmt.WaveFormatExPtr() points to a tWAVEFORMATEX with the values
wFormatTag =1
nChannels=2
nSamplesPerSec=22050
nAvgBytesPerSec=88200
nBlockAlign=4;
wBitsPerSample=16;
cbSize=0;
If I understand the MS description (
http://msdn2.microsoft.com/en-us/library/ms717492.aspx)
correctly then cAudioFmt.FormatId() is actualy the value of
SPDFID_WaveFormatEx and the WaveFormatExPtr is a complete description of the
voice channel.
Therefore I tried to make the call as
hr = SPBindToFile(L"c:\\test.wav", SPFM_CREATE_ALWAYS, &cpStream,
&SPDFID_WaveFormatEx, &MyAudioFmt);
where MyAudioFmt is a tWAVEFORMATEX structure filled with the above values.
Still the same error.
The SPDFID_WaveFormatEx is actually a value I had to define in my code as it
was declared as EXTERN_C in sapi.h.
I just put some bogus values there, may this be the reason ?
What is the right value to initialize SPDFID_WaveFormatEx ?
Rds
Marc
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> schrieb im Newsbeitrag
news:4745eb5c$1@newsgroups.borland.com...
>
> "Marc" <info@mawnet.com> wrote in message
> news:47457331@newsgroups.borland.com...
>
>> I replaced it with
> <snip>
>
> That is not the correct replacement. You need to use the IID of the
> interface, not its CLSID, ie:
>
> HRESULT hr = ::CoCreateInstance(CLSID_SpStream, NULL, CLSCTX_ALL,
> IID_ISpStream, (void **)ppStream);
>
>
> Gambit
>
>
Re: BCB and SAPI v5
Author: Remy Lebeau (TeamB)
Date: Thu, 22 Nov 2007 22:52
Date: Thu, 22 Nov 2007 22:52
17 lines
1694 bytes
1694 bytes
"Marc" <info@mawnet.com> wrote in message news:4746024a@newsgroups.borland.com... > The SPDFID_WaveFormatEx is actually a value I had to define > in my code as it was declared as EXTERN_C in sapi.h. > I just put some bogus values there, may this be the reason ? Of course. You can't make things up as you wish. You have to use the real values as they are defined. > What is the right value to initialize SPDFID_WaveFormatEx ? I do not know right now. I will have to track it down when I have time. Gambit
Re: BCB and SAPI v5
Author: Marc
Date: Thu, 22 Nov 2007 23:16
Date: Thu, 22 Nov 2007 23:16
40 lines
2297 bytes
2297 bytes
Remy > Of course. You can't make things up as you wish. You have to use the > real > values as they are defined. Well if you have it, I would be very interessted. I tried to find it all over. But this is apparently the key to a lot of functions in SAPI. As per http://coding.derkeiler.com/Archive/Delphi/borland.public.delphi.language.objectpascal/2003-10/2158.html the definition should be in sapi.lib, but the MIDL does not return it. Rds Marc "Remy Lebeau (TeamB)" <no.spam@no.spam.com> schrieb im Newsbeitrag news:474607e4$1@newsgroups.borland.com... > > "Marc" <info@mawnet.com> wrote in message > news:4746024a@newsgroups.borland.com... > >> The SPDFID_WaveFormatEx is actually a value I had to define >> in my code as it was declared as EXTERN_C in sapi.h. >> I just put some bogus values there, may this be the reason ? > > Of course. You can't make things up as you wish. You have to use the > real > values as they are defined. > >> What is the right value to initialize SPDFID_WaveFormatEx ? > > I do not know right now. I will have to track it down when I have time. > > > Gambit > >
Re: BCB and SAPI v5 => Success
Author: Marc
Date: Fri, 23 Nov 2007 14:54
Date: Fri, 23 Nov 2007 14:54
57 lines
2875 bytes
2875 bytes
For those who are still interested :-)
const GUID SPDFID_Text =
StringToGUID("{7CEEF9F9-3D13-11D2-9EE7-00C04F797396}");
const GUID SPDFID_WaveFormatEx =
StringToGUID("{C31ADBAE-527F-4FF5-A230-F62BB61FF70C}");
They are defined sapiaut.idl.
Rds
Marc
"Marc" <info@mawnet.com> schrieb im Newsbeitrag
news:47460e0b$1@newsgroups.borland.com...
> Remy
>
>> Of course. You can't make things up as you wish. You have to use the
>> real
>> values as they are defined.
>
> Well if you have it, I would be very interessted. I tried to find it all
> over.
> But this is apparently the key to a lot of functions in SAPI.
> As per
> http://coding.derkeiler.com/Archive/Delphi/borland.public.delphi.language.objectpascal/2003-10/2158.html
>
> the definition should be in sapi.lib, but the MIDL does not return it.
>
> Rds
> Marc
>
>
> "Remy Lebeau (TeamB)" <no.spam@no.spam.com> schrieb im Newsbeitrag
> news:474607e4$1@newsgroups.borland.com...
>>
>> "Marc" <info@mawnet.com> wrote in message
>> news:4746024a@newsgroups.borland.com...
>>
>>> The SPDFID_WaveFormatEx is actually a value I had to define
>>> in my code as it was declared as EXTERN_C in sapi.h.
>>> I just put some bogus values there, may this be the reason ?
>>
>> Of course. You can't make things up as you wish. You have to use the
>> real
>> values as they are defined.
>>
>>> What is the right value to initialize SPDFID_WaveFormatEx ?
>>
>> I do not know right now. I will have to track it down when I have time.
>>
>>
>> Gambit
>>
>>
>
>
Re: BCB and SAPI v5 => Success
Author: Remy Lebeau (TeamB)
Date: Fri, 23 Nov 2007 19:04
Date: Fri, 23 Nov 2007 19:04
16 lines
1773 bytes
1773 bytes
"Marc" <info@mawnet.com> wrote in message
news:4746e9d4@newsgroups.borland.com...
> For those who are still interested :-)
StringToGUID() is a run-time operation. You should define the values
statically at compile-time instead:
const GUID SPDFID_Text = {0x7CEEF9F9, 0x3D13, 0x11D2, {0x9E, 0xE7, 0x00,
0xC0, 0x4F, 0x79, 0x73, 0x96}};
const GUID SPDFID_WaveFormatEx = {0xC31ADBAE, 0x527F, 0x4FF5, {0xA2,
0x30, 0xF6, 0x2B, 0xB6, 0x1F, 0xF7, 0x0C}};
Gambit
Re: BCB and SAPI v5 => Success
Author: Marc
Date: Fri, 23 Nov 2007 22:51
Date: Fri, 23 Nov 2007 22:51
26 lines
2038 bytes
2038 bytes
OK, thanks for the hint!
Rds
Marc
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> schrieb im Newsbeitrag
news:474723f4$1@newsgroups.borland.com...
>
> "Marc" <info@mawnet.com> wrote in message
> news:4746e9d4@newsgroups.borland.com...
>
>> For those who are still interested :-)
>
> StringToGUID() is a run-time operation. You should define the values
> statically at compile-time instead:
>
> const GUID SPDFID_Text = {0x7CEEF9F9, 0x3D13, 0x11D2, {0x9E, 0xE7,
> 0x00,
> 0xC0, 0x4F, 0x79, 0x73, 0x96}};
> const GUID SPDFID_WaveFormatEx = {0xC31ADBAE, 0x527F, 0x4FF5, {0xA2,
> 0x30, 0xF6, 0x2B, 0xB6, 0x1F, 0xF7, 0x0C}};
>
>
> Gambit
>
>
Re: BCB and SAPI v5
Author: Darko Miletic
Date: Sat, 24 Nov 2007 21:31
Date: Sat, 24 Nov 2007 21:31
77 lines
3525 bytes
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;
}
//---------------------------------------------------------------------------
Re: BCB and SAPI v5
Author: Michael Harris
Date: Sun, 25 Nov 2007 17:02
Date: Sun, 25 Nov 2007 17:02
79 lines
3901 bytes
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);
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads