Debian Codegraph @

sapi/README

raw
1 Microsoft Speech API 5.1 support for CMU Flite
2 ----------------------------------------------
3
4 Copyright Cepstral, LLC, 2001 all rights reserved
5
6 David Huggins-Daines <[email protected]>
7 December 6th, 2001
8
9 About the Flite SAPI port
10 -------------------------
11
12 Funding for this work was provided by the Instituto de Engenharia de
13 Sistemas e Computadores (Lisbon, Portugal). The port itself was done
14 by David Huggins-Daines at Cepstral, LLC (Pittsburgh, USA).
15
16 This work remains Copyright Cepstral, LLC but is distributed under
17 the same free software licence as CMU Flite.
18
19 What's here
20 -----------
21
22 This directory contains a port of CMU Flite 1.1 and the included 8kHz
23 diphone voice to the Win32 platform under Visual C++, as well as an
24 interface library that allows Flite voices to be compiled into COM
25 objects which implement the TTS engine interfaces for Microsoft's
26 Speech API 5.1 (SAPI).
27
28 What isn't here
29 ---------------
30
31 There isn't a pointy-clicky tool for automatically converting voices
32 to SAPI objects. You are more than welcome to write one; it should be
33 fairly straightforward to do as a Visual Studio wizard or add-in or
34 whatever they call those things.
35
36 Instead, the procedure for making SAPI objects is documented below.
37 Feel free to ask me questions at the address above if you don't
38 understand some parts of it.
39
40 Some parts of the SAPI interface code are language specific, namely
41 the viseme and phoneme translation code, and to some extent the text
42 processing code. These have been implemented for US English only,
43 although the relevant functions are abstracted with function pointers
44 so each voice is free to choose its own. See "Language-Specific
45 Functions" below for more information.
46
47 Building and testing the example voice
48 --------------------------------------
49
50 In order to build the Flite SAPI code and example diphone voice, you
51 will need a copy of Visual C++ 6.0 or later, as well as the full SDK
52 for SAPI 5.1. If you have the Microsoft Platform SDK, you will need
53 to make sure to install the Internet Explorer SDK as well, as it
54 contains some IDL files that are required in order to build COM
55 objects with the Platform SDK.
56
57 Before you build anything, you will need to set up Visual C++ to find
58 the SAPI header and IDL files. To do this, select "Options" from the
59 "Tools" menu. In the resulting dialog box, switch to the
60 "Directories" tab. Now, add the "include" and "IDL" directories from
61 your SAPI SDK installation to the list. If you performed a default
62 installation of the SAPI SDK on the C: drive, they will be:
63
64 C:\Program Files\Microsoft Speech SDK 5.1\Include
65 C:\Program Files\Microsoft Speech SDK 5.1\IDL
66
67 Make sure the build type is set to "Win32 - Debug" in Visual C++. Set
68 the active project to "FliteCMUKalDiphone". Select "Build
69 FliteCMUKalDiphone.dll" from the "Build" menu. This will build all of
70 the other libraries before building the SAPI object.
71
72 The first time you use the voice, you will need to register it with
73 Windows. To do this, build the "register_vox" project and execute
74 register_vox.exe (you can find it in the
75 FliteCMUKalDiphone\register_vox\Debug subdirectory, or you can simply
76 run it from within Visual C++).
77
78 Although, normally, Visual C++ should automatically register the
79 FliteCMUKalDiphone object as a COM server, in some cases you may have
80 to do it manually. This can be done by running 'regsvr32
81 FliteCMUKalDiphone.dll' on the command-line from the build directory
82 (sapi\FliteCMUKalDiphone\Debug).
83
84 Now you can test the voice by running the SAPI "TTSApp" example
85 program, or any of the other examples included with the SAPI SDK.
86
87 How to SAPI-enable your own Flite voices
88 ----------------------------------------
89
90 First, you'll obviously need to build your voice under Visual C++.
91 This is relatively straightforward. It's probably best to build it as
92 a static library. You'll need to make sure that it can find the Flite
93 header files as well as the ones for your language and lexicon, which
94 probably means adding their paths in the "Preprocessor" category of
95 the "C/C++" tab of the Project Settings dialog box.
96
97 One thing to be aware of is that the Microsoft linker will probably
98 break if you have very large voice data files as C code. To work
99 around this problem, you can change "Debug Info" from "Program
100 Database for Edit and Continue" to "Program Database" in the "General"
101 category of the "C/C++" tab in the Project Settings dialog box.
102
103 Since there is no support for dynamically discovering and loading
104 voices in Flite, each SAPI voice links to its own instance of the
105 engine. This also simplifies the distribution and installation of
106 voices considerably.
107
108 The common code used to implement the SAPI interface is in the
109 FliteTTSEngineObj library. Your voice should create a subclass of
110 CFliteTTSEngineObj. In the minimal case, you only need to provide a
111 constructor that sets the 'regfunc' and 'unregfunc' members of the
112 base class to the registration and unregistration functions defined in
113 your Flite voice.
114
115 To set up the voice object, create a new Visual C++ project, using the
116 project type "ATL COM AppWizard". For "Server Type", choose "Dynamic
117 Link Library (DLL)".
118
119 Now you must create a definition for the voice object. To do this,
120 switch to "ClassView" in the sidebar, right-click on the project name,
121 and choose "New ATL Object...". Then, from the selection box, choose
122 "Simple Object".
123
124 In the "Names" tab of the next dialog box ("ATL Object Wizard
125 Properties"), choose whatever names you like for your class. In the
126 "Attributes" tab, select "Both" in the "Threading Model" section, and
127 "Custom" in the "Interface" section.
128
129 Next, you need to edit the IDL file to import and use the relevant
130 SAPI interfaces. You should be able to find this file in the "Source
131 Files" section of your new project in the "FileView" tab in the
132 sidebar. If your project name was "FooVoice", the IDL file will be
133 called "FooVoice.idl". In order to import the SAPI interfaces, you
134 should add the following line to the list of 'import' statements at
135 the top of the file:
136
137 import "sapiddk.idl";
138
139 In order for Visual C++ to find this import, you will have to add the
140 SAPI IDL directory it to the Tools->Options dialog box as detailed
141 above (do not add it to the Project Settings, because MIDL.EXE is
142 broken and will not accept it.)
143
144 Just underneath the list of import statements, Visual C++ will have
145 created a bogus interface definition for your object, which will look
146 like this (the UUID and interface name will be different, of course):
147
148 [
149 object,
150 uuid(51284204-38B4-48C4-B65E-4FDAF6476D13),
151
152 helpstring("IFooVoiceObj Interface"),
153 pointer_default(unique)
154 ]
155 interface IFooVoiceObj : IUnknown
156 {
157 };
158
159 You should delete this section. Then, you should change the list of
160 interfaces in the 'coclass' section to use the SAPI TTS Engine
161 interfaces. It should look like this (replace "FooVoiceObj" with the
162 name of your voice object):
163
164 coclass FooVoiceObj
165 {
166 [default] interface ISpTTSEngine;
167 interface ISpObjectWithToken;
168 };
169
170 Now you will need to edit the source code for your voice object. As
171 noted above, in the minimal case, you will simply need to include
172 "voxdefs.h" from your voice library, inherit from CFliteTTSEngineObj,
173 provide declarations for REGISTER_VOX and UNREGISTER_VOX, and
174 initialize the pointers to them in a constructor.
175
176 To do this, open the header file for your voice object. It can be
177 found in the "Header Files" section for your project in the "FileView"
178 tab in the sidebar. If your voice object name (as entered in the
179 "Names" tab in the "ATL Object Wizard Properties" dialog box above)
180 was "FooVoiceObj", then this file will be called
181 "FooVoiceObj.h".
182
183 First, add these declarations underneath the #include statements at
184 the top of the file:
185
186 #include "FliteTTSEngineObj.h"
187 #include "flite_sapi_usenglish.h"
188 extern "C" {
189 #include "voxdefs.h"
190 cst_voice *REGISTER_VOX(const char *voxdir);
191 void UNREGISTER_VOX(cst_voice *vox);
192 };
193
194 You will need to either put the full path to voxdefs.h in the #include
195 statement, or add the directory containing your voice's source code to
196 the list of extra include directories in the "Preprocessor" category
197 of the "C/C++" tab of the Project Settings dialog box. You may also
198 need to do the same for "FliteTTSEngineObj.h" (if you create your
199 voice within the "flite_sapi" workspace included here, you can enter
200 "..\FliteTTSEngineObj" here).
201
202 Next, you must adjust the inheritance list for your voice's class.
203 Remove the following lines marked with '-' and add the line marked
204 with '+':
205
206 - public CComObjectRootEx<CComMultiThreadModel>,
207 public CComCoClass<CFooVoiceObj, &CLSID_FooVoiceObj>,
208 - public IFooVoiceObj
209 + public CFliteTTSEngineObj
210
211 You must also change the COM interface map to contain the SAPI
212 interfaces, by making the following changes (as above, remove the
213 lines marked with '-' and add those marked with '+'):
214
215 BEGIN_COM_MAP(CFooVoiceObj)
216 - COM_INTERFACE_ENTRY(IFooVoiceObj)
217 + COM_INTERFACE_ENTRY(ISpTTSEngine)
218 + COM_INTERFACE_ENTRY(ISpObjectWithToken)
219 END_COM_MAP()
220
221 Finally, add code to the constructor to set the 'regfunc' and
222 'unregfunc' members, and the language-specific functions, if you have
223 them, by adding the lines marked with '+':
224
225 public:
226 CFooVoiceObject() {
227 + regfunc = REGISTER_VOX;
228 + unregfunc = UNREGISTER_VOX;
229 + phonemefunc = flite_sapi_usenglish_phoneme;
230 + visemefunc = flite_sapi_usenglish_viseme;
231 + featurefunc = flite_sapi_usenglish_feature;
232 + pronouncefunc = flite_sapi_usenglish_pronounce;
233 }
234
235 Before you build the SAPI object, you will need to add the voice
236 library and the Flite libraries (flite.lib, plus the libraries for the
237 lexicon and language model, which are cmulex.lib and usenglish.lib for
238 US English) to the list of extra libraries (in the "Input" section of
239 the "Linker" tab of the Project Settings dialog box in Visual C++).
240 You also need to include "winmm.lib" here as it is required by the
241 Flite library. You'll also need to make sure that Visual C++ can find
242 the Flite libraries - you can either set their projects up as
243 dependencies of your SAPI object's project, or you can add a list of
244 relative paths to their build directories in the Project Settings.
245
246 Registering and testing your new SAPI voice object
247 --------------------------------------------------
248
249 Now that you've built your voice as a SAPI component, you must
250 register it with the system so that it can be found and used by
251 programs using the SAPI interface. Predictably, this involves
252 twiddling bits in the Windows Registry.
253
254 Source code and a Visual C++ project is provided (in register-vox.cpp)
255 for a small command-line program which performs the necessary
256 operations for the CMU diphone voice. To use it for another voice,
257 you will need to make the modifications noted by /* CHANGEME */
258 comments in the source code.
259
260 To test your SAPI voice, use the TTSApp program included with the SAPI
261 SDK. You may find it helpful to build the debugging version of TTSApp
262 from source code and specify it as the executable to run when
263 debugging for your SAPI object's project. This will allow you to set
264 breakpoints in your code and get proper backtraces and so forth.
265
266 Language-specific functions
267 ---------------------------
268
269 The language-specific functions for US English are contained in the
270 files flite_sapi_usenglish.c and flite_sapi_usenglish.h. The SAPI
271 object is set up to use them by initializing four function pointers
272 which are members of class CFliteTTSEngineObj:
273
274 int (*phonemefunc)(cst_item *s);
275
276 This function takes a cst_item representing a single phone (usually a
277 member of the "Segment" relation) and returns the appropriate SAPI
278 phone ID for it.
279
280 int (*visemefunc)(cst_item *s);
281
282 This function takes a cst_item representing a single phone and returns
283 the appropriate SAPI viseme ID for it. The SAPI visemes are
284 potentially language independent, though they are expressed in the
285 documentation in terms of US English phonemes. A more general
286 description of them is included below.
287
288 SP_VISEME_0 silence
289 SP_VISEME_1 low mid/front unrounded vowels (ae, ah, ax)
290 SP_VISEME_2 low back unrounded vowels (aa)
291 SP_VISEME_3 low/mid-low back rounded vowels (ao)
292 SP_VISEME_4 mid front unrounded vowels (eh, ey)
293 SP_VISEME_5 English mid rhotic vowel (er)
294 SP_VISEME_6 high front unrounded vowels and glides (ih, iy, y)
295 SP_VISEME_7 high back rounded vowels and glides (uw, w)
296 SP_VISEME_8 rounded-to-rounded rising diphthongs (ow)
297 SP_VISEME_9 unrounded-to-rounded rising diphthongs (aw)
298 SP_VISEME_10 rounded-to-unrounded rising diphthongs (oy)
299 SP_VISEME_11 unrounded-to-unrounded rising diphthongs (ay)
300 SP_VISEME_12 English glottal fricative (hh)
301 SP_VISEME_13 English retroflex approximant (r)
302 SP_VISEME_14 English lateral approximant (l)
303 SP_VISEME_15 grooved alveolar/dental fricatives (s, z)
304 SP_VISEME_16 palatal fricatives and affricates (sh, zh, ch, jh)
305 SP_VISEME_17 interdental fricatives (th, dh)
306 SP_VISEME_18 labiodental fricatives (f, v)
307 SP_VISEME_19 alveolar/dental occlusives (d, t, n)
308 SP_VISEME_20 velar occlusives (k, g, ng)
309 SP_VISEME_21 bilabial occlusives (p, b, m)
310
311 When adapting them to your phoneset, remember that the position of the
312 lips and teeth as viewed from the front is more important than the
313 place or manner of articulation /per se/.
314
315 Also, while the US English code implements this using a table lookup,
316 it may be more appropriate to determine them algorithmically from the
317 feature values used in your phoneset.
318
319 int (*featurefunc)(cst_item *s);
320
321 This function returns a bitmask used by SAPI to indicate placement of
322 stress or emphasis (see the pages on the SPEVENTENUM and SPVFEATURE
323 enumerations in the SAPI documentation for more information on this).
324 If you use "stressed" and "accented" as the feature names for these
325 things in your language code, you can just copy
326 flite_sapi_usenglish_feature().
327
328 cst_val *(*pronounce_func)(SPPHONEID *spids);
329
330 This function takes a zero-terminated array of SAPI phone identifiers
331 and converts it to a list of cst_val containing the phone names as
332 used by Flite as strings. You will probably want to simply copy
333 flite_sapi_usenglish_pronounce(), changing the tables it uses to look
334 up phone names.