From b8378c2667f5a2b924084358f92291dfda346c23 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sat, 12 Dec 2015 12:29:48 +0000 Subject: [PATCH] Expose the CompileMbrola function via a new espeak_ng.h API. --- .gitignore | 6 ++-- src/espeakedit.cpp | 7 ++-- src/include/espeak-ng/espeak_ng.h | 53 +++++++++++++++++++++++++++++++ src/libespeak-ng/compiledata.c | 14 ++++---- 4 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 src/include/espeak-ng/espeak_ng.h diff --git a/.gitignore b/.gitignore index 72c7fc0e..eb65a116 100644 --- a/.gitignore +++ b/.gitignore @@ -44,9 +44,9 @@ libespeak-ng.so* # programs platforms/*/espeak-phoneme-data -espeak-ng -espeakedit -speak-ng +src/espeak-ng +src/espeakedit +src/speak-ng # Linux/Source distribution files diff --git a/src/espeakedit.cpp b/src/espeakedit.cpp index 6b937fbf..8c5b7345 100644 --- a/src/espeakedit.cpp +++ b/src/espeakedit.cpp @@ -33,6 +33,8 @@ #include #include "speak_lib.h" +#include "espeak_ng.h" + #include "main.h" #include "speech.h" #include "options.h" @@ -63,7 +65,6 @@ extern void DictionarySort(const char *dictname); extern void init_z(); extern void CompilePhonemeData(void); extern void CompileSampleRate(void); -extern "C" void CompileMbrola(const char *mbrola_file); extern void CompileIntonation(); extern void InitSpectrumDisplay(); extern void InitProsodyDisplay(); @@ -157,7 +158,7 @@ if(argc > 1) fprintf(stderr, "Failed to load default voice\n"); exit(1); } - CompileMbrola(argv[2]); + espeak_ng_CompileMbrolaVoice(argv[2], stdout); } exit(0); } @@ -792,7 +793,7 @@ void MyFrame::OnTools(wxCommandEvent& event) case MENU_COMPILE_MBROLA: { wxString filepath = wxFileSelector(_T("Read Mbrola phonemes file"),path_phsource+_T("/mbrola"),_T(""),_T(""),_T("*"),wxOPEN); - CompileMbrola(filepath.mb_str(wxConvLocal)); + espeak_ng_CompileMbrolaVoice(filepath.mb_str(wxConvLocal), stdout); } break; diff --git a/src/include/espeak-ng/espeak_ng.h b/src/include/espeak-ng/espeak_ng.h new file mode 100644 index 00000000..fe5744bf --- /dev/null +++ b/src/include/espeak-ng/espeak_ng.h @@ -0,0 +1,53 @@ +/* eSpeak NG API. + * + * Copyright (C) 2015 Reece H. Dunn + * + * This file is part of espeak-ng. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef ESPEAK_NG_H +#define ESPEAK_NG_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifdef __WIN32__ +#define ESPEAK_NG_API __declspec(dllexport) +#else +#define ESPEAK_NG_API +#endif + +typedef enum { + /* Success Codes (>= 0) */ + + ENS_OK = 0, + + /* Error Codes (< 0) */ + + ENE_NOT_FOUND = -1, + ENE_WRITE_FAILED = -2, +} espeak_ng_STATUS; + +ESPEAK_NG_API espeak_ng_STATUS +espeak_ng_CompileMbrolaVoice(const char *path, FILE *log); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/libespeak-ng/compiledata.c b/src/libespeak-ng/compiledata.c index a85a75ee..3baf8c13 100644 --- a/src/libespeak-ng/compiledata.c +++ b/src/libespeak-ng/compiledata.c @@ -22,6 +22,7 @@ #include #include "speak_lib.h" +#include "espeak_ng.h" #include "phoneme.h" #include "speech.h" @@ -47,7 +48,7 @@ static unsigned int StringToWord(const char *string) return(word); } -void CompileMbrola(const char *filepath) +espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *filepath, FILE *log) { char *p; FILE *f_in; @@ -70,8 +71,8 @@ void CompileMbrola(const char *filepath) strcpy(buf,filepath); if((f_in = fopen(buf,"r")) == NULL) { - fprintf(stderr, "Can't read: %s\n", filepath); - return; + fprintf(log, "Can't read: %s\n", filepath); + return ENE_NOT_FOUND; } while(fgets(buf,sizeof(phoneme),f_in) != NULL) @@ -116,8 +117,8 @@ void CompileMbrola(const char *filepath) sprintf(buf,"%s/mbrola_ph/%s_phtrans",path_home,mbrola_voice); if((f_out = fopen(buf,"wb")) == NULL) { - fprintf(stderr, "Can't write to: %s\n", buf); - return; + fprintf(log, "Can't write to: %s\n", buf); + return ENE_WRITE_FAILED; } data[count].name = 0; // list terminator @@ -129,5 +130,6 @@ void CompileMbrola(const char *filepath) Write4Bytes(f_out, *pw); } fclose(f_out); - fprintf(stdout, "Mbrola translation file: %d phonemes", count); + fprintf(log, "Mbrola translation file: %s -- %d phonemes\n", buf, count); + return ENS_OK; }