1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
/* This file is a part of gnome-voice-control
*
* Copyright (C) 2007 Shyam Karanattu <aeshyamae@gmail.com>
*
* main.c:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#define WNCK_I_KNOW_THIS_IS_UNSTABLE
#include <libwnck/libwnck.h>
#include <gtk/gtk.h>
#include <X11/Xlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include <signal.h>
WnckScreen *scr;
WnckWindow *win;
GList *tmp,*head;
#define DHVANISCRIPT GNOMEDATADIR"/sharika/parser.sh"
#include <setjmp.h>
#include <string.h>
#include "s2types.h"
#include "err.h"
#include "ad.h"
#include "cont_ad.h"
#include "fbs.h"
#define SAMPLE_RATE 16000
static ad_rec_t *ad;
/* Sleep for specified msec */
static void sleep_msec (int32 ms)
{
struct timeval tmo;
tmo.tv_sec = 0;
tmo.tv_usec = ms*1000;
select(0, NULL, NULL, NULL, &tmo);
}
static void utterance_loop(int argc,char *argv[])
{
int16 adbuf[4096];
int32 k, fr, ts, rem;
char *hyp;
cont_ad_t *cont;
int count=0,i=1,flag;
char word[256];
/* Initialize continuous listening module */
if ((cont = cont_ad_init (ad, ad_read)) == NULL)
E_FATAL("cont_ad_init failed\n");
if (ad_start_rec (ad) < 0)
E_FATAL("ad_start_rec failed\n");
if (cont_ad_calib (cont) < 0)
E_FATAL("cont_ad_calib failed\n");
for (;;)
{
/* Indicate listening for next utterance */
printf ("READY....\n");
fflush (stdout); fflush (stderr);
/* Await data for next utterance */
while ((k = cont_ad_read (cont, adbuf, 4096)) == 0)
sleep_msec(200);
if (k < 0)
E_FATAL("cont_ad_read failed\n");
/*
* Non-zero amount of data received; start recognition of new utterance.
* NULL argument to uttproc_begin_utt => automatic generation of utterance-id.
*/
if (uttproc_begin_utt (NULL) < 0)
E_FATAL("uttproc_begin_utt() failed\n");
uttproc_rawdata (adbuf, k, 0);
printf ("Listening...\n"); fflush (stdout);
/* Note timestamp for this first block of data */
ts = cont->read_ts;
/* Decode utterance until end (marked by a "long" silence, >1sec) */
for (;;) {
/* Read non-silence audio data, if any, from continuous listening module */
if ((k = cont_ad_read (cont, adbuf, 4096)) < 0)
E_FATAL("cont_ad_read failed\n");
if (k == 0) {
/*
* No speech data available; check current timestamp with most recent
* speech to see if more than 1 sec elapsed. If so, end of utterance.
*/
if ((cont->read_ts - ts) > DEFAULT_SAMPLES_PER_SEC)
break;
} else {
/* New speech data received; note current timestamp */
ts = cont->read_ts;
}
/*
* Decode whatever data was read above. NOTE: Non-blocking mode!!
* rem = #frames remaining to be decoded upon return from the function.
*/
rem = uttproc_rawdata (adbuf, k, 0);
/* If no work to be done, sleep a bit */
if ((rem == 0) && (k == 0))
sleep_msec (20);
}
/*
* Utterance ended; flush any accumulated, unprocessed A/D data and stop
* listening until current utterance completely decoded
*/
ad_stop_rec (ad);
while (ad_read (ad, adbuf, 4096) >= 0);
cont_ad_reset (cont);
printf ("Stopped listening, please wait...\n"); fflush (stdout);
#if 0
/* Power histogram dump (FYI) */
cont_ad_powhist_dump (stdout, cont);
#endif
/* Finish decoding, obtain and print result */
uttproc_end_utt ();
if (uttproc_result (&fr, &hyp, 1) < 0)
E_FATAL("uttproc_result failed\n");
/*obtaining the results*/
sscanf (hyp, "%s", word);
printf ("%d: %s\n", fr,word); fflush (stdout);
win=wnck_screen_get_active_window(scr);
tmp=wnck_screen_get_windows(wnck_window_get_screen(win));
i=g_list_index(tmp,win);/*the place value of window in the list*/
printf("<<<<<<<<<<<<<<>>>>>>>>>>>>>>i:%d,%s\n\n\n",i,wnck_window_get_name(win));
count=0;
while(tmp!=NULL)
{
printf("%d:%s\n\n",count,wnck_window_get_name(tmp->data));
tmp=tmp->next;count++;
}
/*comparison and action for DAKKU */
if(strcmp(word,"PADU")==0)
g_spawn_command_line_async("totem --play",NULL);
if(strcmp(word,"EMACS")==0)
g_spawn_command_line_async("emacs",NULL);
if(strcmp(word,"SAMAYAM")==0)
g_spawn_command_line_async(DHVANISCRIPT,NULL);
if(strcmp(word,"VALAPARATHU")==0)
g_spawn_command_line_async("epiphany",NULL);
if(strcmp(word,"EAZHUTHIDAM")==0)
g_spawn_command_line_async("gedit",NULL);
/*Minimizing current active window*/
if (strcmp (word, "CHURUKKU") == 0)
wnck_window_minimize(win);
/*Moving focus(active window)towards the left of the panel.The active window is changed to
the next normal window on the left.effect of alt+tab key press*/
if(strcmp(word,"ADUTHATHU")==0)
{
win=wnck_screen_get_active_window(scr);
tmp=wnck_screen_get_windows(wnck_window_get_screen(win));
while(tmp!=NULL)/*while traces the current active window through the list*/
{
printf("tracing:current:%s\n\ntmp:%s\n\n",wnck_window_get_name(win),wnck_window_get_name(tmp->data));
if(tmp->data==win)
{
printf("BREAKED with tmp:%s\n",wnck_window_get_name(tmp->data));
break;
}
tmp=tmp->next;
}
if(tmp==NULL){printf("BULL SHIT GIVE A WINDOW IN THE LIST\n\n");}//exit(1);}
if(tmp->next==NULL)/*shifting back to the first window by refreshing the list*/
tmp=wnck_screen_get_windows(wnck_window_get_screen(win));
else
tmp=tmp->next;
printf("cuow:%s\n\n",wnck_window_get_name(tmp->data));
while(tmp!=NULL)
{
printf("tmp in while:%s\n\n",wnck_window_get_name(tmp->data));
if(wnck_window_get_window_type(tmp->data)==WNCK_WINDOW_NORMAL)
{
wnck_window_activate(tmp->data,0);
flag=1;
break;
}
else
tmp=tmp->next;
}
if(flag==0)
{
printf("FLAG==0 DETECTED:\n");
tmp=wnck_screen_get_windows(wnck_window_get_screen(win));
while(tmp!=NULL)
{
printf("tmp in last while:%s\n",wnck_window_get_name(tmp->data));
if(wnck_window_get_window_type(tmp->data)==WNCK_WINDOW_NORMAL)
{
wnck_window_activate(tmp->data,0);
break;
}
else
tmp=tmp->next;
}
}
}
if(strcmp(word,"VALUTHAKKU")==0)
{
if(wnck_window_get_window_type(win)!= WNCK_WINDOW_NORMAL)
{
if(wnck_window_get_window_type(wnck_screen_get_previously_active_window(scr))==WNCK_WINDOW_NORMAL)
win=wnck_screen_get_previously_active_window(scr);
}
wnck_window_unminimize(win,0);
}
while(gtk_events_pending())/*gtk probing and refreshing the win and tmp*/
{
gtk_main_iteration();
win=wnck_screen_get_active_window(scr);
tmp=wnck_screen_get_windows(wnck_window_get_screen(win));
}
/* Resume A/D recording for next utterance */
if (ad_start_rec (ad) < 0)
E_FATAL("ad_start_rec failed\n");
}
cont_ad_close (cont);
}
static char *sphinx_command =
"sharika "
"-bestpath yes "
"-fsgfn " GNOMEDATADIR "/sharika/sharika.fsg "
"-dictfn " GNOMEDATADIR "/sharika/sharika.dic "
"-hmmdirlist " GNOMEDATADIR "/sharika/model "
"-hmmext chmm "
"-mdeffn "GNOMEDATADIR "/sharika/mdef "
"-meanfn " GNOMEDATADIR "/sharika/means "
"-varfn " GNOMEDATADIR "/sharika/variances "
"-mixwfn " GNOMEDATADIR "/sharika/mixture_weights ";
static jmp_buf jbuf;
static void sighandler(int signo)
{
longjmp(jbuf, 1);
}
int main (int argc, char *argv[])
{
/* Make sure we exit cleanly (needed for profiling among other things) */
g_shell_parse_argv(sphinx_command,&argc,&argv,NULL);
gtk_init(&argc, &argv);
scr = wnck_screen_get_default();
while(gtk_events_pending()) gtk_main_iteration();
win = wnck_screen_get_active_window(scr);
tmp=wnck_screen_get_windows(wnck_window_get_screen(win));
signal(SIGINT, &sighandler);
fbs_init (argc, argv);
if ((ad = ad_open_sps (SAMPLE_RATE)) == NULL)
E_FATAL("ad_open_sps failed\n");
// E_INFO("%s COMPILED ON: %s, AT: %s\n\n", argv[0], __DATE__, __TIME__);
if (setjmp(jbuf) == 0) {
utterance_loop (argc,argv);
}
fbs_end ();
ad_close (ad);
return 0;
}
|