2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 #include <sys/socket.h>
28 static void report_focus_event (void *fp);
29 static void report_button_press (void *fp);
30 static boolean report_key_event (void *fp);
31 static void get_environment_vars (void);
33 static int _festival_init ();
34 static void _festival_say (const char *text, const char *voice, boolean shutup);
35 static void _festival_write (const char *buff, int fd);
37 static boolean use_magnifier = FALSE;
38 static boolean use_festival = FALSE;
39 static boolean festival_chatty = FALSE;
42 main(int argc, char **argv)
48 Accessible *application;
49 AccessibleEventListener *focus_listener;
50 AccessibleEventListener *button_listener;
51 KeystrokeListener *key_listener;
53 if ((argc > 1) && (!strncmp(argv[1],"-h",2)))
55 printf ("Usage: simple-at\n");
56 printf ("\tEnvironment variables used:\n\t\tFESTIVAL\n\t\tMAGNIFIER\n\t\tFESTIVAL_CHATTY\n");
62 focus_listener = createEventListener (report_focus_event);
63 button_listener = createEventListener (report_button_press);
65 registerGlobalEventListener (focus_listener, "focus:");
66 registerGlobalEventListener (button_listener, "Gtk:GtkWidget:button-press-event");
68 n_desktops = getDesktopCount ();
70 for (i=0; i<n_desktops; ++i)
72 desktop = getDesktop (i);
73 fprintf (stderr, "desktop %d name: %s\n", i, Accessible_getName (desktop));
74 n_apps = Accessible_getChildCount (desktop);
75 for (j=0; j<n_apps; ++j)
77 application = Accessible_getChildAtIndex (desktop, j);
78 fprintf (stderr, "app %d name: %s\n", j, Accessible_getName (application));
82 /* prepare the keyboard snoopers */
83 /* key_listener = createKeystrokeListener(report_key_event);
84 registerKeystrokeListener(key_listener, KEYMASK_SHIFT); */
86 get_environment_vars();
88 SPI_event_main(FALSE);
92 get_environment_vars()
94 if (getenv ("FESTIVAL"))
97 if (getenv ("FESTIVAL_CHATTY"))
99 festival_chatty = TRUE;
102 if (getenv("MAGNIFIER"))
104 use_magnifier = TRUE;
109 report_focus_event (void *p)
111 AccessibleEvent *ev = (AccessibleEvent *) p;
112 fprintf (stderr, "%s event from %s\n", ev->type,
113 Accessible_getName (&ev->source));
119 _festival_say (Accessible_getRole (&ev->source), "voice_don_diphone", TRUE);
121 _festival_say (Accessible_getName (&ev->source), "voice_kal_diphone", festival_chatty==FALSE);
124 if (Accessible_isComponent (&ev->source))
126 long x, y, width, height;
127 AccessibleComponent *component = Accessible_getComponent (&ev->source);
128 AccessibleComponent_getExtents (component, &x, &y, &width, &height,
130 fprintf (stderr, "Bounding box: (%ld, %ld) ; (%ld, %ld)\n",
131 x, y, x+width, y+height);
133 magnifier_set_roi (x, y, width, height);
136 if (Accessible_isText(&ev->source))
137 /* if this is a text object, speak the first sentence. */
139 AccessibleText *text_interface = Accessible_getText (&ev->source);
140 long start_offset, end_offset;
141 char *first_sentence = "";
142 first_sentence = AccessibleText_getTextAtOffset (
143 text_interface, (long) 0, TEXT_BOUNDARY_WORD_END,
144 &start_offset, &end_offset);
145 _festival_say(first_sentence, "voice_don_diphone", festival_chatty==FALSE);
150 report_button_press (void *p)
152 AccessibleEvent *ev = (AccessibleEvent *) p;
153 fprintf (stderr, "%s event from %s\n", ev->type,
154 Accessible_getName (&ev->source));
158 report_key_event (void *p)
160 KeyStroke *key = (KeyStroke *) p;
161 fprintf (stderr, ".");
165 static int _festival_init ()
168 struct sockaddr_in name;
171 name.sin_family = AF_INET;
172 name.sin_port = htons (1314);
173 name.sin_addr.s_addr = htonl(INADDR_ANY);
174 fd = socket (PF_INET, SOCK_STREAM, 0);
176 while (connect(fd, (struct sockaddr *) &name, sizeof (name)) < 0) {
183 _festival_write ("(audio_mode'async)\n", fd);
184 _festival_write ("(Parameter.set 'Duration_Model 'Tree_ZScore)\n", fd);
185 _festival_write ("(Parameter.set 'Duration_Stretch 0.75)\n", fd);
189 static void _festival_say (const char *text, const char *voice, boolean shutup)
195 static gchar voice_spec[32];
199 fd = _festival_init ();
202 fprintf (stderr, "saying text: %s\n", text);
204 quoted = g_malloc(64+strlen(text)*2);
206 sprintf (prefix, "(SayText \"");
208 strncpy(quoted, prefix, 10);
209 p = quoted+strlen(prefix);
211 if ( *text == '\\' || *text == '"' )
220 if (shutup) _festival_write ("(audio_mode'shutup)\n", fd);
221 if (voice && (strncmp (voice, (char *) (voice_spec+1), strlen(voice))))
223 snprintf (voice_spec, 32, "(%s)\n", voice);
224 _festival_write (voice_spec, fd);
225 _festival_write ("(Parameter.set 'Duration_Model 'Tree_ZScore)\n", fd);
226 _festival_write ("(Parameter.set 'Duration_Stretch 0.75)\n", fd);
229 _festival_write (quoted, fd);
234 static void _festival_write (const gchar *command_string, int fd)
236 fprintf(stderr, command_string);
241 write(fd, command_string, strlen(command_string));