🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: BCB and SAPI v5

#966
From: Marc
Date: Thu, 22 Nov 2007 13:38
465 lines
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
>>>
>>
>>
>
> 
Technical Details
Message-ID: <474586a2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.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>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,67677465280073fd
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII
Reply-To: "Marc" <info@mawnet.com>
From: "Marc" <info@mawnet.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>
Subject: Re: BCB and SAPI v5
Date: Thu, 22 Nov 2007 14:38:35 +0100
Lines: 467
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: 83.76.36.137
Message-ID: <474586a2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1195738786 83.76.36.137 (22 Nov 2007 05:39:46 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail