Board index » cppbuilder » Startup help with SAPI

Startup help with SAPI


2007-11-17 06:10:08 PM
cppbuilder3
Hi all
I try to implement a simple SAPI application that reads back a phone number.
I downloaded the SDK 5.1 from Microsoft and had a look at the samples... and
did not quite got into it. Does someone has a simple sample in BCB that just
shows how to speak a number?
Rds
Marc
 
 

Re:Startup help with SAPI

The following will "speak" anything - numbers as well as words.
John
//---------------------------------------------------------------------------
#ifndef JMCSpeechH
#define JMCSpeechH
#include <sapi.h>//For ISp definitions - part of SDK
//---------------------------------------------------------------------------
//Speech Utilities:
//This object instantiates the COM Object SpVoice and gives us an easy
//function call in order to speak a string.
class TJMCSpeech
{
public:
TJMCSpeech(); //Constructor
~TJMCSpeech(); //Destructor
void Speak(String Words); //Speak the input words in the string.
private:
HRESULT hr;
ISpVoice* pVoice;
};
#endif
-------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "JMCSpeech.h"
//#include "SUTIL.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//Constructor
TJMCSpeech::TJMCSpeech()
{
hr = S_OK;
pVoice = NULL;
::CoInitialize(NULL);
//Create a SAPI voice:
hr = CoCreateInstance( CLSID_SpVoice,NULL,CLSCTX_ALL,IID_ISpVoice,
(void**)&pVoice);
}
//Destructor
TJMCSpeech::~TJMCSpeech()
{
if(SUCCEEDED(hr))
pVoice->Release();
::CoUninitialize();
}
//---------------------------------------------------------------------------
void TJMCSpeech::Speak(String Words)
{
if(SUCCEEDED(hr))
pVoice->Speak(WideString(Words),SPF_DEFAULT,NULL);
}
//Note: I originally had:
// pVoice->Speak(TJMCSUtil::StrToBSTR(Words),SPF_DEFAULT,NULL);
//It was pointed out by Remy Lebeau (TeamB) < XXXX@XXXXX.COM >
//that this was a memory leak and that I should use the following:
// pVoice->Speak(WideString(Words),SPF_DEFAULT,NULL);
//---------------------------------------------------------------------------
"Marc" < XXXX@XXXXX.COM >wrote in message
Quote
Hi all

I try to implement a simple SAPI application that reads back a phone
number. I downloaded the SDK 5.1 from Microsoft and had a look at the
samples... and did not quite got into it. Does someone has a simple sample
in BCB that just shows how to speak a number?

Rds
Marc

 

Re:Startup help with SAPI

Thanks!
"JohnC" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
The following will "speak" anything - numbers as well as words.
John
//---------------------------------------------------------------------------

#ifndef JMCSpeechH
#define JMCSpeechH

#include <sapi.h>//For ISp definitions - part of SDK

//---------------------------------------------------------------------------

//Speech Utilities:
//This object instantiates the COM Object SpVoice and gives us an easy
//function call in order to speak a string.

class TJMCSpeech
{
public:
TJMCSpeech(); //Constructor
~TJMCSpeech(); //Destructor
void Speak(String Words); //Speak the input words in the string.
private:
HRESULT hr;
ISpVoice* pVoice;
};


#endif
-------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "JMCSpeech.h"
//#include "SUTIL.h"
//---------------------------------------------------------------------------

#pragma package(smart_init)

//Constructor
TJMCSpeech::TJMCSpeech()
{
hr = S_OK;
pVoice = NULL;
::CoInitialize(NULL);

//Create a SAPI voice:
hr = CoCreateInstance( CLSID_SpVoice,NULL,CLSCTX_ALL,IID_ISpVoice,
(void**)&pVoice);
}
//Destructor
TJMCSpeech::~TJMCSpeech()
{
if(SUCCEEDED(hr))
pVoice->Release();

::CoUninitialize();
}
//---------------------------------------------------------------------------
void TJMCSpeech::Speak(String Words)
{
if(SUCCEEDED(hr))
pVoice->Speak(WideString(Words),SPF_DEFAULT,NULL);
}
//Note: I originally had:
// pVoice->Speak(TJMCSUtil::StrToBSTR(Words),SPF_DEFAULT,NULL);
//It was pointed out by Remy Lebeau (TeamB) < XXXX@XXXXX.COM >
//that this was a memory leak and that I should use the following:
// pVoice->Speak(WideString(Words),SPF_DEFAULT,NULL);
//---------------------------------------------------------------------------


"Marc" < XXXX@XXXXX.COM >wrote in message
news:473ebe39$ XXXX@XXXXX.COM ...
>Hi all
>
>I try to implement a simple SAPI application that reads back a phone
>number. I downloaded the SDK 5.1 from Microsoft and had a look at the
>samples... and did not quite got into it. Does someone has a simple
>sample in BCB that just shows how to speak a number?
>
>Rds
>Marc
>


 

{smallsort}

Re:Startup help with SAPI

John
I tried this but hit a wall.
I used implib to create a BCB compatible library, but now I get the errors
[Linker Error] Unresolved external '_IID_ISpVoice' referenced from
T:\UNIT2.OBJ
[Linker Error] Unresolved external '_CLSID_SpVoice' referenced from
T:\UNIT2.OBJ
I found some references for this on Google, but no solution :-(
Rds
Marc
"JohnC" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
The following will "speak" anything - numbers as well as words.
John
//---------------------------------------------------------------------------

#ifndef JMCSpeechH
#define JMCSpeechH

#include <sapi.h>//For ISp definitions - part of SDK

//---------------------------------------------------------------------------

//Speech Utilities:
//This object instantiates the COM Object SpVoice and gives us an easy
//function call in order to speak a string.

class TJMCSpeech
{
public:
TJMCSpeech(); //Constructor
~TJMCSpeech(); //Destructor
void Speak(String Words); //Speak the input words in the string.
private:
HRESULT hr;
ISpVoice* pVoice;
};


#endif
-------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "JMCSpeech.h"
//#include "SUTIL.h"
//---------------------------------------------------------------------------

#pragma package(smart_init)

//Constructor
TJMCSpeech::TJMCSpeech()
{
hr = S_OK;
pVoice = NULL;
::CoInitialize(NULL);

//Create a SAPI voice:
hr = CoCreateInstance( CLSID_SpVoice,NULL,CLSCTX_ALL,IID_ISpVoice,
(void**)&pVoice);
}
//Destructor
TJMCSpeech::~TJMCSpeech()
{
if(SUCCEEDED(hr))
pVoice->Release();

::CoUninitialize();
}
//---------------------------------------------------------------------------
void TJMCSpeech::Speak(String Words)
{
if(SUCCEEDED(hr))
pVoice->Speak(WideString(Words),SPF_DEFAULT,NULL);
}
//Note: I originally had:
// pVoice->Speak(TJMCSUtil::StrToBSTR(Words),SPF_DEFAULT,NULL);
//It was pointed out by Remy Lebeau (TeamB) < XXXX@XXXXX.COM >
//that this was a memory leak and that I should use the following:
// pVoice->Speak(WideString(Words),SPF_DEFAULT,NULL);
//---------------------------------------------------------------------------


"Marc" < XXXX@XXXXX.COM >wrote in message
news:473ebe39$ XXXX@XXXXX.COM ...
>Hi all
>
>I try to implement a simple SAPI application that reads back a phone
>number. I downloaded the SDK 5.1 from Microsoft and had a look at the
>samples... and did not quite got into it. Does someone has a simple
>sample in BCB that just shows how to speak a number?
>
>Rds
>Marc
>


 

Re:Startup help with SAPI

I also tried to use coff2omf to convert the sapi.lib library, but the
resulting library is only 1Kb (the original sapi.lib has 39kB) and it gives
me the same error message....
What am I doing wrong here ?
Rds
Marc
"Marc" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
John

I tried this but hit a wall.
I used implib to create a BCB compatible library, but now I get the errors

[Linker Error] Unresolved external '_IID_ISpVoice' referenced from
T:\UNIT2.OBJ
[Linker Error] Unresolved external '_CLSID_SpVoice' referenced from
T:\UNIT2.OBJ

I found some references for this on Google, but no solution :-(

Rds
Marc



"JohnC" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
news:473ee927$ XXXX@XXXXX.COM ...
>The following will "speak" anything - numbers as well as words.
>John
>//---------------------------------------------------------------------------
>
>#ifndef JMCSpeechH
>#define JMCSpeechH
>
>#include <sapi.h>//For ISp definitions - part of SDK
>
>//---------------------------------------------------------------------------
>
>//Speech Utilities:
>//This object instantiates the COM Object SpVoice and gives us an easy
>//function call in order to speak a string.
>
>class TJMCSpeech
>{
>public:
>TJMCSpeech(); //Constructor
>~TJMCSpeech(); //Destructor
>void Speak(String Words); //Speak the input words in the string.
>private:
>HRESULT hr;
>ISpVoice* pVoice;
>};
>
>
>#endif
>-------------------
>//---------------------------------------------------------------------------
>#include <vcl.h>
>#pragma hdrstop
>
>#include "JMCSpeech.h"
>//#include "SUTIL.h"
>//---------------------------------------------------------------------------
>
>#pragma package(smart_init)
>
>//Constructor
>TJMCSpeech::TJMCSpeech()
>{
>hr = S_OK;
>pVoice = NULL;
>::CoInitialize(NULL);
>
>//Create a SAPI voice:
>hr = CoCreateInstance( CLSID_SpVoice,NULL,CLSCTX_ALL,IID_ISpVoice,
>(void**)&pVoice);
>}
>//Destructor
>TJMCSpeech::~TJMCSpeech()
>{
>if(SUCCEEDED(hr))
>pVoice->Release();
>
>::CoUninitialize();
>}
>//---------------------------------------------------------------------------
>void TJMCSpeech::Speak(String Words)
>{
>if(SUCCEEDED(hr))
>pVoice->Speak(WideString(Words),SPF_DEFAULT,NULL);
>}
>//Note: I originally had:
>// pVoice->Speak(TJMCSUtil::StrToBSTR(Words),SPF_DEFAULT,NULL);
>//It was pointed out by Remy Lebeau (TeamB) < XXXX@XXXXX.COM >
>//that this was a memory leak and that I should use the following:
>// pVoice->Speak(WideString(Words),SPF_DEFAULT,NULL);
>//---------------------------------------------------------------------------
>
>
>"Marc" < XXXX@XXXXX.COM >wrote in message
>news:473ebe39$ XXXX@XXXXX.COM ...
>>Hi all
>>
>>I try to implement a simple SAPI application that reads back a phone
>>number. I downloaded the SDK 5.1 from Microsoft and had a look at the
>>samples... and did not quite got into it. Does someone has a simple
>>sample in BCB that just shows how to speak a number?
>>
>>Rds
>>Marc
>>
>
>


 

Re:Startup help with SAPI

Marc wrote:
Quote
Hi all

I try to implement a simple SAPI application that reads back a phone number.
I downloaded the SDK 5.1 from Microsoft and had a look at the samples... and
did not quite got into it. Does someone has a simple sample in BCB that just
shows how to speak a number?

Rds
Marc


bccsdk contains everything you need to develop SAPI 5. 1 app's. There is
even one example supplied there. You can get it from bccsdk.sf.net
 

Re:Startup help with SAPI

"Marc" wrote in message news:473ebe39$ XXXX@XXXXX.COM ...
...
Quote
Does someone has a simple sample in BCB that just shows how to speak a
number?

Rds
Marc
I went about it a little differently.
Import Type Library
// Type Lib: C:\Program Files\Common Files\Microsoft Shared\Speech\sapi.dll
(1)
saved as \..\CBuilder5\Imports\SpeechLib_TLB.cpp
application.cpp
USEUNIT("..\..\CBuilder5\Imports\SpeechLib_TLB.cpp");
unit1.cpp
namespace { // anon
ISpeechVoicePtr VoicePtr;
SpeechVoiceSpeakFlags eSpeechVoiceSpeakFlags = SVSFDefault;
};
void __fastcall TfrmMain::Button1Click(TObject *Sender)
{
if (!VoicePtr)
VoicePtr = CoSpVoice::Create();
VoicePtr->Speak(WideString("Hello world"), eSpeechVoiceSpeakFlags);
// or
VoicePtr->Speak(WideString(Edit1->Text), eSpeechVoiceSpeakFlags);
}
worked fine.
 

Re:Startup help with SAPI

Hi Darko
Thank you for your message.
I downloaded bccsdk but could not find the SAPI sample :-(
Rds
Marc
"Darko Miletic" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
Marc wrote:
>Hi all
>
>I try to implement a simple SAPI application that reads back a phone
>number. I downloaded the SDK 5.1 from Microsoft and had a look at the
>samples... and did not quite got into it. Does someone has a simple
>sample in BCB that just shows how to speak a number?
>
>Rds
>Marc

bccsdk contains everything you need to develop SAPI 5. 1 app's. There is
even one example supplied there. You can get it from bccsdk.sf.net
 

Re:Startup help with SAPI

Hi all
With your help I managed to get my first "Hello World" through the
loud-speaker :-)
So now I try to implement a SpeakToFile call.
But here things get quite out of my hands (and competence).
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 SPDebug.h and many more errors complaining about missing definitions.
I searched my PC for a definition of _CRTDBG_MODE_DEBUG and could not find
it. Does anyone know in which file the definition is supposed to be ?
So I compiled without _DEBUG and now am stuck with an error in the
sphelper.h, on line 1858
HRESULT hr = ::CoCreateInstance(CLSID_SpStream, NULL, CLSCTX_ALL,
__uuidof(*ppStream), (void **)ppStream);
Error: Invalid use of __uuidof
I am using BCB professional, v6 (Build 10.161), OS on XP SP2
Does this version have any problems or missing files ?
I also tried with bccsdk of Darko Miletic, but no success neither.
Thank you for every idea to get me a step further !
Rds
Marc
"Marc" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
Hi all

I try to implement a simple SAPI application that reads back a phone
number. I downloaded the SDK 5.1 from Microsoft and had a look at the
samples... and did not quite got into it. Does someone has a simple sample
in BCB that just shows how to speak a number?

Rds
Marc

 

Re:Startup help with SAPI

I'm still trying to figure out why you are having trouble getting SAPI at
all.
As far as I can see, it comes with the operating system.
Check your Control Panel / Speech and look at the Text To Speech tab.
If you can see at least one voice in the list, you should have SAPI
installed.
Try selecting from the list (even if only one voice) or press the "Preview
Voice" button.
If you can hear a voice, then everything should be there.
Now, if I'm all wet about this, I'd appreciate it if someone would let me
know.
I repeat: I've been using SAPI in both XP Media Center and Vista Home Basic
and did nothing special to install SAPI.
John
"Marc" < XXXX@XXXXX.COM >wrote in message
Quote
Hi Darko

Thank you for your message.
I downloaded bccsdk but could not find the SAPI sample :-(

Rds
Marc



"Darko Miletic" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
news:4741b9b4$ XXXX@XXXXX.COM ...
>Marc wrote:
>>Hi all
>>
>>I try to implement a simple SAPI application that reads back a phone
>>number. I downloaded the SDK 5.1 from Microsoft and had a look at the
>>samples... and did not quite got into it. Does someone has a simple
>>sample in BCB that just shows how to speak a number?
>>
>>Rds
>>Marc
>
>bccsdk contains everything you need to develop SAPI 5. 1 app's. There is
>even one example supplied there. You can get it from bccsdk.sf.net


 

Re:Startup help with SAPI

I couldn't get the sphelper stuff to work at all - gave up and did things
directly.
John
"Marc" < XXXX@XXXXX.COM >wrote in message
Quote
So I compiled without _DEBUG and now am stuck with an error in the
sphelper.h, on line 1858
HRESULT hr = ::CoCreateInstance(CLSID_SpStream, NULL, CLSCTX_ALL,
__uuidof(*ppStream), (void **)ppStream);

Error: Invalid use of __uuidof
 

Re:Startup help with SAPI

John
SAPI works, this was not the problem.
The issue I had was with the sapi.lib that came with the SAPI SDK. It was in
a different format, so I had to recreate it.
This did the trick and now I was able to use its functionality (at least
partly... see below)
Rds
Marc
"JohnC" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
I'm still trying to figure out why you are having trouble getting SAPI at
all.
As far as I can see, it comes with the operating system.
Check your Control Panel / Speech and look at the Text To Speech tab.
If you can see at least one voice in the list, you should have SAPI
installed.
Try selecting from the list (even if only one voice) or press the "Preview
Voice" button.
If you can hear a voice, then everything should be there.

Now, if I'm all wet about this, I'd appreciate it if someone would let me
know.
I repeat: I've been using SAPI in both XP Media Center and Vista Home
Basic
and did nothing special to install SAPI.
John


"Marc" < XXXX@XXXXX.COM >wrote in message
news:47440db0$ XXXX@XXXXX.COM ...
>Hi Darko
>
>Thank you for your message.
>I downloaded bccsdk but could not find the SAPI sample :-(
>
>Rds
>Marc
>
>
>
>"Darko Miletic" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
>news:4741b9b4$ XXXX@XXXXX.COM ...
>>Marc wrote:
>>>Hi all
>>>
>>>I try to implement a simple SAPI application that reads back a phone
>>>number. I downloaded the SDK 5.1 from Microsoft and had a look at the
>>>samples... and did not quite got into it. Does someone has a simple
>>>sample in BCB that just shows how to speak a number?
>>>
>>>Rds
>>>Marc
>>
>>bccsdk contains everything you need to develop SAPI 5. 1 app's. There is
>>even one example supplied there. You can get it from
>>bccsdk.sf.net
>
>


 

Re:Startup help with SAPI

John
This could be an idea...
Did you succeed in implementing a SpeakToFile solution? Where a WAV file is
created rather than the text read through the loud speaker?
Rds
Marc
"JohnC" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
I couldn't get the sphelper stuff to work at all - gave up and did things
directly.
John

"Marc" < XXXX@XXXXX.COM >wrote in message
news:47441606$ XXXX@XXXXX.COM ...
>So I compiled without _DEBUG and now am stuck with an error in the
>sphelper.h, on line 1858
>HRESULT hr = ::CoCreateInstance(CLSID_SpStream, NULL, CLSCTX_ALL,
>__uuidof(*ppStream), (void **)ppStream);
>
>Error: Invalid use of __uuidof


 

Re:Startup help with SAPI

Sorry, no. My application didn't need speech recognition.
Good Luck,
John
"Marc" < XXXX@XXXXX.COM >wrote in message
Quote
John

This could be an idea...
Did you succeed in implementing a SpeakToFile solution? Where a WAV file
is created rather than the text read through the loud speaker?

Rds
Marc
 

Re:Startup help with SAPI

I wonder if anything in this article may help you :-
dn.codegear.com/article/29583
--
Mark Jacobs
DK Computing
www.dkcomputing.co.uk