Debian Codegraph @

main/flite_time_main.c

raw
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 2001 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Author: Alan W Black ([email protected]) */
34 /* Date: June 2001 */
35 /*************************************************************************/
36 /* */
37 /* Example of clunits voice (ldom time) */
38 /* */
39 /*************************************************************************/
40
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <sys/time.h>
45 #include <unistd.h>
46
47 #include "flite.h"
48 #include "cst_clunits.h"
49 #include "cst_regex.h"
50 #include "cst_units.h"
51 #include "cst_wave.h"
52 #include "cst_track.h"
53 #include "cst_sigpr.h"
54
55 cst_voice *register_cmu_time_awb(const char *voxdir);
56 static const char *time_approx(int hour, int minute);
57 static const char *time_min(int hour, int minute);
58 static const char *time_hour(int hour, int minute);
59 static const char *time_tod(int hour, int minute);
60
61 int main(int argc, char **argv)
62 {
63 cst_voice *v;
64 char thetime[1024];
65 char b[3];
66 int hour, min;
67 cst_regex *timex;
68 char *output = "play";
69
70 if (argc != 2)
71 {
72 fprintf(stderr,"usage: flite_time HH:MM\n");
73 exit(-1);
74 }
75 timex = new_cst_regex("[012][0-9]:[0-5][0-9]");
76 if (!cst_regex_match(timex,argv[1]))
77 {
78 fprintf(stderr,"not a valid time\n");
79 fprintf(stderr,"usage: flite_time HH:MM\n");
80 exit(-1);
81 }
82 delete_cst_regex(timex);
83 b[2] = '\0';
84 b[0] = argv[1][0];
85 b[1] = argv[1][1];
86 hour = atoi(b);
87 b[0] = argv[1][3];
88 b[1] = argv[1][4];
89 min = atoi(b);
90
91 flite_init();
92
93 v = register_cmu_time_awb(NULL);
94
95 sprintf(thetime,
96 "The time is now, %s %s %s, %s.",
97 time_approx(hour,min),
98 time_min(hour,min),
99 time_hour(hour,min),
100 time_tod(hour,min));
101
102 printf("%s\n",thetime);
103 flite_text_to_speech(thetime,v,output);
104
105 return 0;
106 }
107
108 static const char *time_approx(int hour, int minute)
109
110 {
111 int mm;
112
113 mm = minute % 5;
114
115 if ((mm == 0) || (mm == 4))
116 return "exactly";
117 else if (mm == 1)
118 return "just after";
119 else if (mm == 2)
120 return "a little after";
121 else
122 return "almost";
123 }
124
125 static const char *time_min(int hour, int minute)
126 {
127 int mm;
128
129 mm = minute / 5;
130 if ((minute % 5) > 2)
131 mm += 1;
132 mm = mm * 5;
133 if (mm > 55)
134 mm = 0;
135
136 if (mm == 0)
137 return "";
138 else if (mm == 5)
139 return "five past";
140 else if (mm == 10)
141 return "ten past";
142 else if (mm == 15)
143 return "quarter past";
144 else if (mm == 20)
145 return "twenty past";
146 else if (mm == 25)
147 return "twenty-five past";
148 else if (mm == 30)
149 return "half past";
150 else if (mm == 35)
151 return "twenty-five to";
152 else if (mm == 40)
153 return "twenty to";
154 else if (mm == 45)
155 return "quarter to";
156 else if (mm == 50)
157 return "ten to";
158 else if (mm == 55)
159 return "five to";
160 else
161 return "five to";
162 }
163
164 static const char *time_hour(int hour, int minute)
165 {
166 int hh;
167
168 hh = hour;
169 if (minute > 32)
170 hh += 1;
171 if (hh == 24)
172 hh = 0;
173 if (hh > 12)
174 hh -= 12;
175
176 if (hh == 0)
177 return "midnight";
178 else if (hh == 1)
179 return "one";
180 else if (hh == 2)
181 return "two";
182 else if (hh == 3)
183 return "three";
184 else if (hh == 4)
185 return "four";
186 else if (hh == 5)
187 return "five";
188 else if (hh == 6)
189 return "six";
190 else if (hh == 7)
191 return "seven";
192 else if (hh == 8)
193 return "eight";
194 else if (hh == 9)
195 return "nine";
196 else if (hh == 10)
197 return "ten";
198 else if (hh == 11)
199 return "eleven";
200 else if (hh == 12)
201 return "twelve";
202 else
203 return "twelve";
204 }
205
206 static const char *time_tod(int hour, int minute)
207 {
208 int hh = hour;
209
210 if (minute > 58)
211 hh++;
212
213 if (hh == 24)
214 return "";
215 else if (hh > 17)
216 return "in the evening";
217 else if (hh > 11)
218 return "in the afternoon";
219 else if ((hh == 0) && (minute < 33))
220 return "";
221 else
222 return "in the morning";
223 }