-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathflite_time_main.c
223 lines (200 loc) · 6.28 KB
/
flite_time_main.c
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
/*************************************************************************/
/* */
/* Language Technologies Institute */
/* Carnegie Mellon University */
/* Copyright (c) 2001 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author: Alan W Black (awb@cs.cmu.edu) */
/* Date: June 2001 */
/*************************************************************************/
/* */
/* Example of clunits voice (ldom time) */
/* */
/*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include "flite.h"
#include "cst_clunits.h"
#include "cst_regex.h"
#include "cst_units.h"
#include "cst_wave.h"
#include "cst_track.h"
#include "cst_sigpr.h"
cst_voice *register_cmu_time_awb(const char *voxdir);
static const char *time_approx(int hour, int minute);
static const char *time_min(int hour, int minute);
static const char *time_hour(int hour, int minute);
static const char *time_tod(int hour, int minute);
int main(int argc, char **argv)
{
cst_voice *v;
char thetime[1024];
char b[3];
int hour, min;
cst_regex *timex;
char *output = "play";
if (argc != 2)
{
fprintf(stderr,"usage: flite_time HH:MM\n");
exit(-1);
}
timex = new_cst_regex("[012][0-9]:[0-5][0-9]");
if (!cst_regex_match(timex,argv[1]))
{
fprintf(stderr,"not a valid time\n");
fprintf(stderr,"usage: flite_time HH:MM\n");
exit(-1);
}
delete_cst_regex(timex);
b[2] = '\0';
b[0] = argv[1][0];
b[1] = argv[1][1];
hour = atoi(b);
b[0] = argv[1][3];
b[1] = argv[1][4];
min = atoi(b);
flite_init();
v = register_cmu_time_awb(NULL);
sprintf(thetime,
"The time is now, %s %s %s, %s.",
time_approx(hour,min),
time_min(hour,min),
time_hour(hour,min),
time_tod(hour,min));
printf("%s\n",thetime);
flite_text_to_speech(thetime,v,output);
return 0;
}
static const char *time_approx(int hour, int minute)
{
int mm;
mm = minute % 5;
if ((mm == 0) || (mm == 4))
return "exactly";
else if (mm == 1)
return "just after";
else if (mm == 2)
return "a little after";
else
return "almost";
}
static const char *time_min(int hour, int minute)
{
int mm;
mm = minute / 5;
if ((minute % 5) > 2)
mm += 1;
mm = mm * 5;
if (mm > 55)
mm = 0;
if (mm == 0)
return "";
else if (mm == 5)
return "five past";
else if (mm == 10)
return "ten past";
else if (mm == 15)
return "quarter past";
else if (mm == 20)
return "twenty past";
else if (mm == 25)
return "twenty-five past";
else if (mm == 30)
return "half past";
else if (mm == 35)
return "twenty-five to";
else if (mm == 40)
return "twenty to";
else if (mm == 45)
return "quarter to";
else if (mm == 50)
return "ten to";
else if (mm == 55)
return "five to";
else
return "five to";
}
static const char *time_hour(int hour, int minute)
{
int hh;
hh = hour;
if (minute > 32)
hh += 1;
if (hh == 24)
hh = 0;
if (hh > 12)
hh -= 12;
if (hh == 0)
return "midnight";
else if (hh == 1)
return "one";
else if (hh == 2)
return "two";
else if (hh == 3)
return "three";
else if (hh == 4)
return "four";
else if (hh == 5)
return "five";
else if (hh == 6)
return "six";
else if (hh == 7)
return "seven";
else if (hh == 8)
return "eight";
else if (hh == 9)
return "nine";
else if (hh == 10)
return "ten";
else if (hh == 11)
return "eleven";
else if (hh == 12)
return "twelve";
else
return "twelve";
}
static const char *time_tod(int hour, int minute)
{
int hh = hour;
if (minute > 58)
hh++;
if (hh == 24)
return "";
else if (hh > 17)
return "in the evening";
else if (hh > 11)
return "in the afternoon";
else if ((hh == 0) && (minute < 33))
return "";
else
return "in the morning";
}