MIDAS
Loading...
Searching...
No Matches
mspeaker.cpp
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: mspeaker.c
4 Created by: Pierre-Andre Amaudruz, Stefan Ritt
5
6 Contents: Speaks midas messages
7
8 Requires Microsoft Speech SDK 5.1 to be installed under
9
10 \Program Files\Microsoft Speech SDK 5.1\
11
12 $Id$
13
14\********************************************************************/
15
16#include <stdlib.h>
17#include <sapi.h>
18#include "midas.h"
19#include "msystem.h"
20
21char mtUserStr[128], mtTalkStr[128];
23
24ISpVoice* Voice = NULL; // The voice interface
25
26char *type_name[] = {
27 "ERROR",
28 "INFO",
29 "DEBUG" "USER",
30 "LOG",
31 "TALK",
32 "CALL",
33};
34
35/*----- receive_message --------------------------------------------*/
36
38{
39 char str[256], *pc, *sp;
40 static DWORD last_beep = 0;
41
42 /* print message */
43 printf("%s\n", (char *) (message));
44
45 /* skip none talking message */
46 if (header->trigger_mask == MT_TALK || header->trigger_mask == MT_USER) {
47
48 /* strip [<username.] */
49 pc = strchr((char *) (message), ']') + 2;
50 sp = pc + strlen(pc) - 1;
51 while (*sp == ' ' || *sp == '\t')
52 sp--;
53 *(++sp) = '\0';
54
55 if ((ss_time() - last_beep) > shutupTime) {
56 switch (header->trigger_mask) {
57 case MT_TALK:
58 if (mtTalkStr[0])
60 break;
61 case MT_USER:
62 if (mtUserStr[0])
64 break;
65 }
66
67 // beep first
70
71 ss_sleep(500);
72
73 wchar_t wcstring[1000];
75
76 // Speak!
77 Voice->Speak(wcstring, SPF_DEFAULT, NULL );
78 }
79 }
80
81 return;
82}
83
84/*------------------------------------------------------------------*/
85
86int main(int argc, char *argv[])
87{
88 INT status, i, ch;
91
92 /* get default from environment */
94
95 /* default wave files */
96 strcpy(mtTalkStr, "\\Windows\\Media\\notify.wav");
97 strcpy(mtUserStr, "\\Windows\\Media\\notify.wav");
98
99 /* parse command line parameters */
100 for (i = 1; i < argc; i++) {
101 if (argv[i][0] == '-') {
102 if (i + 1 >= argc || argv[i + 1][0] == '-')
103 goto usage;
104 if (argv[i][1] == 'e')
105 strcpy(exp_name, argv[++i]);
106 else if (argv[i][1] == 'h')
107 strcpy(host_name, argv[++i]);
108 else if (argv[i][1] == 't')
109 strcpy(mtTalkStr, argv[++i]);
110 else if (argv[i][1] == 'u')
111 strcpy(mtUserStr, argv[++i]);
112 else if (argv[i][1] == 's')
113 shutupTime = atoi(argv[++i]);
114 else {
115 usage:
116 printf("usage: mspeaker [-h <hostname>] [-e <experiment>]\n\n");
117 printf(" [-t <file>] Specify the alert wave file for MT_TALK messages\n");
118 printf(" [-u <file>] Specify the alert wave file for MT_USER messages\n");
119 printf(" [-s <sec>] Specify the min time interval between alert [s]\n");
120 return 0;
121 }
122 }
123 }
124
125 // Initialize COM
126 CoInitialize ( NULL );
127
128 // Create the voice interface object
130 if (Voice == NULL) {
131 printf("Cannot initialize speech system\n");
132 return 1;
133 }
134
135 reconnect:
136
137 /* now connect to server */
139 if (status != CM_SUCCESS)
140 return 1;
141
143
144 /* increased watchdog timeout for long messages */
146
147 printf("Midas Message Talker connected to %s. Press \"!\" to exit\n",
148 host_name[0] ? host_name : "local host");
149
150 do {
151 status = cm_yield(1000);
152 if (ss_kbhit()) {
153 ch = getch();
154 if (ch == 'r')
156 if (ch == '!')
157 break;
158 }
159
160 if (status == SS_ABORT) {
162 printf("Trying to reconnect...\n");
163 ss_sleep(3000);
164 goto reconnect;
165 }
166
167 } while (status != RPC_SHUTDOWN);
168
169 // Shutdown the voice
170 if (Voice != NULL)
171 Voice->Release();
172
173 // Shutdown COM
175
177 return 1;
178}
static void usage()
INT cm_yield(INT millisec)
Definition midas.cxx:5642
INT cm_connect_experiment(const char *host_name, const char *exp_name, const char *client_name, void(*func)(char *))
Definition midas.cxx:2278
INT cm_disconnect_experiment(void)
Definition midas.cxx:2846
INT cm_get_environment(char *host_name, int host_name_size, char *exp_name, int exp_name_size)
Definition midas.cxx:2134
INT cm_set_watchdog_params(BOOL call_watchdog, DWORD timeout)
Definition midas.cxx:3283
#define CM_SUCCESS
Definition midas.h:582
#define SS_ABORT
Definition midas.h:677
#define RPC_SHUTDOWN
Definition midas.h:707
unsigned int DWORD
Definition mcstd.h:51
#define MT_TALK
Definition midas.h:547
#define MT_USER
Definition midas.h:545
BOOL ss_kbhit()
Definition system.cxx:3664
DWORD ss_time()
Definition system.cxx:3462
INT ss_sleep(INT millisec)
Definition system.cxx:3628
void ss_clear_screen()
Definition system.cxx:7299
INT cm_msg_register(EVENT_HANDLER *func)
Definition midas.cxx:1051
int main()
Definition hwtest.cxx:23
char exp_name[NAME_LENGTH]
Definition mana.cxx:243
char host_name[HOST_NAME_LENGTH]
Definition mana.cxx:242
INT i
Definition mdump.cxx:32
INT HNDLE
Definition midas.h:132
int INT
Definition midas.h:129
#define TRUE
Definition midas.h:182
#define NAME_LENGTH
Definition midas.h:272
#define message(type, str)
HNDLE hBuf
Definition minife.c:23
char mtUserStr[128]
Definition mspeaker.cpp:21
char mtTalkStr[128]
Definition mspeaker.cpp:21
ISpVoice * Voice
Definition mspeaker.cpp:24
void receive_message(HNDLE hBuf, HNDLE id, EVENT_HEADER *header, void *message)
Definition mspeaker.cpp:37
char * type_name[]
Definition mspeaker.cpp:26
DWORD shutupTime
Definition mspeaker.cpp:22
char str[256]
Definition odbhist.cxx:33
DWORD status
Definition odbhist.cxx:39
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
short int trigger_mask
Definition midas.h:853