Eclectic Media Git rhapsode / 4298dd3
Draft SpeechD integration. Adrian Cochrane 5 months ago
1 changed file(s) with 35 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
77 #include "HsFFI.h"
88 #include <espeak-ng/espeak_ng.h>
99 #include <sndfile.h>
10
11 // #define WITH_SPEECHD // FIXME Doesn't support audio cues, navigation, or even read the full page.
12 #ifdef WITH_SPEECHD
13 #include <speechd_types.h>
14 #include <libspeechd.h>
15 #endif
1016
1117 /* Exported Haskell functions/types */
1218 struct session;
225231 FILE *fd_links = NULL;
226232 int use_espeak = 0;
227233 tcgetattr(0, &stored_settings);
234 #ifdef WITH_SPEECHD
235 SPDConnection *spd_conn = NULL;
236 #endif
228237
229238 int c;
230239 opterr = 0;
240 #ifdef WITH_SPEECHD
241 while ((c = getopt(argc, argv, "xs::l::kw::dh")) != -1) {
242 #else
231243 while ((c = getopt(argc, argv, "xs::l::kw::h")) != -1) {
244 #endif
232245 switch (c) {
233246 case 'x':
234247 mimes = "text/xml application/xml application/xhtml+xml text/html text/plain";
253266 use_espeak = 1;
254267 path_wav = optarg;
255268 break;
269 #ifdef WITH_SPEECHD
270 case 'd':
271 spd_conn = spd_open("rhapsode", "main", NULL, SPD_MODE_SINGLE);
272 if (spd_conn == NULL) fprintf(stderr, "Failed to open SpeechD connection, ignoring\n");
273 spd_set_data_mode(spd_conn, SPD_DATA_SSML);
274 break;
275 #endif
256276 case '?':
257277 fprintf(stderr, "Invalid flag %c\n\n", optopt);
258278 case 'h':
269289 }
270290 }
271291 if (fd_ssml == stdout && fd_links == stdout) fd_links = stderr;
272 if (fd_ssml == NULL && fd_links == NULL && !use_espeak) use_espeak = 1;
292 #ifdef WITH_SPEECHD
293 if (fd_ssml == NULL && fd_links == NULL && spd_conn == NULL && !use_espeak)
294 #else
295 if (fd_ssml == NULL && fd_links == NULL && !use_espeak)
296 #endif
297 use_espeak = 1;
273298
274299 struct session *session = c_newSession();
275300 struct page *referer = c_initialReferer();
278303 char *ssml;
279304 for (int i = optind; i < argc; i++) {
280305 if (use_espeak && speak_err == 0) speak(argv[i], NULL);
306 #ifdef WITH_SPEECHD
307 else if (spd_conn != NULL) spd_say(spd_conn, SPD_MESSAGE, argv[i]);
308 #endif
281309 else printf("%s\n", argv[i]);
282310
283311 struct page *page = c_fetchURL(session, mimes, referer, argv[i]);
287315 if (fd_ssml != NULL) fprintf(fd_ssml, "%s\n", ssml);
288316 if (fd_links != NULL) write_links(fd_links, links);
289317 if (use_espeak & speak_err == 0) speak(ssml, "main");
318 #ifdef WITH_SPEECHD
319 if (spd_conn != NULL) spd_say(spd_conn, SPD_MESSAGE, ssml);
320 #endif
290321
291322 c_freePage(page);
292323 }
293324 if (use_espeak & speak_err == 0) speak_err = speak_finalize(ssml);
325 #ifdef WITH_SPEECHD
326 if (spd_conn != NULL) spd_close(spd_conn);
327 #endif
294328
295329 c_freePage(referer);
296330 c_freeSession(session);