Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/cst_cg.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "cst_wave.h"
#include "cst_audio.h"
#include "cst_synth.h" /* for dur_stat */
#include "mimic.h"

typedef struct cst_cg_db_struct {
/* Please do not change this structure, but if you do only add things
Expand Down Expand Up @@ -135,8 +136,7 @@ cst_wave *mlsa_resynthesis(const cst_track *t,
cst_audio_streaming_info *asc);
cst_track *mlpg(const cst_track *param_track, cst_cg_db *cg_db);

cst_voice *cst_cg_load_voice(const char *voxdir,
const cst_lang lang_table[]);
cst_voice *cst_cg_load_voice(mimic_context *ctx, const char *voxdir);
int cst_cg_dump_voice(const cst_voice *v, const cst_string *filename);

#endif
21 changes: 12 additions & 9 deletions include/cst_plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,32 @@
#ifndef include_cst_plugins_h
#define include_cst_plugins_h
#include "mimic_core_config.h"

struct mimic_context_s;
typedef struct mimic_context_s mimic_context;

#ifdef MIMIC_ENABLE_PLUGINS
typedef struct mimic_plugin_s
{
char *name;
int version;
void (*mimic_init)(void);
void (*mimic_exit)(void);
void (*mimic_init)(mimic_context *ctx);
void (*mimic_exit)(mimic_context *ctx);
} mimic_plugin_t;

typedef struct mimic_plugin_handler_s
{
void *handle;
mimic_plugin_t* plugin;
mimic_plugin_t *plugin;
} mimic_plugin_handler_t;

mimic_plugin_handler_t* mimic_plugin_load(const char *filename);
int mimic_plugin_unload(mimic_plugin_handler_t *plugin);
extern mimic_plugin_handler_t** mimic_plugins;

mimic_plugin_handler_t* mimic_plugin_load(mimic_context *ctx, const char *filename);
int mimic_plugin_unload(mimic_context *ctx, mimic_plugin_handler_t *plugin);

#endif


int mimic_plugins_init();
void mimic_plugins_exit();
int mimic_plugins_init(mimic_context *ctx);
void mimic_plugins_exit(mimic_context *ctx);

#endif /*header */
39 changes: 26 additions & 13 deletions include/mimic.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,41 @@ extern "C" {
#include "cst_tokenstream.h"
#include "cst_plugins.h"

MIMIC_CORE_PUBLIC extern cst_val *mimic_voice_list;
extern cst_lang mimic_lang_list[20];
typedef struct mimic_context_s {
uint16_t version;
cst_voice **voices;
cst_lang **languages;
mimic_plugin_handler_t **plugins;
uint32_t num_voices;
uint32_t voices_size;
uint32_t num_languages;
uint32_t languages_size;
cst_voice *voice_selected;
} mimic_context;

/* Public functions */
MIMIC_CORE_PUBLIC int mimic_core_init();
MIMIC_CORE_PUBLIC int mimic_core_exit();
MIMIC_CORE_PUBLIC mimic_context *mimic_core_init();
MIMIC_CORE_PUBLIC int mimic_core_exit(mimic_context *ctx);
MIMIC_CORE_PUBLIC mimic_context *mimic_core_init_no_plugins();
MIMIC_CORE_PUBLIC int mimic_core_exit_no_plugins(mimic_context *ctx);

/* General top level functions */
MIMIC_CORE_PUBLIC const cst_lang *mimic_lang_select(const char *lang);
MIMIC_CORE_PUBLIC cst_voice *mimic_voice_select(const char *name);
MIMIC_CORE_PUBLIC cst_voice *mimic_voice_load(const char *voice_filename);
MIMIC_CORE_PUBLIC const cst_lang *mimic_lang_select(mimic_context *ctx, const char *lang);
MIMIC_CORE_PUBLIC cst_voice *mimic_voice_select(mimic_context *ctx, const char *name);
MIMIC_CORE_PUBLIC cst_voice *mimic_voice_load(mimic_context *ctx, const char *filename);
MIMIC_CORE_PUBLIC int mimic_voice_dump(cst_voice *voice, const char *voice_filename);
MIMIC_CORE_PUBLIC int mimic_file_to_speech(const char *filename, cst_voice *voice,
const char *outtype, float *dur);
MIMIC_CORE_PUBLIC int mimic_text_to_speech(const char *text, cst_voice *voice,
const char *outtype, float *dur);
MIMIC_CORE_PUBLIC int mimic_phones_to_speech(const char *text, cst_voice *voice,
const char *outtype, float *dur);
MIMIC_CORE_PUBLIC int mimic_ssml_file_to_speech(const char *filename, cst_voice *voice,
const char *outtype, float *dur);
MIMIC_CORE_PUBLIC int mimic_ssml_text_to_speech(const char *text, cst_voice *voice,
const char *outtype, float *dur);
MIMIC_CORE_PUBLIC int mimic_ssml_file_to_speech(
mimic_context *ctx,const char *filename, cst_voice *voice,
const char *outtype, float *dur);
MIMIC_CORE_PUBLIC int mimic_ssml_text_to_speech(
mimic_context *ctx, const char *text, cst_voice *voice,
const char *outtype, float *dur);
MIMIC_CORE_PUBLIC int mimic_voice_add_lex_addenda(cst_voice *v, const cst_string *lexfile);

/* Lower lever user functions */
Expand Down Expand Up @@ -132,8 +145,8 @@ MIMIC_CORE_PUBLIC int mimic_voice_add_lex_addenda(cst_voice *v, const cst_string

/* These functions are *not* thread-safe, they are designed to be called */
/* before the initial synthesis occurs */
MIMIC_CORE_PUBLIC int mimic_add_voice(cst_voice *voice);
MIMIC_CORE_PUBLIC int mimic_add_lang(const char *langname,
MIMIC_CORE_PUBLIC int mimic_voice_add(mimic_context *ctx, cst_voice *voice);
MIMIC_CORE_PUBLIC int mimic_lang_add(mimic_context *ctx, const char *langname,
void (*lang_init) (cst_voice *vox),
cst_lexicon *(*lex_init) ());
/* These are init functions for generic grapheme based voices */
Expand Down
40 changes: 17 additions & 23 deletions main/mimic_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ BOOL WINAPI windows_signal_handler(DWORD signum)
return FALSE;
}
#else
void sigint_handler(int signum)
static void sigint_handler(int signum)
{
mimic_audio_shutdown(signum);
}
Expand Down Expand Up @@ -118,19 +118,16 @@ static void mimic_usage()
exit(0);
}

static void mimic_voice_list_print(void)
static void mimic_voice_list_print(mimic_context *ctx)
{
cst_voice *voice;
const cst_val *v;
size_t i;

printf("Voices available: ");
for (v = mimic_voice_list; v; v = val_cdr(v))
for (i = 0; i < ctx->num_voices;i++)
{
voice = val_voice(val_car(v));
printf("%s ", voice->name);
printf("%s ", ctx->voices[i]->name);
}
printf("\n");

return;
}

Expand Down Expand Up @@ -234,14 +231,14 @@ int main(int argc, char **argv)
ssml_mode = FALSE;
extra_feats = new_features();

mimic_core_init();
mimic_context *ctx = mimic_core_init();

for (i = 1; i < argc; i++)
{
if (cst_streq(argv[i], "--version"))
{
mimic_version();
mimic_core_exit();
mimic_core_exit(ctx);
return 1;
}
else if (cst_streq(argv[i], "-h") || cst_streq(argv[i], "--help")
Expand All @@ -251,8 +248,9 @@ int main(int argc, char **argv)
mimic_verbose = TRUE;
else if (cst_streq(argv[i], "-lv"))
{
mimic_voice_list_print();
mimic_voice_list_print(ctx);
delete_features(extra_feats);
mimic_core_exit(ctx);
exit(0);
}
else if (cst_streq(argv[i], "-l"))
Expand All @@ -269,7 +267,7 @@ int main(int argc, char **argv)
}
else if ((cst_streq(argv[i], "-voice")) && (i + 1 < argc))
{
desired_voice = mimic_voice_select(argv[i + 1]);
desired_voice = mimic_voice_select(ctx, argv[i + 1]);
i++;
}
else if ((cst_streq(argv[i], "-add_lex")) && (i + 1 < argc))
Expand Down Expand Up @@ -361,14 +359,14 @@ int main(int argc, char **argv)

if (filename == NULL)
filename = "-"; /* stdin */
if (desired_voice == 0)
desired_voice = mimic_voice_select(NULL);
if (desired_voice == NULL)
desired_voice = mimic_voice_select(ctx, NULL);

if (desired_voice == 0)
if (desired_voice == NULL)
{
fprintf(stderr, "No voice given and no voice precompiled\n");
delete_features(extra_feats);
mimic_core_exit();
mimic_core_exit(ctx);
return 1;
}
v = desired_voice;
Expand Down Expand Up @@ -409,14 +407,14 @@ int main(int argc, char **argv)
else if ((strchr(filename, ' ') && !explicit_filename) || explicit_text)
{
if (ssml_mode)
err = mimic_ssml_text_to_speech(filename, v, outtype, &durs);
err = mimic_ssml_text_to_speech(ctx, filename, v, outtype, &durs);
else
err = mimic_text_to_speech(filename, v, outtype, &durs);
}
else
{
if (ssml_mode)
err = mimic_ssml_file_to_speech(filename, v, outtype, &durs);
err = mimic_ssml_file_to_speech(ctx, filename, v, outtype, &durs);
else
err = mimic_file_to_speech(filename, v, outtype, &durs);
}
Expand All @@ -434,10 +432,6 @@ int main(int argc, char **argv)
goto loop;

delete_features(extra_feats);
delete_val(mimic_voice_list);
mimic_voice_list = 0;
/* cst_alloc_debug_summary(); */

mimic_core_exit();
mimic_core_exit(ctx);
return 0;
}
6 changes: 3 additions & 3 deletions main/mimicvox_info_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ int main(int argc, char **argv)
"-info Output general info on voice\n"
"set/get features in a mimicvox voice.", args);

mimic_core_init();
mimic_context *ctx = mimic_core_init();

if (!feat_present(args, "-voice"))
{
fprintf(stderr, "no voice specified\n");
exit(-1);
}
voice_name = feat_string(args, "-voice");
v = mimic_voice_load(voice_name);
v = mimic_voice_load(ctx, voice_name);
if (v == NULL)
{
fprintf(stderr, "can't load voice %s\n", voice_name);
Expand Down Expand Up @@ -100,7 +100,7 @@ int main(int argc, char **argv)
printf("%s \"%s\"\n", feat, feat_string(v->features, feat));
}

mimic_core_exit();
mimic_core_exit(ctx);

return 0;

Expand Down
10 changes: 5 additions & 5 deletions main/t2p_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ static cst_utterance *no_wave_synth(cst_utterance *u)
return u;
}

static cst_voice *voice_no_wave(const char *lang_code, const char *dialect,
static cst_voice *voice_no_wave(mimic_context *ctx, const char *lang_code, const char *dialect,
int use_addenda, int use_lexicon)
{
const cst_lang *lang = mimic_lang_select(lang_code);
const cst_lang *lang = mimic_lang_select(ctx, lang_code);
cst_voice *v = new_voice();

v->name = "no_wave_voice";
Expand Down Expand Up @@ -137,8 +137,8 @@ int main(int argc, char **argv)
{
use_lexicon = 0;
}
mimic_core_init();
v = voice_no_wave(lang, dialect, use_addenda, use_lexicon);
mimic_context *ctx = mimic_core_init();
v = voice_no_wave(ctx, lang, dialect, use_addenda, use_lexicon);
if (v == NULL)
{
cst_errmsg("Could not load voice with language '%s' and dialect '%s'\n", lang, dialect == NULL ? "" : dialect);
Expand All @@ -164,6 +164,6 @@ int main(int argc, char **argv)
delete_features(args);
delete_val(files);

mimic_core_exit();
mimic_core_exit(ctx);
return 0;
}
17 changes: 7 additions & 10 deletions src/cg/cst_cg_load_voice.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@
#include "cst_cg_map.h"
#include "cst_alloc.h"

cst_voice *cst_cg_load_voice(const char *filename,
const cst_lang * lang_table)
cst_voice *cst_cg_load_voice(mimic_context *ctx, const char *filename)
{
cst_voice *vox;
cst_lexicon *lex = NULL;
int i, end_of_features;
int end_of_features;
const char *language;
const char *xname;
cst_cg_db *cg_db;
Expand Down Expand Up @@ -109,14 +108,12 @@ cst_voice *cst_cg_load_voice(const char *filename,
language = mimic_get_param_string(vox->features, "language", "");

/* Search Lang table for lang_init() and lex_init(); */
for (i = 0; lang_table[i].lang; i++)
const cst_lang *lang = mimic_lang_select(ctx, language);

if (lang != NULL)
{
if (cst_streq(language, lang_table[i].lang))
{
(lang_table[i].lang_init) (vox);
lex = (lang_table[i].lex_init) ();
break;
}
(lang->lang_init) (vox);
lex = (lang->lex_init) ();
}
if (lex == NULL)
{ /* Language is not supported */
Expand Down
Loading