Add telem replay and larger labels
[fw/altos] / aoview / aoview_voice.c
1 /*
2  * Copyright © 2009 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #include "aoview.h"
19
20 #if HAVE_FLITE
21 #include <stdarg.h>
22
23 FILE    *aoview_flite;
24
25 void aoview_voice_open(void)
26 {
27         if (!aoview_flite)
28                 aoview_flite = popen("aoview_flite", "w");
29 }
30
31 void aoview_voice_close(void)
32 {
33         if (aoview_flite) {
34                 pclose(aoview_flite);
35                 aoview_flite = NULL;
36         }
37 }
38
39 void aoview_voice_speak(char *format, ...)
40 {
41         va_list ap;
42
43         if (aoview_flite) {
44                 va_start(ap, format);
45                 vfprintf(aoview_flite, format, ap);
46                 fflush(aoview_flite);
47                 va_end(ap);
48         }
49 }
50
51 #else
52 void aoview_voice_open(void)
53 {
54 }
55
56 void aoview_voice_close(void)
57 {
58 }
59
60 void aoview_voice_speak(char *format, ...)
61 {
62 }
63 #endif
64
65
66 static GtkCheckMenuItem *voice_enable;
67
68 static void
69 aoview_voice_enable(GtkWidget *widget, gpointer data)
70 {
71         if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) {
72                 aoview_voice_open();
73                 aoview_voice_speak("enable voice system\n");
74         } else {
75                 aoview_voice_speak("disable voice system\n");
76                 aoview_voice_close();
77         }
78 }
79
80 void
81 aoview_voice_init(GladeXML *xml)
82 {
83         aoview_voice_open();
84
85         voice_enable = GTK_CHECK_MENU_ITEM(glade_xml_get_widget(xml, "voice_enable"));
86         assert(voice_enable);
87
88         g_signal_connect(G_OBJECT(voice_enable), "toggled",
89                          G_CALLBACK(aoview_voice_enable),
90                          voice_enable);
91 }