forked from AppleWin/AppleWin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpeech.cpp
More file actions
59 lines (46 loc) · 1.1 KB
/
Copy pathSpeech.cpp
File metadata and controls
59 lines (46 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "StdAfx.h"
#ifdef USE_SPEECH_API
#include <sapi.h>
#include "Speech.h"
CSpeech::~CSpeech(void)
{
// Don't do this: causes crash on app exit!
//if (m_cpVoice)
// m_cpVoice->Release();
}
bool CSpeech::Init(void)
{
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_INPROC, IID_ISpVoice, (LPVOID*)&m_cpVoice);
return hr == S_OK;
}
void CSpeech::Reset(void)
{
if (!m_cpVoice)
return;
HRESULT hr = m_cpVoice->Speak(NULL, SPF_PURGEBEFORESPEAK, 0);
_ASSERT(hr == S_OK);
}
void CSpeech::Speak(const char* const pBuffer)
{
if (!m_cpVoice)
return;
size_t uSize;
errno_t err = mbstowcs_s(&uSize, NULL, 0, pBuffer, 0);
if (err)
return;
WCHAR* pszWTextString = new WCHAR[uSize];
if (!pszWTextString)
return;
err = mbstowcs_s(&uSize, pszWTextString, uSize, pBuffer, uSize);
if (err)
{
delete [] pszWTextString;
return;
}
HRESULT hr = m_cpVoice->Speak(pszWTextString, SPF_ASYNC | SPF_IS_NOT_XML, 0);
_ASSERT(hr == S_OK);
hr = m_cpVoice->Resume();
_ASSERT(hr == S_OK);
delete [] pszWTextString;
}
#endif // USE_SPEECH_API