0
|
1 |
/**
|
|
2 |
* $Id: proser_interface.c 53 2008-01-10 00:19:41Z mbroeker $
|
|
3 |
* $URL: http://localhost/svn/c/VirtualReader/trunk/src/proser_interface.c $
|
|
4 |
*/
|
|
5 |
|
|
6 |
#ifdef PROSER
|
|
7 |
#include <proser_interface.h>
|
|
8 |
|
|
9 |
ttshandles interface_init (tts_options propt)
|
|
10 |
{
|
|
11 |
|
|
12 |
ttshandles pr_handle;
|
|
13 |
|
|
14 |
// initialize Proser options and set default values for a given voice
|
|
15 |
if (init_ProserOpt (&propt.ProserOpt, propt.Voice)) {
|
|
16 |
fprintf (stderr, "Fatal error occurred in set_ProserOpt: %s\n", GetLastNlpErrorDescription (NULL));
|
|
17 |
exit (-1);
|
|
18 |
}
|
|
19 |
// the path to the TTS input data like dictionaries and prosodic stuff has to be set
|
|
20 |
|
|
21 |
propt.ProserOpt.Path = strdup (propt.Path);
|
|
22 |
|
|
23 |
// here some more manipulations of the standard settings can be done
|
|
24 |
|
|
25 |
propt.ProserOpt.PreEmphasis = propt.PreEmphasis;
|
|
26 |
propt.ProserOpt.Speed = propt.Speed;
|
|
27 |
|
|
28 |
// initialize channel //
|
|
29 |
if (!(pr_handle.GermanNlp = OpenNlp (&propt.ProserOpt))) {
|
|
30 |
fprintf (stderr, "Fatal error occurred in OpenNlp: %s (%d)\n",
|
|
31 |
GetLastNlpErrorDescription (pr_handle.GermanNlp), (int)GetLastNlpError (pr_handle.GermanNlp));
|
|
32 |
exit (-1);
|
|
33 |
}
|
|
34 |
// delete structure for Proser Options //
|
|
35 |
if (delete_ProserOpt (&propt.ProserOpt)) {
|
|
36 |
fprintf (stderr, "Fatal error occurred in delete_ProserOpt: %s\n", GetLastNlpErrorDescription (NULL));
|
|
37 |
exit (-1);
|
|
38 |
}
|
|
39 |
return pr_handle;
|
|
40 |
}
|
|
41 |
|
|
42 |
int interface_write_to_wav (char *Filename, char *Text, ttshandles prosh, tts_options propt)
|
|
43 |
{
|
|
44 |
// write Text to a file
|
|
45 |
if (ProserSynthText (prosh.GermanNlp, Text, Filename, propt.FileType, propt.Stype)) {
|
|
46 |
fprintf (stderr, "Fatal error occurred in ProserSynthText: %s\n", GetLastNlpErrorDescription (prosh.GermanNlp));
|
|
47 |
return (-1);
|
|
48 |
}
|
|
49 |
return (0);
|
|
50 |
}
|
|
51 |
|
|
52 |
long *interface_get_timing (ttshandles prosh, char *Text)
|
|
53 |
{
|
|
54 |
// analyze given text, return array with long values containing
|
|
55 |
// time in ms when each word of the given text will start in the
|
|
56 |
// output
|
|
57 |
long *timings = NULL;
|
|
58 |
LPPHONEME PhoneticSentenceDescription;
|
|
59 |
long NumberOfPhoneticUnits;
|
|
60 |
int i = 0, WordNum = 0;
|
|
61 |
|
|
62 |
PhoneticSentenceDescription = TextToPho (prosh.GermanNlp, Text, &NumberOfPhoneticUnits);
|
|
63 |
#ifdef DEBUG
|
|
64 |
printf ("\n[S] %s\n", Text);
|
|
65 |
#endif
|
|
66 |
while (i < (NumberOfPhoneticUnits - 1)) {
|
|
67 |
if (PhoneticSentenceDescription[i + 1].Event != 0) {
|
|
68 |
timings = realloc (timings, (WordNum + 2) * sizeof (long));
|
|
69 |
timings[WordNum] = PhoneticSentenceDescription[i + 1].Offset;
|
|
70 |
#ifdef DEBUG
|
|
71 |
printf ("Wort:\t %i \t Time: %ld ms\n", WordNum, PhoneticSentenceDescription[i + 1].Offset);
|
|
72 |
#endif
|
|
73 |
WordNum++;
|
|
74 |
}
|
|
75 |
i++;
|
|
76 |
}
|
|
77 |
timings[WordNum] = 0;
|
|
78 |
return timings;
|
|
79 |
}
|
|
80 |
|
|
81 |
tts_options interface_get_cl_opts (int argc, char **argv)
|
|
82 |
{
|
|
83 |
int i, j;
|
|
84 |
tts_options propt;
|
|
85 |
|
|
86 |
propt.TextFile = propt.AudioFile = propt.Voice = propt.Path = NULL;
|
|
87 |
|
|
88 |
j = 0;
|
|
89 |
propt.PreEmphasis = 0.0f;
|
|
90 |
propt.Speed = 1.0f;
|
|
91 |
propt.Stype = LIN16;
|
|
92 |
propt.FileType = WAV;
|
|
93 |
|
|
94 |
for (i = 1; i < argc; i++) {
|
|
95 |
if (!strcmp (argv[i], "-i")) {
|
|
96 |
propt.TextFile = argv[++i];
|
|
97 |
continue;
|
|
98 |
} else if (!strcmp (argv[i], "-o")) {
|
|
99 |
propt.AudioFile = argv[++i];
|
|
100 |
continue;
|
|
101 |
} else if (!strcmp (argv[i], "-v")) {
|
|
102 |
propt.Voice = argv[++i];
|
|
103 |
continue;
|
|
104 |
} else if (!strcmp (argv[i], "-p")) {
|
|
105 |
propt.Path = argv[++i];
|
|
106 |
continue;
|
|
107 |
} else if (!strcmp (argv[i], "-pre")) {
|
|
108 |
propt.PreEmphasis = atof (argv[++i]);
|
|
109 |
continue;
|
|
110 |
} else if (!strcmp (argv[i], "-speed")) {
|
|
111 |
propt.Speed = atof (argv[++i]);
|
|
112 |
continue;
|
|
113 |
} else if (!strcmp (argv[i], "-format")) {
|
|
114 |
i++;
|
|
115 |
for (j = 0; j < (int)strlen (argv[i]); j++)
|
|
116 |
argv[i][j] = toupper (argv[i][j]);
|
|
117 |
if (!strcmp (argv[i], "RAW")) {
|
|
118 |
propt.FileType = RAW;
|
|
119 |
continue;
|
|
120 |
} else if (!strcmp (argv[i], "WAV")) {
|
|
121 |
propt.FileType = WAV;
|
|
122 |
continue;
|
|
123 |
} else if (!strcmp (argv[i], "AU")) {
|
|
124 |
propt.FileType = AU;
|
|
125 |
continue;
|
|
126 |
} else {
|
|
127 |
fprintf (stderr, "Unknown output type %s\n", argv[i]);
|
|
128 |
fprintf (stderr, "Supported output types: RAW - AU - WAV\n");
|
|
129 |
exit (-1);
|
|
130 |
}
|
|
131 |
}
|
|
132 |
if (strcmp (argv[i], "-audio") == 0) {
|
|
133 |
i++;
|
|
134 |
for (j = 0; j < strlen (argv[i]); j++)
|
|
135 |
argv[i][j] = toupper (argv[i][j]);
|
|
136 |
if (!strcmp (argv[i], "LIN16")) {
|
|
137 |
propt.Stype = LIN16;
|
|
138 |
continue;
|
|
139 |
} else if (!strcmp (argv[i], "LIN8")) {
|
|
140 |
propt.Stype = LIN8;
|
|
141 |
continue;
|
|
142 |
} else if (!strcmp (argv[i], "ULAW")) {
|
|
143 |
propt.Stype = ULAW;
|
|
144 |
continue;
|
|
145 |
} else if (!strcmp (argv[i], "ALAW")) {
|
|
146 |
propt.Stype = ALAW;
|
|
147 |
continue;
|
|
148 |
}
|
|
149 |
} else {
|
|
150 |
fprintf (stderr, "Unknown option: %s\n", argv[i]);
|
|
151 |
exit (-1);
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
if (!propt.TextFile) {
|
|
156 |
fprintf (stderr, "It's substantial to give a text file by -i <text file>!\n");
|
|
157 |
exit (-1);
|
|
158 |
} else if (!propt.Voice) {
|
|
159 |
fprintf (stderr, "It's substantial to give a voice database by -v <voice>!\n");
|
|
160 |
exit (-1);
|
|
161 |
} else if (!propt.Path) {
|
|
162 |
fprintf (stderr, "It's substantial to give a path for the prosodic stuff by -p <path>!\n");
|
|
163 |
exit (-1);
|
|
164 |
}
|
|
165 |
return (propt);
|
|
166 |
}
|
|
167 |
#endif
|