flite 0.0.3.1-x86-mingw32 → 0.1.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,8 +41,18 @@ typedef struct {
41
41
  const char *name;
42
42
  cst_voice *(*register_)(const char *voxdir);
43
43
  cst_voice **cached;
44
+ #ifdef RBFLITE_WIN32_BINARY_GEM
45
+ const char *dll_name;
46
+ const char *func_name;
47
+ const char *var_name;
48
+ #endif
44
49
  } rbflite_builtin_voice_t;
45
50
 
51
+ #ifdef RBFLITE_WIN32_BINARY_GEM
52
+ cst_voice *rbfile_call_voice_register_func(rbflite_builtin_voice_t *v, const char *voxdir);
53
+ extern rbflite_builtin_voice_t rbflite_builtin_voice_list[];
54
+ #else
46
55
  extern const rbflite_builtin_voice_t rbflite_builtin_voice_list[];
56
+ #endif
47
57
 
48
58
  #endif /* RBFLITE_H */
@@ -0,0 +1,432 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*-
2
+ *
3
+ * ruby-flite - a small speech synthesis module
4
+ * https://github.com/kubo/ruby-flite
5
+ *
6
+ * Copyright (C) 2015 Kubo Takehiro <kubo@jiubao.org>
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without
9
+ * modification, are permitted provided that the following conditions are met:
10
+ *
11
+ * 1. Redistributions of source code must retain the above copyright
12
+ * notice, this list of conditions and the following disclaimer.
13
+ *
14
+ * 2. Redistributions in binary form must reproduce the above
15
+ * copyright notice, this list of conditions and the following
16
+ * disclaimer in the documentation and/or other materials provided
17
+ * with the distribution.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS OR
20
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR CONTRIBUTORS BE
23
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
26
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
29
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ *
31
+ * The views and conclusions contained in the software and documentation
32
+ * are those of the authors and should not be interpreted as representing
33
+ * official policies, either expressed or implied, of the authors.
34
+ */
35
+
36
+ #include <ruby.h>
37
+ #include "rbflite.h"
38
+
39
+ #ifndef STRINGIZE
40
+ #define STRINGIZE(expr) STRINGIZE0(expr)
41
+ #ifndef STRINGIZE0
42
+ #define STRINGIZE0(expr) #expr
43
+ #endif
44
+ #endif
45
+
46
+ #ifdef HAVE_LAME_LAME_H
47
+ #include <lame/lame.h>
48
+ #define HAVE_MP3LAME 1
49
+ #endif
50
+
51
+ #ifdef HAVE_LAME_H
52
+ #include <lame.h>
53
+ #define HAVE_MP3LAME 1
54
+ #endif
55
+
56
+ /* flite.dll */
57
+ typedef cst_val *(*audio_streaming_info_val_t)(const cst_audio_streaming_info *);
58
+ typedef void (*delete_voice_t)(cst_voice *);
59
+ typedef int (*flite_add_lang_t)(const char *, void (*)(cst_voice *), cst_lexicon *(*)());
60
+ typedef int (*flite_feat_remove_t)(cst_features *, const char *);
61
+ typedef void (*flite_feat_set_t)(cst_features *, const char *, const cst_val *);
62
+ typedef const char *(*flite_get_param_string_t)(const cst_features *, const char *, const char *);
63
+ typedef float (*flite_text_to_speech_t)(const char *, cst_voice *, const char *);
64
+ typedef cst_voice *(*flite_voice_load_t)(const char *);
65
+ typedef cst_audio_streaming_info *(*new_audio_streaming_info_t)();
66
+
67
+ /* flite_usenglish.dll */
68
+ typedef void (*usenglish_init_t)(cst_voice *);
69
+
70
+ /* flite_cmulex.dll */
71
+ typedef cst_lexicon *(*cmulex_init_t)(void);
72
+
73
+ /* flite_cmu_grapheme_lang.dll */
74
+ typedef void (*cmu_grapheme_lang_init_t)(cst_voice *);
75
+
76
+ /* flite_cmu_grapheme_lex.dll */
77
+ typedef cst_lexicon *(*cmu_grapheme_lex_init_t)(void);
78
+
79
+ /* flite_cmu_indic_lang.dll */
80
+ typedef void (*cmu_indic_lang_init_t)(cst_voice *);
81
+
82
+ /* flite_cmu_indic_lex.dll */
83
+ typedef cst_lexicon *(*cmu_indic_lex_init_t)(void);
84
+
85
+ #ifdef HAVE_MP3LAME
86
+ /* libmp3lame-0.dll */
87
+ typedef int (*lame_close_t)(lame_global_flags *);
88
+ typedef int (*lame_encode_buffer_t)(lame_global_flags *, const short int *, const short int *, const int , unsigned char *, const int);
89
+ typedef int (*lame_encode_flush_t)(lame_global_flags *, unsigned char *, int);
90
+ typedef lame_global_flags *(*lame_init_t)(void);
91
+ typedef int (*lame_init_params_t)(lame_global_flags *);
92
+ typedef int (*lame_set_bWriteVbrTag_t)(lame_global_flags *, int);
93
+ typedef int (*lame_set_brate_t)(lame_global_flags *, int);
94
+ typedef int (*lame_set_in_samplerate_t)(lame_global_flags *, int);
95
+ typedef int (*lame_set_mode_t)(lame_global_flags *, MPEG_mode);
96
+ typedef int (*lame_set_num_channels_t)(lame_global_flags *, int);
97
+ typedef int (*lame_set_num_samples_t)(lame_global_flags *, unsigned long);
98
+ typedef int (*lame_set_scale_t)(lame_global_flags *, float);
99
+ typedef int (*lame_set_quality_t)(lame_global_flags *, int);
100
+ #endif
101
+
102
+ static HMODULE this_module;
103
+ static CRITICAL_SECTION loading_mutex;
104
+
105
+ #define CALL_FUNC(dll_name, func_name, args, rettype) \
106
+ static func_name##_t func; \
107
+ rettype rv; \
108
+ if (func == NULL) { \
109
+ func = (func_name##_t)load_func(dll_name##_dll(), #dll_name, #func_name); \
110
+ } \
111
+ rv = func args; \
112
+ return rv;
113
+
114
+ #define CALL_FUNC0(dll_name, func_name, args) \
115
+ static func_name##_t func; \
116
+ if (func == NULL) { \
117
+ func = (func_name##_t)load_func(dll_name##_dll(), #dll_name, #func_name); \
118
+ } \
119
+ func args; \
120
+
121
+ #define CALL_LAME_FUNC(func_name, args, rettype) \
122
+ static func_name##_t func; \
123
+ rettype rv; \
124
+ if (func == NULL) { \
125
+ func = (func_name##_t)load_func(libmp3lame_dll(), "libmp3lame-0.dll", #func_name); \
126
+ } \
127
+ rv = func args; \
128
+ return rv;
129
+
130
+ static HMODULE load_module(const char *dll_name)
131
+ {
132
+ static char path[MAX_PATH];
133
+ static char *fname = NULL;
134
+ HMODULE hModule;
135
+
136
+ EnterCriticalSection(&loading_mutex);
137
+ if (fname == NULL) {
138
+ if (GetModuleFileNameA(this_module, path, sizeof(path)) == 0) {
139
+ LeaveCriticalSection(&loading_mutex);
140
+ rb_raise(rb_eLoadError, "Failed to get path of flite.so");
141
+ }
142
+ fname = strrchr(path, '\\') + 1;
143
+ if (fname == NULL) {
144
+ LeaveCriticalSection(&loading_mutex);
145
+ rb_raise(rb_eLoadError, "Failed to directory name of flite.so");
146
+ }
147
+ if (fname - path + strlen(dll_name) + 1 >= MAX_PATH) {
148
+ fname = NULL;
149
+ LeaveCriticalSection(&loading_mutex);
150
+ rb_raise(rb_eLoadError, "flite.so is in a too deep directory.");
151
+ }
152
+ }
153
+ strcpy(fname, dll_name);
154
+ hModule = LoadLibraryA(path);
155
+ if (hModule == NULL) {
156
+ LeaveCriticalSection(&loading_mutex);
157
+ rb_raise(rb_eLoadError, "Failed to load %s: %s", path, rb_w32_strerror(-1));
158
+ }
159
+ LeaveCriticalSection(&loading_mutex);
160
+ return hModule;
161
+ }
162
+
163
+ static FARPROC load_func(HMODULE hModule, const char *dll_name, const char *func_name)
164
+ {
165
+ FARPROC func = GetProcAddress(hModule, func_name);
166
+ if (func == NULL) {
167
+ rb_raise(rb_eLoadError, "Failed to load symbol %s in %s.dll: %s", func_name, dll_name, rb_w32_strerror(-1));
168
+ }
169
+ return func;
170
+ }
171
+
172
+ static HMODULE flite_dll(void)
173
+ {
174
+ static HMODULE hModule = NULL;
175
+ if (hModule == NULL) {
176
+ hModule = load_module("flite.dll");
177
+ }
178
+ return hModule;
179
+ }
180
+
181
+ static HMODULE flite_usenglish_dll(void)
182
+ {
183
+ static HMODULE hModule = NULL;
184
+ if (hModule == NULL) {
185
+ flite_dll();
186
+ hModule = load_module("flite_usenglish.dll");
187
+ }
188
+ return hModule;
189
+ }
190
+
191
+ static HMODULE flite_cmulex_dll(void)
192
+ {
193
+ static HMODULE hModule = NULL;
194
+ if (hModule == NULL) {
195
+ flite_dll();
196
+ hModule = load_module("flite_cmulex.dll");
197
+ }
198
+ return hModule;
199
+ }
200
+
201
+ static HMODULE flite_cmu_grapheme_lang_dll(void)
202
+ {
203
+ static HMODULE hModule = NULL;
204
+ if (hModule == NULL) {
205
+ flite_dll();
206
+ hModule = load_module("flite_cmu_grapheme_lang.dll");
207
+ }
208
+ return hModule;
209
+ }
210
+
211
+ static HMODULE flite_cmu_grapheme_lex_dll(void)
212
+ {
213
+ static HMODULE hModule = NULL;
214
+ if (hModule == NULL) {
215
+ flite_dll();
216
+ hModule = load_module("flite_cmu_grapheme_lex.dll");
217
+ }
218
+ return hModule;
219
+ }
220
+
221
+ static HMODULE flite_cmu_indic_lang_dll(void)
222
+ {
223
+ static HMODULE hModule = NULL;
224
+ if (hModule == NULL) {
225
+ flite_usenglish_dll();
226
+ hModule = load_module("flite_cmu_indic_lang.dll");
227
+ }
228
+ return hModule;
229
+ }
230
+
231
+ static HMODULE flite_cmu_indic_lex_dll(void)
232
+ {
233
+ static HMODULE hModule = NULL;
234
+ if (hModule == NULL) {
235
+ flite_cmu_indic_lang_dll();
236
+ hModule = load_module("flite_cmu_indic_lex.dll");
237
+ }
238
+ return hModule;
239
+ }
240
+
241
+ cst_voice *rbfile_call_voice_register_func(rbflite_builtin_voice_t *v, const char *voxdir)
242
+ {
243
+ HMODULE hModule;
244
+
245
+ flite_usenglish_dll();
246
+ flite_cmulex_dll();
247
+ hModule = load_module(v->dll_name);
248
+ v->cached = (cst_voice **)load_func(hModule, v->dll_name, v->var_name);
249
+ v->register_ = (cst_voice *(*)(const char *))load_func(hModule, v->dll_name, v->func_name);
250
+ return v->register_(voxdir);
251
+ }
252
+
253
+ /* flite.dll */
254
+ cst_val *audio_streaming_info_val(const cst_audio_streaming_info *v)
255
+ {
256
+ CALL_FUNC(flite, audio_streaming_info_val, (v), cst_val *);
257
+ }
258
+
259
+ /* flite.dll */
260
+ void delete_voice(cst_voice *u)
261
+ {
262
+ CALL_FUNC0(flite, delete_voice, (u));
263
+ }
264
+
265
+ /* flite.dll */
266
+ int flite_add_lang(const char *langname, void (*lang_init)(cst_voice *vox), cst_lexicon *(*lex_init)())
267
+ {
268
+ CALL_FUNC(flite, flite_add_lang, (langname, lang_init, lex_init), int);
269
+ }
270
+
271
+ /* flite.dll */
272
+ int flite_feat_remove(cst_features *f, const char *name)
273
+ {
274
+ CALL_FUNC(flite, flite_feat_remove, (f, name), int);
275
+ }
276
+
277
+ /* flite.dll */
278
+ void flite_feat_set(cst_features *f, const char *name, const cst_val *v)
279
+ {
280
+ CALL_FUNC0(flite, flite_feat_set, (f, name, v));
281
+ }
282
+
283
+ /* flite.dll */
284
+ const char *flite_get_param_string(const cst_features *f, const char *name, const char *def)
285
+ {
286
+ CALL_FUNC(flite, flite_get_param_string, (f, name, def), const char *);
287
+ }
288
+
289
+ /* flite.dll */
290
+ float flite_text_to_speech(const char *text, cst_voice *voice, const char *outtype)
291
+ {
292
+ CALL_FUNC(flite, flite_text_to_speech, (text, voice, outtype), float);
293
+ }
294
+
295
+ /* flite.dll */
296
+ cst_voice *flite_voice_load(const char *voice_filename)
297
+ {
298
+ CALL_FUNC(flite, flite_voice_load, (voice_filename), cst_voice *);
299
+ }
300
+
301
+ /* flite.dll */
302
+ cst_audio_streaming_info *new_audio_streaming_info()
303
+ {
304
+ CALL_FUNC(flite, new_audio_streaming_info, (), cst_audio_streaming_info *);
305
+ }
306
+
307
+ /* flite_usenglish.dll */
308
+ void usenglish_init(cst_voice *v)
309
+ {
310
+ CALL_FUNC0(flite_usenglish, usenglish_init, (v));
311
+ }
312
+
313
+ /* flite_cmulex.dll */
314
+ cst_lexicon *cmulex_init(void)
315
+ {
316
+ CALL_FUNC(flite_cmulex, cmulex_init, (), cst_lexicon *);
317
+ }
318
+
319
+ /* flite_cmu_grapheme_lang.dll */
320
+ void cmu_grapheme_lang_init(cst_voice *v)
321
+ {
322
+ CALL_FUNC0(flite_cmu_grapheme_lang, cmu_grapheme_lang_init, (v));
323
+ }
324
+
325
+ /* flite_cmu_grapheme_lex.dll */
326
+ cst_lexicon *cmu_grapheme_lex_init(void)
327
+ {
328
+ CALL_FUNC(flite_cmu_grapheme_lex, cmu_grapheme_lex_init, (), cst_lexicon *);
329
+ }
330
+
331
+ /* flite_cmu_indic_lang.dll */
332
+ void cmu_indic_lang_init(cst_voice *v)
333
+ {
334
+ CALL_FUNC0(flite_cmu_indic_lang, cmu_indic_lang_init, (v));
335
+ }
336
+
337
+ /* flite_cmu_indic_lex.dll */
338
+ cst_lexicon *cmu_indic_lex_init(void)
339
+ {
340
+ CALL_FUNC(flite_cmu_indic_lex, cmu_indic_lex_init, (), cst_lexicon *);
341
+ }
342
+
343
+ #ifdef HAVE_MP3LAME
344
+ static HMODULE libmp3lame_dll(void)
345
+ {
346
+ static HMODULE hModule = NULL;
347
+ if (hModule == NULL) {
348
+ hModule = load_module("libmp3lame-0.dll");
349
+ }
350
+ return hModule;
351
+ }
352
+
353
+ int lame_close(lame_global_flags *gf)
354
+ {
355
+ CALL_LAME_FUNC(lame_close, (gf), int);
356
+ }
357
+
358
+ int lame_encode_buffer(lame_global_flags *gf, const short int *buffer_l, const short int *buffer_r, const int nsamples, unsigned char *mp3buf, const int mp3buf_size)
359
+ {
360
+ CALL_LAME_FUNC(lame_encode_buffer, (gf, buffer_l, buffer_r, nsamples, mp3buf, mp3buf_size), int);
361
+ }
362
+
363
+ int lame_encode_flush(lame_global_flags *gf, unsigned char *mp3buf, int size)
364
+ {
365
+ CALL_LAME_FUNC(lame_encode_flush, (gf, mp3buf, size), int);
366
+ }
367
+
368
+ lame_global_flags *lame_init(void)
369
+ {
370
+ CALL_LAME_FUNC(lame_init, (), lame_global_flags *);
371
+ }
372
+
373
+ int lame_init_params(lame_global_flags *gf)
374
+ {
375
+ CALL_LAME_FUNC(lame_init_params, (gf), int);
376
+ }
377
+
378
+ int lame_set_bWriteVbrTag(lame_global_flags *gf, int bWriteVbrTag)
379
+ {
380
+ CALL_LAME_FUNC(lame_set_bWriteVbrTag, (gf, bWriteVbrTag), int);
381
+ }
382
+
383
+ int lame_set_brate(lame_global_flags *gf, int brate)
384
+ {
385
+ CALL_LAME_FUNC(lame_set_brate, (gf, brate), int);
386
+ }
387
+
388
+ int lame_set_in_samplerate(lame_global_flags *gf, int in_samplerate)
389
+ {
390
+ CALL_LAME_FUNC(lame_set_in_samplerate, (gf, in_samplerate), int);
391
+ }
392
+
393
+ int lame_set_mode(lame_global_flags *gf, MPEG_mode mode)
394
+ {
395
+ CALL_LAME_FUNC(lame_set_mode, (gf, mode), int);
396
+ }
397
+
398
+ int lame_set_num_channels(lame_global_flags *gf, int num_channels)
399
+ {
400
+ CALL_LAME_FUNC(lame_set_num_channels, (gf, num_channels), int);
401
+ }
402
+
403
+ int lame_set_num_samples(lame_global_flags *gf, unsigned long num_samples)
404
+ {
405
+ CALL_LAME_FUNC(lame_set_num_samples, (gf, num_samples), int);
406
+ }
407
+
408
+ int lame_set_scale(lame_global_flags *gf, float scale)
409
+ {
410
+ CALL_LAME_FUNC(lame_set_scale, (gf, scale), int);
411
+ }
412
+
413
+ int lame_set_quality(lame_global_flags *gf, int quality)
414
+ {
415
+ CALL_LAME_FUNC(lame_set_quality, (gf, quality), int);
416
+ }
417
+ #endif
418
+
419
+ __declspec(dllexport)
420
+ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
421
+ {
422
+ switch (fdwReason) {
423
+ case DLL_PROCESS_ATTACH:
424
+ this_module = hinstDLL;
425
+ InitializeCriticalSection(&loading_mutex);
426
+ break;
427
+ case DLL_PROCESS_DETACH:
428
+ DeleteCriticalSection(&loading_mutex);
429
+ break;
430
+ }
431
+ return TRUE;
432
+ }
@@ -15,10 +15,10 @@ Gem::Specification.new do |spec|
15
15
  spec.version = Flite::VERSION
16
16
  spec.authors = ["Kubo Takehiro"]
17
17
  spec.email = ["kubo@jiubao.org"]
18
- spec.extensions = ["ext/flite/extconf.rb"] if gem_platform == Gem::Platform::RUBY
19
18
  spec.summary = %q{a small speech synthesis library}
20
19
  spec.description = <<EOS
21
- Ruby-flite is a small speech synthesis library using CMU flite[http://cmuflite.org].
20
+ Ruby-flite is a small speech synthesis library for ruby using
21
+ CMU flite[http://cmuflite.org].
22
22
 
23
23
  CMU Flite (festival-lite) is a small, fast run-time synthesis engine
24
24
  developed at CMU and primarily designed for small embedded machines
@@ -34,7 +34,11 @@ EOS
34
34
  files.delete('build.bat')
35
35
  files.delete('.gitignore')
36
36
  if gem_platform == 'current'
37
- files << 'lib/flite_200.so' << 'lib/flite_210.so'
37
+ files += Dir.glob('lib/flite_*.so')
38
+ files += Dir.glob('lib/flite*.dll')
39
+ files << 'lib/libmp3lame-0.dll'
40
+ else
41
+ spec.extensions = ["ext/flite/extconf.rb"]
38
42
  end
39
43
  spec.files = files
40
44
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }