-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTMspeech.cpp
More file actions
98 lines (78 loc) · 1.37 KB
/
Copy pathTMspeech.cpp
File metadata and controls
98 lines (78 loc) · 1.37 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Tom's E-Mail Client, started on 9/21/98
// By Tom Grandgent (tgrand@canvaslink.com)
// Speech functions
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#define SPEECH
#ifdef SPEECH
#include <initguid.h>
#include <mbctype.h>
#include <spchwrap.h>
PCVoiceText pCVTxt = NULL;
int COMInitialized = 0;
int speechInitialized = 0;
#endif
int init_tts_engine(void)
{
#ifdef SPEECH
if (speechInitialized)
return 1;
if (!COMInitialized)
{
CoInitialize(NULL);
COMInitialized = 1;
}
pCVTxt = new CVoiceText;
if (!pCVTxt)
return 1;
HRESULT hRes;
//hRes = pCVTxt->Init(L"TMIDI");
hRes = pCVTxt->Init();
if (hRes)
return 1;
speechInitialized = 1;
#endif
return 0;
}
void speak(char *text, ...)
{
#ifdef SPEECH
va_list ap;
char s[4096];
static UINT uCodePage = 0;
WCHAR ws[4096];
if (speechInitialized)
{
if (!uCodePage)
uCodePage = _getmbcp();
va_start(ap, text);
vsprintf(s, text, ap);
va_end(ap);
HRESULT hRes;
MultiByteToWideChar(uCodePage, 0, s, -1, ws, 4096);
hRes = pCVTxt->Speak(ws);
}
#endif
}
void stop_speaking(void)
{
#ifdef SPEECH
pCVTxt->StopSpeaking();
#endif
}
int shutdown_tts_engine(void)
{
#ifdef SPEECH
if (pCVTxt)
delete pCVTxt;
if (COMInitialized)
{
CoUninitialize();
COMInitialized = 0;
}
speechInitialized = 0;
#endif
return 0;
}