I created a void named "bot" to get text and speak it using a variable named "text". Like this,
void bot(string text).
To use this void bot("Hello") or bot("Hi, my name is blah blah")
but it is not working.
Here is my code,
#include <iostream>
#include <sapi.h>
#include <string>
using namespace std;
void bot(string text)
{
ISpVoice* pVoice = NULL;
if (FAILED(::CoInitialize(NULL)))
{
exit(1);
}
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void**)&pVoice);
if (SUCCEEDED(hr))
{
hr = pVoice->Speak(text, 0, NULL);
pVoice->Release();
pVoice = NULL;
}
::CoUninitialize();
}
int main()
{
bot("Hello");
return 0;
}
Any help please....
I tried like this,
{
hr = pVoice->Speak(L + text, 0, NULL);
pVoice->Release();
pVoice = NULL;
}
And this,
string sentence = text;
{
hr = pVoice->Speak(sentence, 0, NULL);
pVoice->Release();
pVoice = NULL;
}
But it didn't work.
Like this
and this
and this
Speakapparently requires a wide C string.wstringis the type for a wide C++ string.c_str()is the way you 'translate' from C++ strings to C strings.L"hello"is the way you write a wide string literal.