Debian Codegraph @

testsuite/flite_test_main.c

raw
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 2015 */
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: February 2015 */
35 /*************************************************************************/
36 /* */
37 /* A minmal example test program */
38 /* */
39 /*************************************************************************/
40
41 #include <stdio.h>
42 #include <string.h>
43 #include "flite.h"
44
45 void usenglish_init(cst_voice *v);
46 cst_lexicon *cmulex_init(void);
47
48 int main(int argc, char **argv)
49 {
50 cst_voice *v;
51 cst_wave *w;
52 cst_utterance *u;
53 const char *voice_pathname;
54 const char *text;
55 const char *outfile;
56
57 if (argc != 4)
58 {
59 fprintf(stderr,"usage: VOICE.flitevox TEXT WAVEFILE\n");
60 return 1;
61 }
62
63 voice_pathname = argv[1]; /* pathname to .flitevox file */
64 text = argv[2]; /* text to be synthesized */
65 outfile = argv[3]; /* output file (or "play" or "none") */
66
67 /* Initialize Flite, and set up language and lexicon */
68 flite_init();
69 flite_add_lang("eng",usenglish_init,cmulex_init);
70 flite_add_lang("usenglish",usenglish_init,cmulex_init);
71
72 /* Load and select voice */
73 v = flite_voice_select(voice_pathname);
74 if (v == NULL)
75 {
76 fprintf(stderr,"failed to load voice: %s\n",voice_pathname);
77 return 1;
78 }
79
80 u = flite_synth_text(text,v);
81 w = utt_wave(u);
82
83 /* Play the resulting wave, save it to a filename, or do none of these */
84 if (cst_streq(outfile,"play"))
85 play_wave(w);
86 else if (!cst_streq(outfile,"none"))
87 cst_wave_save_riff(w,outfile);
88
89 delete_utterance(u); /* will delete w too */
90
91 return 0;
92 }