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