Mercurial > cpython-lru_cache-weakref
annotate Mac/Modules/macspeechmodule.c @ 15842:f6cd36498a50 legacy-trunk
Document extensions to .pth files.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Sat, 13 Jan 2001 09:54:41 +0000 |
| parents | db963a615bc9 |
| children | d3268d62e462 |
| rev | line source |
|---|---|
| 1922 | 1 /*********************************************************** |
|
5079
d6b292a33cfe
Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents:
5071
diff
changeset
|
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
| 2091 | 3 The Netherlands. |
| 1922 | 4 |
| 5 All Rights Reserved | |
| 6 | |
| 7 Permission to use, copy, modify, and distribute this software and its | |
| 8 documentation for any purpose and without fee is hereby granted, | |
| 9 provided that the above copyright notice appear in all copies and that | |
| 10 both that copyright notice and this permission notice appear in | |
| 11 supporting documentation, and that the names of Stichting Mathematisch | |
| 12 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 13 distribution of the software without specific, written prior permission. | |
| 14 | |
| 15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 25 | |
| 5071 | 26 #include "Python.h" |
|
13547
db963a615bc9
ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents:
12836
diff
changeset
|
27 #include "macglue.h" |
| 1922 | 28 |
|
5152
bd708fe1934b
- Changed GestaltEqu.h to Gestalt.h
Jack Jansen <jack.jansen@cwi.nl>
parents:
5079
diff
changeset
|
29 #include <Gestalt.h> |
| 2027 | 30 #include "Speech.h" |
| 31 | |
| 32 #ifdef __MWERKS__ | |
|
12836
3fe304050434
Made the core toolbox modules carbon-compatible using the new greylist feature of bgen: non-carbon methods are still included in non-carbon MacPython. The issue of backward compatibility of Python code is still open.
Jack Jansen <jack.jansen@cwi.nl>
parents:
6442
diff
changeset
|
33 #define OLDP2C 1 |
|
5429
ac235c9e6881
- Changed the m# format for PyArg_ParseTuple back to s#
Jack Jansen <jack.jansen@cwi.nl>
parents:
5152
diff
changeset
|
34 #include <TextUtils.h> |
|
12836
3fe304050434
Made the core toolbox modules carbon-compatible using the new greylist feature of bgen: non-carbon methods are still included in non-carbon MacPython. The issue of backward compatibility of Python code is still open.
Jack Jansen <jack.jansen@cwi.nl>
parents:
6442
diff
changeset
|
35 #ifndef c2pstr |
| 2027 | 36 #define c2pstr C2PStr |
|
12836
3fe304050434
Made the core toolbox modules carbon-compatible using the new greylist feature of bgen: non-carbon methods are still included in non-carbon MacPython. The issue of backward compatibility of Python code is still open.
Jack Jansen <jack.jansen@cwi.nl>
parents:
6442
diff
changeset
|
37 #endif |
|
3fe304050434
Made the core toolbox modules carbon-compatible using the new greylist feature of bgen: non-carbon methods are still included in non-carbon MacPython. The issue of backward compatibility of Python code is still open.
Jack Jansen <jack.jansen@cwi.nl>
parents:
6442
diff
changeset
|
38 #ifndef p2cstr |
| 2027 | 39 #define p2cstr P2CStr |
|
12836
3fe304050434
Made the core toolbox modules carbon-compatible using the new greylist feature of bgen: non-carbon methods are still included in non-carbon MacPython. The issue of backward compatibility of Python code is still open.
Jack Jansen <jack.jansen@cwi.nl>
parents:
6442
diff
changeset
|
40 #endif |
| 2027 | 41 #else |
| 1922 | 42 #include "pascal.h" |
| 2027 | 43 #endif /* __MWERKS__ */ |
| 44 | |
| 45 #ifdef __powerc | |
|
5152
bd708fe1934b
- Changed GestaltEqu.h to Gestalt.h
Jack Jansen <jack.jansen@cwi.nl>
parents:
5079
diff
changeset
|
46 #include <CodeFragments.h> |
| 2027 | 47 int lib_available; |
| 48 #endif /* __powerc */ | |
| 1922 | 49 |
| 50 /* Somehow the Apple Fix2X and X2Fix don't do what I expect */ | |
| 51 #define fixed2double(x) (((double)(x))/32768.0) | |
| 52 #define double2fixed(x) ((Fixed)((x)*32768.0)) | |
| 53 | |
| 54 char *CurrentSpeech; | |
| 5071 | 55 PyObject *ms_error_object; |
| 2027 | 56 int speech_available; |
| 1922 | 57 |
| 2027 | 58 static |
| 59 init_available() { | |
| 60 OSErr err; | |
| 61 long result; | |
| 62 | |
| 63 #ifdef __powerc | |
| 64 lib_available = ((ProcPtr)SpeakString != (ProcPtr)0); | |
| 65 #endif | |
| 66 err = Gestalt(gestaltSpeechAttr, &result); | |
| 67 if ( err == noErr && (result & (1<<gestaltSpeechMgrPresent))) | |
| 68 return 1; | |
| 69 return 0; | |
| 70 } | |
| 71 | |
| 72 static | |
| 73 check_available() { | |
| 74 if ( !speech_available ) { | |
| 5071 | 75 PyErr_SetString(ms_error_object, "Speech Mgr not available"); |
| 2027 | 76 return 0; |
| 77 } | |
| 78 #ifdef __powerc | |
| 79 if ( !lib_available ) { | |
| 5071 | 80 PyErr_SetString(ms_error_object, "Speech Mgr available, but shared lib missing"); |
| 2027 | 81 return 0; |
| 82 } | |
| 83 #endif | |
| 84 return 1; | |
| 1922 | 85 } |
| 86 | |
| 87 /* ------------- | |
| 88 ** | |
| 89 ** Part one - the speech channel object | |
| 90 */ | |
| 91 typedef struct { | |
| 5071 | 92 PyObject_HEAD |
| 1922 | 93 SpeechChannel chan; |
| 5071 | 94 PyObject *curtext; /* If non-NULL current text being spoken */ |
| 1922 | 95 } scobject; |
| 96 | |
| 5071 | 97 staticforward PyTypeObject sctype; |
| 1922 | 98 |
| 99 #define is_scobject(v) ((v)->ob_type == &sctype) | |
| 100 | |
| 101 static scobject * | |
| 102 newscobject(arg) | |
| 103 VoiceSpec *arg; | |
| 104 { | |
| 2027 | 105 scobject *self; |
| 1922 | 106 OSErr err; |
| 107 | |
| 5071 | 108 self = PyObject_NEW(scobject, &sctype); |
| 2027 | 109 if (self == NULL) |
| 1922 | 110 return NULL; |
| 2027 | 111 if ( (err=NewSpeechChannel(arg, &self->chan)) != 0) { |
| 5071 | 112 Py_DECREF(self); |
| 2027 | 113 return (scobject *)PyErr_Mac(ms_error_object, err); |
| 1922 | 114 } |
| 2027 | 115 self->curtext = NULL; |
| 116 return self; | |
| 1922 | 117 } |
| 118 | |
| 119 /* sc methods */ | |
| 120 | |
| 121 static void | |
| 2027 | 122 sc_dealloc(self) |
| 123 scobject *self; | |
| 1922 | 124 { |
| 2027 | 125 DisposeSpeechChannel(self->chan); |
| 5071 | 126 PyMem_DEL(self); |
| 1922 | 127 } |
| 128 | |
| 5071 | 129 static PyObject * |
| 1922 | 130 sc_Stop(self, args) |
| 131 scobject *self; | |
| 5071 | 132 PyObject *args; |
| 1922 | 133 { |
| 134 OSErr err; | |
| 135 | |
| 5071 | 136 if (!PyArg_NoArgs(args)) |
| 1922 | 137 return NULL; |
| 2027 | 138 if ((err=StopSpeech(self->chan)) != 0) { |
| 139 PyErr_Mac(ms_error_object, err); | |
| 140 return NULL; | |
| 141 } | |
| 1922 | 142 if ( self->curtext ) { |
| 5071 | 143 Py_DECREF(self->curtext); |
| 1922 | 144 self->curtext = NULL; |
| 145 } | |
| 5071 | 146 Py_INCREF(Py_None); |
| 147 return Py_None; | |
| 1922 | 148 } |
| 149 | |
| 5071 | 150 static PyObject * |
| 1922 | 151 sc_SpeakText(self, args) |
| 152 scobject *self; | |
| 5071 | 153 PyObject *args; |
| 1922 | 154 { |
| 155 OSErr err; | |
| 156 char *str; | |
| 157 int len; | |
| 158 | |
|
5429
ac235c9e6881
- Changed the m# format for PyArg_ParseTuple back to s#
Jack Jansen <jack.jansen@cwi.nl>
parents:
5152
diff
changeset
|
159 if (!PyArg_Parse(args, "s#", &str, &len)) |
| 1922 | 160 return NULL; |
| 161 if ( self->curtext ) { | |
| 162 StopSpeech(self->chan); | |
| 5071 | 163 Py_DECREF(self->curtext); |
| 1922 | 164 self->curtext = NULL; |
| 165 } | |
| 2027 | 166 if ((err=SpeakText(self->chan, (Ptr)str, (long)len)) != 0) { |
| 167 PyErr_Mac(ms_error_object, err); | |
| 168 return 0; | |
| 169 } | |
| 5071 | 170 (void)PyArg_Parse(args, "O", &self->curtext); /* Or should I check this? */ |
| 171 Py_INCREF(self->curtext); | |
| 172 Py_INCREF(Py_None); | |
| 173 return Py_None; | |
| 1922 | 174 } |
| 175 | |
| 5071 | 176 static PyObject * |
| 1922 | 177 sc_GetRate(self, args) |
| 178 scobject *self; | |
| 5071 | 179 PyObject *args; |
| 1922 | 180 { |
| 181 OSErr err; | |
| 182 Fixed farg; | |
| 183 | |
| 5071 | 184 if (!PyArg_NoArgs(args)) |
| 1922 | 185 return NULL; |
| 2027 | 186 if ((err=GetSpeechRate(self->chan, &farg)) != 0) { |
| 187 PyErr_Mac(ms_error_object, err); | |
| 188 return 0; | |
| 189 } | |
| 5071 | 190 return PyFloat_FromDouble(fixed2double(farg)); |
| 1922 | 191 } |
| 192 | |
| 5071 | 193 static PyObject * |
| 1922 | 194 sc_GetPitch(self, args) |
| 195 scobject *self; | |
| 5071 | 196 PyObject *args; |
| 1922 | 197 { |
| 198 OSErr err; | |
| 199 Fixed farg; | |
| 200 | |
| 5071 | 201 if (!PyArg_NoArgs(args)) |
| 1922 | 202 return NULL; |
| 2027 | 203 if ((err=GetSpeechPitch(self->chan, &farg)) != 0) { |
| 204 PyErr_Mac(ms_error_object, err); | |
| 205 return 0; | |
| 206 } | |
| 5071 | 207 return PyFloat_FromDouble(fixed2double(farg)); |
| 1922 | 208 } |
| 209 | |
| 5071 | 210 static PyObject * |
| 1922 | 211 sc_SetRate(self, args) |
| 212 scobject *self; | |
| 5071 | 213 PyObject *args; |
| 1922 | 214 { |
| 215 OSErr err; | |
| 216 double darg; | |
| 217 | |
| 5071 | 218 if (!PyArg_Parse(args, "d", &darg)) |
| 1922 | 219 return NULL; |
| 2027 | 220 if ((err=SetSpeechRate(self->chan, double2fixed(darg))) != 0) { |
| 221 PyErr_Mac(ms_error_object, err); | |
| 222 return 0; | |
| 223 } | |
| 5071 | 224 Py_INCREF(Py_None); |
| 225 return Py_None; | |
| 1922 | 226 } |
| 227 | |
| 5071 | 228 static PyObject * |
| 1922 | 229 sc_SetPitch(self, args) |
| 230 scobject *self; | |
| 5071 | 231 PyObject *args; |
| 1922 | 232 { |
| 233 OSErr err; | |
| 234 double darg; | |
| 235 | |
| 5071 | 236 if (!PyArg_Parse(args, "d", &darg)) |
| 1922 | 237 return NULL; |
| 2027 | 238 if ((err=SetSpeechPitch(self->chan, double2fixed(darg))) != 0) { |
| 239 PyErr_Mac(ms_error_object, err); | |
| 240 return NULL; | |
| 241 } | |
| 5071 | 242 Py_INCREF(Py_None); |
| 243 return Py_None; | |
| 1922 | 244 } |
| 245 | |
| 5071 | 246 static struct PyMethodDef sc_methods[] = { |
| 247 {"Stop", (PyCFunction)sc_Stop}, | |
| 248 {"SetRate", (PyCFunction)sc_SetRate}, | |
| 249 {"GetRate", (PyCFunction)sc_GetRate}, | |
| 250 {"SetPitch", (PyCFunction)sc_SetPitch}, | |
| 251 {"GetPitch", (PyCFunction)sc_GetPitch}, | |
| 252 {"SpeakText", (PyCFunction)sc_SpeakText}, | |
| 1922 | 253 {NULL, NULL} /* sentinel */ |
| 254 }; | |
| 255 | |
| 5071 | 256 static PyObject * |
| 2027 | 257 sc_getattr(self, name) |
| 258 scobject *self; | |
| 1922 | 259 char *name; |
| 260 { | |
| 5071 | 261 return Py_FindMethod(sc_methods, (PyObject *)self, name); |
| 1922 | 262 } |
| 263 | |
| 5071 | 264 static PyTypeObject sctype = { |
| 265 PyObject_HEAD_INIT(&PyType_Type) | |
| 1922 | 266 0, /*ob_size*/ |
| 267 "MacSpeechChannel", /*tp_name*/ | |
| 268 sizeof(scobject), /*tp_basicsize*/ | |
| 269 0, /*tp_itemsize*/ | |
| 270 /* methods */ | |
| 271 (destructor)sc_dealloc, /*tp_dealloc*/ | |
| 272 0, /*tp_print*/ | |
| 273 (getattrfunc)sc_getattr, /*tp_getattr*/ | |
| 2027 | 274 0, /*tp_setattr*/ |
| 1922 | 275 0, /*tp_compare*/ |
| 276 0, /*tp_repr*/ | |
| 277 0, /*tp_as_number*/ | |
| 278 0, /*tp_as_sequence*/ | |
| 279 0, /*tp_as_mapping*/ | |
| 280 0, /*tp_hash*/ | |
| 281 }; | |
| 282 | |
| 283 /* ------------- | |
| 284 ** | |
| 285 ** Part two - the voice object | |
| 286 */ | |
| 287 typedef struct { | |
| 5071 | 288 PyObject_HEAD |
| 1922 | 289 int initialized; |
| 290 VoiceSpec vs; | |
| 291 VoiceDescription vd; | |
| 292 } mvobject; | |
| 293 | |
| 5071 | 294 staticforward PyTypeObject mvtype; |
| 1922 | 295 |
| 296 #define is_mvobject(v) ((v)->ob_type == &mvtype) | |
| 297 | |
| 298 static mvobject * | |
| 299 newmvobject() | |
| 300 { | |
| 2027 | 301 mvobject *self; |
| 5071 | 302 self = PyObject_NEW(mvobject, &mvtype); |
| 2027 | 303 if (self == NULL) |
| 1922 | 304 return NULL; |
| 2027 | 305 self->initialized = 0; |
| 306 return self; | |
| 1922 | 307 } |
| 308 | |
| 309 static int | |
| 310 initmvobject(self, ind) | |
| 311 mvobject *self; | |
| 312 int ind; | |
| 313 { | |
| 314 OSErr err; | |
| 315 | |
| 316 if ( (err=GetIndVoice((short)ind, &self->vs)) != 0 ) { | |
| 2027 | 317 PyErr_Mac(ms_error_object, err); |
| 1922 | 318 return 0; |
| 319 } | |
| 320 if ( (err=GetVoiceDescription(&self->vs, &self->vd, sizeof self->vd)) != 0) { | |
| 2027 | 321 PyErr_Mac(ms_error_object, err); |
| 1922 | 322 return 0; |
| 323 } | |
| 324 self->initialized = 1; | |
| 325 return 1; | |
| 326 } | |
| 327 /* mv methods */ | |
| 328 | |
| 329 static void | |
| 2027 | 330 mv_dealloc(self) |
| 331 mvobject *self; | |
| 1922 | 332 { |
| 5071 | 333 PyMem_DEL(self); |
| 1922 | 334 } |
| 335 | |
| 5071 | 336 static PyObject * |
| 1922 | 337 mv_getgender(self, args) |
| 338 mvobject *self; | |
| 5071 | 339 PyObject *args; |
| 1922 | 340 { |
| 5071 | 341 PyObject *rv; |
| 1922 | 342 |
| 5071 | 343 if (!PyArg_NoArgs(args)) |
| 1922 | 344 return NULL; |
| 345 if (!self->initialized) { | |
| 5071 | 346 PyErr_SetString(ms_error_object, "Uninitialized voice"); |
| 1922 | 347 return NULL; |
| 348 } | |
| 5071 | 349 rv = PyInt_FromLong(self->vd.gender); |
| 1922 | 350 return rv; |
| 351 } | |
| 352 | |
| 5071 | 353 static PyObject * |
| 1922 | 354 mv_newchannel(self, args) |
| 355 mvobject *self; | |
| 5071 | 356 PyObject *args; |
| 1922 | 357 { |
| 5071 | 358 if (!PyArg_NoArgs(args)) |
| 1922 | 359 return NULL; |
| 360 if (!self->initialized) { | |
| 5071 | 361 PyErr_SetString(ms_error_object, "Uninitialized voice"); |
| 1922 | 362 return NULL; |
| 363 } | |
| 5071 | 364 return (PyObject *)newscobject(&self->vs); |
| 1922 | 365 } |
| 366 | |
| 5071 | 367 static struct PyMethodDef mv_methods[] = { |
| 368 {"GetGender", (PyCFunction)mv_getgender}, | |
| 369 {"NewChannel", (PyCFunction)mv_newchannel}, | |
| 1922 | 370 {NULL, NULL} /* sentinel */ |
| 371 }; | |
| 372 | |
| 5071 | 373 static PyObject * |
| 2027 | 374 mv_getattr(self, name) |
| 375 mvobject *self; | |
| 1922 | 376 char *name; |
| 377 { | |
| 5071 | 378 return Py_FindMethod(mv_methods, (PyObject *)self, name); |
| 1922 | 379 } |
| 380 | |
| 5071 | 381 static PyTypeObject mvtype = { |
| 382 PyObject_HEAD_INIT(&PyType_Type) | |
| 1922 | 383 0, /*ob_size*/ |
| 384 "MacVoice", /*tp_name*/ | |
| 385 sizeof(mvobject), /*tp_basicsize*/ | |
| 386 0, /*tp_itemsize*/ | |
| 387 /* methods */ | |
| 388 (destructor)mv_dealloc, /*tp_dealloc*/ | |
| 389 0, /*tp_print*/ | |
| 390 (getattrfunc)mv_getattr, /*tp_getattr*/ | |
| 2027 | 391 0, /*tp_setattr*/ |
| 1922 | 392 0, /*tp_compare*/ |
| 393 0, /*tp_repr*/ | |
| 394 0, /*tp_as_number*/ | |
| 395 0, /*tp_as_sequence*/ | |
| 396 0, /*tp_as_mapping*/ | |
| 397 0, /*tp_hash*/ | |
| 398 }; | |
| 399 | |
| 400 | |
| 401 /* ------------- | |
| 402 ** | |
| 403 ** Part three - The module interface | |
| 404 */ | |
| 405 | |
| 406 /* See if Speech manager available */ | |
| 407 | |
| 5071 | 408 static PyObject * |
| 1922 | 409 ms_Available(self, args) |
| 5071 | 410 PyObject *self; /* Not used */ |
| 411 PyObject *args; | |
| 1922 | 412 { |
| 413 | |
| 5071 | 414 if (!PyArg_NoArgs(args)) |
| 1922 | 415 return NULL; |
| 5071 | 416 return PyInt_FromLong(speech_available); |
| 1922 | 417 } |
| 418 | |
| 419 /* Count number of busy speeches */ | |
| 420 | |
| 5071 | 421 static PyObject * |
| 1922 | 422 ms_Busy(self, args) |
| 5071 | 423 PyObject *self; /* Not used */ |
| 424 PyObject *args; | |
| 1922 | 425 { |
| 426 short result; | |
| 427 | |
| 5071 | 428 if (!PyArg_NoArgs(args)) |
| 1922 | 429 return NULL; |
| 2027 | 430 if ( !check_available() ) |
| 431 return NULL; | |
| 1922 | 432 result = SpeechBusy(); |
| 5071 | 433 return PyInt_FromLong(result); |
| 1922 | 434 } |
| 435 | |
| 436 /* Say something */ | |
| 437 | |
| 5071 | 438 static PyObject * |
| 1922 | 439 ms_SpeakString(self, args) |
| 5071 | 440 PyObject *self; /* Not used */ |
| 441 PyObject *args; | |
| 1922 | 442 { |
| 443 OSErr err; | |
| 444 char *str; | |
| 445 int len; | |
| 446 | |
| 5071 | 447 if (!PyArg_Parse(args, "s", &str)) |
| 1922 | 448 return NULL; |
| 2027 | 449 if ( !check_available()) |
| 450 return NULL; | |
| 1922 | 451 if (CurrentSpeech) { |
| 452 /* Free the old speech, after killing it off | |
| 453 ** (note that speach is async and c2pstr works inplace) | |
| 454 */ | |
| 455 SpeakString("\p"); | |
| 456 free(CurrentSpeech); | |
| 457 } | |
| 458 len = strlen(str); | |
| 459 CurrentSpeech = malloc(len+1); | |
| 460 strcpy(CurrentSpeech, str); | |
| 461 err = SpeakString(c2pstr(CurrentSpeech)); | |
| 2027 | 462 if ( err ) { |
| 463 PyErr_Mac(ms_error_object, err); | |
| 464 return NULL; | |
| 465 } | |
| 5071 | 466 Py_INCREF(Py_None); |
| 467 return Py_None; | |
| 1922 | 468 } |
| 469 | |
| 470 | |
| 471 /* Count number of available voices */ | |
| 472 | |
| 5071 | 473 static PyObject * |
| 1922 | 474 ms_CountVoices(self, args) |
| 5071 | 475 PyObject *self; /* Not used */ |
| 476 PyObject *args; | |
| 1922 | 477 { |
| 478 short result; | |
| 479 | |
| 5071 | 480 if (!PyArg_NoArgs(args)) |
| 1922 | 481 return NULL; |
| 2027 | 482 if ( !check_available()) |
| 483 return NULL; | |
| 1922 | 484 CountVoices(&result); |
| 5071 | 485 return PyInt_FromLong(result); |
| 1922 | 486 } |
| 487 | |
| 5071 | 488 static PyObject * |
| 1922 | 489 ms_GetIndVoice(self, args) |
| 5071 | 490 PyObject *self; /* Not used */ |
| 491 PyObject *args; | |
| 1922 | 492 { |
| 493 mvobject *rv; | |
| 494 long ind; | |
| 495 | |
| 5071 | 496 if( !PyArg_Parse(args, "i", &ind)) |
| 2027 | 497 return NULL; |
| 498 if ( !check_available() ) | |
| 499 return NULL; | |
| 1922 | 500 rv = newmvobject(); |
| 501 if ( !initmvobject(rv, ind) ) { | |
| 5071 | 502 Py_DECREF(rv); |
| 1922 | 503 return NULL; |
| 504 } | |
| 5071 | 505 return (PyObject *)rv; |
| 1922 | 506 } |
| 507 | |
| 508 | |
| 5071 | 509 static PyObject * |
| 2027 | 510 ms_Version(self, args) |
| 5071 | 511 PyObject *self; /* Not used */ |
| 512 PyObject *args; | |
| 2027 | 513 { |
| 514 NumVersion v; | |
| 515 | |
| 5071 | 516 if (!PyArg_NoArgs(args)) |
| 2027 | 517 return NULL; |
| 518 if ( !check_available()) | |
| 519 return NULL; | |
| 520 v = SpeechManagerVersion(); | |
| 5071 | 521 return PyInt_FromLong(*(int *)&v); |
| 2027 | 522 } |
| 523 | |
| 1922 | 524 |
| 525 /* List of functions defined in the module */ | |
| 526 | |
| 5071 | 527 static struct PyMethodDef ms_methods[] = { |
| 1922 | 528 {"Available", ms_Available}, |
| 529 {"CountVoices", ms_CountVoices}, | |
| 530 {"Busy", ms_Busy}, | |
| 531 {"SpeakString", ms_SpeakString}, | |
| 532 {"GetIndVoice", ms_GetIndVoice}, | |
| 2027 | 533 {"Version", ms_Version}, |
| 1922 | 534 {NULL, NULL} /* sentinel */ |
| 535 }; | |
| 536 | |
| 537 /* Initialization function for the module (*must* be called initmacspeech) */ | |
| 538 | |
| 539 void | |
| 540 initmacspeech() | |
| 541 { | |
| 5071 | 542 PyObject *m, *d; |
| 1922 | 543 |
| 2027 | 544 speech_available = init_available(); |
| 1922 | 545 /* Create the module and add the functions */ |
| 5071 | 546 m = Py_InitModule("macspeech", ms_methods); |
| 1922 | 547 |
| 548 /* Add some symbolic constants to the module */ | |
| 5071 | 549 d = PyModule_GetDict(m); |
| 6442 | 550 ms_error_object = PyErr_NewException("macspeech.error", NULL, NULL); |
| 5071 | 551 PyDict_SetItemString(d, "error", ms_error_object); |
| 1922 | 552 } |
