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.
26 void report_focus_event (void *fp);
28 void report_button_press (void *fp);
30 static int _festival_init ();
31 static void _festival_say (const char *text, const char *voice, boolean shutup);
32 static void _festival_write (const char *buff, int fd);
34 static boolean use_festival = TRUE;
35 static boolean festival_terse = TRUE;
38 main(int argc, char **argv)
44 Accessible *application;
45 AccessibleEventListener *focus_listener;
46 AccessibleEventListener *button_listener;
50 focus_listener = createEventListener (report_focus_event);
51 button_listener = createEventListener (report_button_press);
53 registerGlobalEventListener (focus_listener, "focus:");
54 registerGlobalEventListener (button_listener, "Gtk:GtkWidget:button-press-event");
56 n_desktops = getDesktopCount ();
58 for (i=0; i<n_desktops; ++i)
60 desktop = getDesktop (i);
61 fprintf (stderr, "desktop %d name: %s\n", i, Accessible_getName (desktop));
62 n_apps = Accessible_getChildCount (desktop);
63 for (j=0; j<n_apps; ++j)
65 application = Accessible_getChildAtIndex (desktop, j);
66 fprintf (stderr, "app %d name: %s\n", j, Accessible_getName (application));
70 if (getenv ("FESTIVAL"))
75 SPI_event_main(FALSE);
79 report_focus_event (void *p)
81 AccessibleEvent *ev = (AccessibleEvent *) p;
82 fprintf (stderr, "%s event from %s\n", ev->type,
83 Accessible_getName (&ev->source));
89 _festival_say (Accessible_getRole (&ev->source), "voice_don_diphone", TRUE);
91 _festival_say (Accessible_getName (&ev->source), "voice_kal_diphone", FALSE);
94 if (Accessible_isComponent (&ev->source))
96 long x, y, width, height;
97 AccessibleComponent *component = Accessible_getComponent (&ev->source);
98 fprintf (stderr, "Source implements IDL:Accessibility/Component:1.0\n");
99 AccessibleComponent_getExtents (component, &x, &y, &width, &height,
101 fprintf (stderr, "Bounding box: (%ld, %ld) ; (%ld, %ld)\n",
102 x, y, x+width, y+height);
107 report_button_press (void *p)
109 AccessibleEvent *ev = (AccessibleEvent *) p;
110 fprintf (stderr, "%s event from %s\n", ev->type,
111 Accessible_getName (&ev->source));
114 static int _festival_init ()
117 struct sockaddr_in name;
120 name.sin_family = AF_INET;
121 name.sin_port = htons (1314);
122 name.sin_addr.s_addr = htonl(INADDR_ANY);
123 fd = socket (PF_INET, SOCK_STREAM, 0);
125 while (connect(fd, (struct sockaddr *) &name, sizeof (name)) < 0) {
132 _festival_write ("(audio_mode'async)", fd);
133 _festival_write ("(Parameter.set 'Duration_Stretch 0.5)", fd);
134 _festival_write ("(Parameter.set 'Duration_Model 'Tree_ZScore)", fd);
138 static void _festival_say (const char *text, const char *voice, boolean shutup)
144 gchar voice_spec[32];
148 fd = _festival_init ();
151 fprintf (stderr, "saying text: %s\n", text);
153 quoted = g_malloc(64+strlen(text)*2);
155 sprintf (prefix, "(SayText \"");
157 strncpy(quoted, prefix, 10);
158 p = quoted+strlen(prefix);
160 if ( *text == '\\' || *text == '"' )
169 if(shutup) _festival_write ("(audio_mode'shutup)\n", fd);
172 sprintf (voice_spec, "(%s)\n", voice);
173 _festival_write (voice_spec, fd);
177 _festival_write ("(Parameter.set 'Duration_Model 'Tree_ZScore)\n", fd);
178 _festival_write ("(Parameter.set 'Duration_Stretch 0.5)\n", fd);
180 _festival_write (quoted, fd);
185 static void _festival_write (const gchar *command_string, int fd)
187 fprintf(stderr, command_string);
192 write(fd, command_string, strlen(command_string));