Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nlite", "nlite\nlite.vcxproj", "{EB0B5264-9BB4-4EE3-B196-A0472DCB32A8}"
ProjectSection(ProjectDependencies) = postProject
{52AD1F16-FE7F-4915-B97C-38E14BD47D9F} = {52AD1F16-FE7F-4915-B97C-38E14BD47D9F}
+ {FBE9021E-5717-4EEE-A3AC-E4516C8A29AD} = {FBE9021E-5717-4EEE-A3AC-E4516C8A29AD}
{5150C843-E70B-4696-8F08-11B900B7F91F} = {5150C843-E70B-4696-8F08-11B900B7F91F}
{B651AE6B-6D20-4612-B7C8-5788FC2ADDB1} = {B651AE6B-6D20-4612-B7C8-5788FC2ADDB1}
{7866D782-163E-45F8-A5D0-ABB124B6DAAC} = {7866D782-163E-45F8-A5D0-ABB124B6DAAC}
--- /dev/null
+Copyright (c) 2009, Nara Institute of Science and Technology, Japan.
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+Neither the name of the Nara Institute of Science and Technology
+(NAIST) nor the names of its contributors may be used to endorse or
+promote products derived from this software without specific prior
+written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+/* ----------------------------------------------------------------- */
+/* The Japanese TTS System "Open JTalk" */
+/* developed by HTS Working Group */
+/* http://open-jtalk.sourceforge.net/ */
+/* ----------------------------------------------------------------- */
+/* */
+/* Copyright (c) 2008-2011 Nagoya Institute of Technology */
+/* Department of Computer Science */
+/* */
+/* All rights reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the following */
+/* conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright */
+/* notice, this list of conditions and the following disclaimer. */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials provided */
+/* with the distribution. */
+/* - Neither the name of the HTS working group nor the names of its */
+/* contributors may be used to endorse or promote products derived */
+/* from this software without specific prior written permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
+/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
+/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
+/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
+/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
+/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
+/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
+/* POSSIBILITY OF SUCH DAMAGE. */
+/* ----------------------------------------------------------------- */
throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
}
+ g_speaker.SynthesisAsync(TEXT("\83e\83X\83g\83R\83\81\83\93\83g"));
-
-
-
+
//\83\81\83b\83Z\81[\83W\83\8b\81[\83v\93o\98^
CMessageLoop theLoop;
_Module.AddMessageLoop(&theLoop);
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
- <IncludePath>$(solutiondir)\nlib;$(solutiondir)\include\WTL\include;$(solutiondir);$(solutiondir)\include;$(solutiondir)\expat;$(IncludePath)</IncludePath>
+ <IncludePath>$(solutiondir)\nlib;$(solutiondir)\include\WTL\include;$(solutiondir);$(solutiondir)\include;$(solutiondir)\expat;$(IncludePath);$(solutiondir)\speaker;$(IncludePath)</IncludePath>
<EmbedManifest>false</EmbedManifest>
<CustomBuildAfterTargets>
</CustomBuildAfterTargets>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-window|Win32'">
<LinkIncremental>true</LinkIncremental>
- <IncludePath>$(solutiondir)\nlib;$(solutiondir)\include\WTL\include;$(solutiondir);$(solutiondir)\include;$(solutiondir)\expat;$(solutiondir)nlib\;$(solutiondir)memorypool\;$(solutiondir)shareCookie\;$(solutiondir);$(IncludePath)</IncludePath>
+ <IncludePath>$(solutiondir)\nlib;$(solutiondir)\include\WTL\include;$(solutiondir);$(solutiondir)\include;$(solutiondir)\expat;$(solutiondir)nlib\;$(solutiondir)memorypool\;$(solutiondir)shareCookie\;$(solutiondir);$(IncludePath);$(solutiondir)\speaker;$(IncludePath)</IncludePath>
<CustomBuildAfterTargets>
</CustomBuildAfterTargets>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
- <IncludePath>$(solutiondir)\nlib;$(solutiondir)\include\WTL\include;$(solutiondir);$(solutiondir)\include;$(solutiondir)\expat;$(WDDK)inc\atl71;$(BOOST);$(IncludePath)</IncludePath>
+ <IncludePath>$(solutiondir)\nlib;$(solutiondir)\include\WTL\include;$(solutiondir);$(solutiondir)\include;$(solutiondir)\expat;$(WDDK)inc\atl71;$(BOOST);$(IncludePath);$(solutiondir)\speaker;$(IncludePath)</IncludePath>
<CustomBuildAfterTargets>
</CustomBuildAfterTargets>
</PropertyGroup>
TCHAR appFolderPath[_MAX_PATH];
CString ncvAppSettingPath;
TCHAR localAppDataPath[_MAX_PATH];
-
+ speaker::ISpeaker &g_speaker = speaker::ISpeaker::GetMeiNormal(TEXT("libs\\Voice\\mei_normal\\"),TEXT("libs\\open_jtalk_dic\\"));
VOID nlite::UnexpectedErrorMessageShow(LPCTSTR headMessage,LPCTSTR summary,UINT line,LPCTSTR fileName,LPCTSTR function){
CString errLogFilePath(nliteProperty.propertySaveFolderPath);
//\83O\83\8d\81[\83o\83\8b\95Ï\90\94
extern const CApplicationInfo * appInfo;
extern CListenerList listenerList;
+ extern speaker::ISpeaker &g_speaker;
extern TCHAR localAppDataPath[];
extern TCHAR appFolderPath[];
extern CString ncvAppSettingPath;
#include <qwerty\windebuger.h>
#include <nlib.h>
#include <nlib_define.h>
+#include <speaker.h>
#include "resource.h"
#pragma comment(lib,"atlthunk.lib")
#pragma comment(lib,"version.lib")
#pragma comment(lib,"Riched20.lib")
-
-
+#pragma comment(lib,"speaker.lib")
+#pragma comment(lib,"open_jtalk_lib.lib")
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
- <Filter Include="ソース ファイル">
- <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
- <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
- </Filter>
<Filter Include="ヘッダー ファイル">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
+ <Filter Include="ソース ファイル">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
</ItemGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
--- /dev/null
+#include "MMD_AgentDammiy.h"
+
+#include <string.h>
+#include <malloc.h>
+
+/* MMDFiles_strdup: strdup */
+char *MMDAgent_pathdup(const char *str)
+{
+ char *buf;
+
+ if(str == NULL)
+ return NULL;
+ buf = (char *) malloc(sizeof(char) * (strlen(str) + 1));
+ strcpy(buf, str);
+
+ return buf;
+}
+
+
+char *MMDAgent_strdup(const char *str)
+{
+ char *buf;
+
+ if(str == NULL)
+ return NULL;
+ buf = (char *) malloc(sizeof(char) * (strlen(str) + 1));
+ strcpy(buf, str);
+
+ return buf;
+}
+
+
+int MMDAgent_strlen(const char *str)
+{
+ if(str == NULL)
+ return 0;
+ else
+ return strlen(str);
+}
--- /dev/null
+#pragma comment
+
+#define MMDAGENT_DIRSEPARATOR '\\'
+
+
+extern char *MMDAgent_pathdup(const char *str);
+
+extern int MMDAgent_strlen(const char *str);
+
+extern char *MMDAgent_strdup(const char *str);
\ No newline at end of file
--- /dev/null
+/* ----------------------------------------------------------------- */
+/* The Toolkit for Building Voice Interaction Systems */
+/* "MMDAgent" developed by MMDAgent Project Team */
+/* http://www.mmdagent.jp/ */
+/* ----------------------------------------------------------------- */
+/* */
+/* Copyright (c) 2009-2011 Nagoya Institute of Technology */
+/* Department of Computer Science */
+/* */
+/* All rights reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the following */
+/* conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright */
+/* notice, this list of conditions and the following disclaimer. */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials provided */
+/* with the distribution. */
+/* - Neither the name of the MMDAgent project team nor the names of */
+/* its contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
+/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
+/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
+/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
+/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
+/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
+/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
+/* POSSIBILITY OF SUCH DAMAGE. */
+/* ----------------------------------------------------------------- */
+
+/* headers */
+
+#include "MMD_AgentDammiy.h"
+#include <math.h>
+#include "mecab.h"
+#include "njd.h"
+#include "jpcommon.h"
+#include "HTS_engine.h"
+
+#include "text2mecab.h"
+#include "mecab2njd.h"
+#include "njd2jpcommon.h"
+
+#include "njd_set_pronunciation.h"
+#include "njd_set_digit.h"
+#include "njd_set_accent_phrase.h"
+#include "njd_set_accent_type.h"
+#include "njd_set_unvoiced_vowel.h"
+#include "njd_set_long_vowel.h"
+
+#include "Open_JTalk.h"
+
+
+/* Open_JTalk::initialize: initialize system */
+void Open_JTalk::initialize()
+{
+ Mecab_initialize(&m_mecab);
+ NJD_initialize(&m_njd);
+ JPCommon_initialize(&m_jpcommon);
+ HTS_Engine_initialize(&m_engine, 3);
+
+ HTS_Engine_set_gamma(&m_engine, OPENJTALK_GAMMA);
+ HTS_Engine_set_log_gain(&m_engine, OPENJTALK_LOGGAIN);
+ HTS_Engine_set_sampling_rate(&m_engine, OPENJTALK_SAMPLINGRATE);
+ HTS_Engine_set_fperiod(&m_engine, OPENJTALK_FPERIOD);
+ HTS_Engine_set_alpha(&m_engine, OPENJTALK_ALPHA);
+ HTS_Engine_set_volume(&m_engine, OPENJTALK_VOLUME);
+ HTS_Engine_set_audio_buff_size(&m_engine, OPENJTALK_AUDIOBUFFSIZE);
+
+ m_f0Shift = OPENJTALK_HALFTONE;
+ m_numModels = 0;
+ m_styleWeights = NULL;
+ m_numStyles = 0;
+}
+
+/* Open_JTalk::clear: free system */
+void Open_JTalk::clear()
+{
+ Mecab_clear(&m_mecab);
+ NJD_clear(&m_njd);
+ JPCommon_clear(&m_jpcommon);
+ HTS_Engine_clear(&m_engine);
+
+ m_f0Shift = 0.0;
+ m_numModels = 0;
+ if (m_styleWeights != NULL)
+ free(m_styleWeights);
+ m_styleWeights = NULL;
+ m_numStyles = 0;
+}
+
+/* Open_JTalk::Open_JTalk: constructor */
+Open_JTalk::Open_JTalk()
+{
+ initialize();
+}
+
+/* Open_JTalk::~Open_JTalk: destructor */
+Open_JTalk::~Open_JTalk()
+{
+ clear();
+}
+
+/* Open_JTalk::load: load dictionary and models */
+bool Open_JTalk::load(const char *dicDir, char **modelDir, int numModels, double *styleWeights, int numStyles)
+{
+ int i, j;
+
+ char buff[2048];
+ char *dn_mecab;
+ char **fn_ws_mcp, **fn_ws_lf0, **fn_ws_lpf;
+ char *fn_gv_switch;
+ char **fn_ts_dur, **fn_ts_mcp, **fn_ts_lf0, **fn_ts_lpf;
+ char **fn_ms_dur, **fn_ms_mcp, **fn_ms_lf0, **fn_ms_lpf;
+ char **fn_ts_gvm, **fn_ts_gvl;
+ char **fn_ms_gvm, **fn_ms_gvl;
+
+ if (dicDir == NULL || modelDir == NULL || numModels <= 0 || styleWeights == NULL || numStyles <= 0)
+ return false;
+ m_numModels = numModels;
+ m_numStyles = numStyles;
+
+ /* set filenames */
+ fn_ws_mcp = (char **) calloc(3, sizeof(char *));
+ fn_ws_lf0 = (char **) calloc(3, sizeof(char *));
+ fn_ws_lpf = (char **) calloc(1, sizeof(char *));
+ fn_ts_dur = (char **) calloc(m_numModels, sizeof(char *));
+ fn_ts_mcp = (char **) calloc(m_numModels, sizeof(char *));
+ fn_ts_lf0 = (char **) calloc(m_numModels, sizeof(char *));
+ fn_ts_lpf = (char **) calloc(m_numModels, sizeof(char *));
+ fn_ms_dur = (char **) calloc(m_numModels, sizeof(char *));
+ fn_ms_mcp = (char **) calloc(m_numModels, sizeof(char *));
+ fn_ms_lf0 = (char **) calloc(m_numModels, sizeof(char *));
+ fn_ms_lpf = (char **) calloc(m_numModels, sizeof(char *));
+ fn_ts_gvm = (char **) calloc(m_numModels, sizeof(char *));
+ fn_ts_gvl = (char **) calloc(m_numModels, sizeof(char *));
+ fn_ms_gvm = (char **) calloc(m_numModels, sizeof(char *));
+ fn_ms_gvl = (char **) calloc(m_numModels, sizeof(char *));
+
+ dn_mecab = MMDAgent_pathdup(dicDir);
+ sprintf(buff, "%s%c%s", modelDir[0], MMDAGENT_DIRSEPARATOR, OPENJTALK_MGCWIN1);
+ fn_ws_mcp[0] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[0], MMDAGENT_DIRSEPARATOR, OPENJTALK_MGCWIN2);
+ fn_ws_mcp[1] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[0], MMDAGENT_DIRSEPARATOR, OPENJTALK_MGCWIN3);
+ fn_ws_mcp[2] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[0], MMDAGENT_DIRSEPARATOR, OPENJTALK_LF0WIN1);
+ fn_ws_lf0[0] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[0], MMDAGENT_DIRSEPARATOR, OPENJTALK_LF0WIN2);
+ fn_ws_lf0[1] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[0], MMDAGENT_DIRSEPARATOR, OPENJTALK_LF0WIN3);
+ fn_ws_lf0[2] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[0], MMDAGENT_DIRSEPARATOR, OPENJTALK_LPFWIN1);
+ fn_ws_lpf[0] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[0], MMDAGENT_DIRSEPARATOR, OPENJTALK_GVSWITCH);
+ fn_gv_switch = MMDAgent_pathdup(buff);
+ for (i = 0; i < m_numModels; i++) {
+ sprintf(buff, "%s%c%s", modelDir[i], MMDAGENT_DIRSEPARATOR, OPENJTALK_DURTREE);
+ fn_ts_dur[i] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[i], MMDAGENT_DIRSEPARATOR, OPENJTALK_MGCTREE);
+ fn_ts_mcp[i] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[i], MMDAGENT_DIRSEPARATOR, OPENJTALK_LF0TREE);
+ fn_ts_lf0[i] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[i], MMDAGENT_DIRSEPARATOR, OPENJTALK_LPFTREE);
+ fn_ts_lpf[i] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[i], MMDAGENT_DIRSEPARATOR, OPENJTALK_DURPDF);
+ fn_ms_dur[i] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[i], MMDAGENT_DIRSEPARATOR, OPENJTALK_MGCPDF);
+ fn_ms_mcp[i] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[i], MMDAGENT_DIRSEPARATOR, OPENJTALK_LF0PDF);
+ fn_ms_lf0[i] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[i], MMDAGENT_DIRSEPARATOR, OPENJTALK_LPFPDF);
+ fn_ms_lpf[i] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[i], MMDAGENT_DIRSEPARATOR, OPENJTALK_MGCGVTREE);
+ fn_ts_gvm[i] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[i], MMDAGENT_DIRSEPARATOR, OPENJTALK_LF0GVTREE);
+ fn_ts_gvl[i] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[i], MMDAGENT_DIRSEPARATOR, OPENJTALK_MGCGVPDF);
+ fn_ms_gvm[i] = MMDAgent_pathdup(buff);
+ sprintf(buff, "%s%c%s", modelDir[i], MMDAGENT_DIRSEPARATOR, OPENJTALK_LF0GVPDF);
+ fn_ms_gvl[i] = MMDAgent_pathdup(buff);
+ }
+
+ /* load */
+ Mecab_load(&m_mecab, dn_mecab);
+ HTS_Engine_load_duration_from_fn(&m_engine, fn_ms_dur, fn_ts_dur, m_numModels);
+ HTS_Engine_load_parameter_from_fn(&m_engine, fn_ms_mcp, fn_ts_mcp, fn_ws_mcp, 0, FALSE, 3, m_numModels);
+ HTS_Engine_load_parameter_from_fn(&m_engine, fn_ms_lf0, fn_ts_lf0, fn_ws_lf0, 1, TRUE, 3, m_numModels);
+ HTS_Engine_load_parameter_from_fn(&m_engine, fn_ms_lpf, fn_ts_lpf, fn_ws_lpf, 2, FALSE, 1, m_numModels);
+ HTS_Engine_load_gv_from_fn(&m_engine, fn_ms_gvm, fn_ts_gvm, 0, m_numModels);
+ HTS_Engine_load_gv_from_fn(&m_engine, fn_ms_gvl, fn_ts_gvl, 1, m_numModels);
+ HTS_Engine_load_gv_switch_from_fn(&m_engine, fn_gv_switch);
+
+ /* free filenames */
+ free(dn_mecab);
+ for (i = 0; i < 3; i++) {
+ free(fn_ws_mcp[i]);
+ free(fn_ws_lf0[i]);
+ }
+ for (i = 0; i < 1; i++) {
+ free(fn_ws_lpf[i]);
+ }
+ free(fn_ws_mcp);
+ free(fn_ws_lf0);
+ free(fn_ws_lpf);
+ free(fn_gv_switch);
+ for (i = 0; i < m_numModels; i++) {
+ free(fn_ts_dur[i]);
+ free(fn_ts_mcp[i]);
+ free(fn_ts_lf0[i]);
+ free(fn_ts_lpf[i]);
+ free(fn_ms_dur[i]);
+ free(fn_ms_mcp[i]);
+ free(fn_ms_lf0[i]);
+ free(fn_ms_lpf[i]);
+ free(fn_ts_gvm[i]);
+ free(fn_ts_gvl[i]);
+ free(fn_ms_gvm[i]);
+ free(fn_ms_gvl[i]);
+ }
+ free(fn_ts_dur);
+ free(fn_ts_mcp);
+ free(fn_ts_lf0);
+ free(fn_ts_lpf);
+ free(fn_ms_dur);
+ free(fn_ms_mcp);
+ free(fn_ms_lf0);
+ free(fn_ms_lpf);
+ free(fn_ts_gvm);
+ free(fn_ts_gvl);
+ free(fn_ms_gvm);
+ free(fn_ms_gvl);
+
+ /* set style interpolation weight */
+ m_styleWeights = (double *) calloc(m_numStyles * (m_numModels * 3 + 4), sizeof(double));
+ for (j = 0; j < m_numStyles * (m_numModels * 3 + 4); j++)
+ m_styleWeights[j] = styleWeights[j];
+
+ setStyle(0);
+ return true;
+}
+
+/* Open_JTalk::prepare: text analysis, decision of state durations, and parameter generation */
+void Open_JTalk::prepare(const char *str)
+{
+ char *buff;
+ char **label_feature = NULL;
+ int label_size = 0;
+ int i;
+ double f;
+
+ if(m_numStyles <= 0)
+ return;
+
+ /* text analysis */
+ HTS_Engine_set_stop_flag(&m_engine, false);
+ buff = (char *) calloc(2 * MMDAgent_strlen(str) + 1, sizeof(char));
+ text2mecab(buff, str);
+ Mecab_analysis(&m_mecab, buff);
+ free(buff);
+ mecab2njd(&m_njd, Mecab_get_feature(&m_mecab), Mecab_get_size(&m_mecab));
+ njd_set_pronunciation(&m_njd);
+ njd_set_digit(&m_njd);
+ njd_set_accent_phrase(&m_njd);
+ njd_set_accent_type(&m_njd);
+ njd_set_unvoiced_vowel(&m_njd);
+ njd_set_long_vowel(&m_njd);
+ njd2jpcommon(&m_jpcommon, &m_njd);
+ JPCommon_make_label(&m_jpcommon);
+ if (JPCommon_get_label_size(&m_jpcommon) > 2) {
+ /* decision of state durations */
+ label_feature = JPCommon_get_label_feature(&m_jpcommon);
+ label_size = JPCommon_get_label_size(&m_jpcommon);
+ HTS_Engine_load_label_from_string_list(&m_engine, &label_feature[1], label_size - 1); /* skip first silence */
+ HTS_Engine_create_sstream(&m_engine);
+ /* parameter generation */
+ if (m_f0Shift != 0.0) {
+ for (i = 0; i < HTS_Engine_get_total_state(&m_engine); i++) {
+ f = HTS_Engine_get_state_mean(&m_engine, 1, i, 0);
+ f += m_f0Shift * log(2.0) / 12;
+ if (f < OPENJTALK_MINLF0VAL)
+ f = OPENJTALK_MINLF0VAL;
+ HTS_Engine_set_state_mean(&m_engine, 1, i, 0, f);
+ }
+ }
+ HTS_Engine_create_pstream(&m_engine);
+ }
+}
+
+/* Open_JTalk::getPhonemeSequence: get phoneme sequence */
+void Open_JTalk::getPhonemeSequence(char *str)
+{
+ int i, j, k;
+ int size;
+ char **feature;
+ int nstate;
+ int fperiod;
+ int sampling_rate;
+ char *ch, *start, *end;
+
+ strcpy(str, "");
+
+ if(m_numStyles <= 0)
+ return;
+
+ size = JPCommon_get_label_size(&m_jpcommon);
+ feature = JPCommon_get_label_feature(&m_jpcommon);
+ nstate = HTS_Engine_get_nstate(&m_engine);
+ fperiod = HTS_Engine_get_fperiod(&m_engine);
+ sampling_rate = HTS_Engine_get_sampling_rate(&m_engine);
+
+ if (size <= 2)
+ return;
+
+ /* skip first and final silence */
+ size -= 2;
+ feature = &feature[1];
+
+ for (i = 0; i < size; i++) {
+ if (i > 0)
+ strcat(str, ",");
+ /* get phoneme from full-context label */
+ start = strchr(feature[i], '-');
+ end = strchr(feature[i], '+');
+ if (start != NULL && end != NULL) {
+ for (ch = start + 1; ch != end; ch++)
+ sprintf(str, "%s%c", str, *ch);
+ } else {
+ strcat(str, feature[i]);
+ }
+ /* get ms */
+ for (j = 0, k = 0; j < nstate; j++)
+ k += (HTS_Engine_get_state_duration(&m_engine, i * nstate + j) * fperiod * 1000) / sampling_rate;
+ sprintf(str, "%s,%d", str, k);
+ }
+}
+
+/* Open_JTalk::synthesis: speech synthesis */
+void Open_JTalk::synthesis()
+{
+ if(m_numStyles <= 0)
+ return;
+ if (JPCommon_get_label_size(&m_jpcommon) > 2) {
+ HTS_Engine_create_gstream(&m_engine);
+ HTS_Engine_refresh(&m_engine);
+ }
+ JPCommon_refresh(&m_jpcommon);
+ NJD_refresh(&m_njd);
+ Mecab_refresh(&m_mecab);
+}
+
+/* Open_JTalk::stop: stop speech synthesis */
+void Open_JTalk::stop()
+{
+ if(m_numStyles <= 0)
+ return;
+ HTS_Engine_set_stop_flag(&m_engine, TRUE);
+}
+
+/* Open_JTalk::setStyle: set style interpolation weight */
+bool Open_JTalk::setStyle(int val)
+{
+ int i, index;
+ double f;
+
+ if (m_numStyles <= 0 || m_styleWeights == NULL || val < 0 || val >= m_numStyles)
+ return false;
+
+ index = val * (m_numModels * 3 + 4);
+ for (i = 0; i < m_numModels; i++)
+ HTS_Engine_set_parameter_interpolation_weight(&m_engine, 0, i, m_styleWeights[index + m_numModels * 0 + i]);
+ for (i = 0; i < m_numModels; i++)
+ HTS_Engine_set_parameter_interpolation_weight(&m_engine, 1, i, m_styleWeights[index + m_numModels * 1 + i]);
+ for (i = 0; i < m_numModels; i++)
+ HTS_Engine_set_duration_interpolation_weight(&m_engine, i, m_styleWeights[index + m_numModels * 2 + i]);
+
+ /* speed */
+ f = OPENJTALK_FPERIOD / m_styleWeights[index + m_numModels * 3 + 0];
+ if(f > OPENJTALK_MAXFPERIOD)
+ HTS_Engine_set_fperiod(&m_engine, OPENJTALK_MAXFPERIOD);
+ else if(f < OPENJTALK_MINFPERIOD)
+ HTS_Engine_set_fperiod(&m_engine, OPENJTALK_MINFPERIOD);
+ else
+ HTS_Engine_set_fperiod(&m_engine, (int) f);
+
+ /* pitch */
+ f = m_styleWeights[index + m_numModels * 3 + 1];
+ if(f > OPENJTALK_MAXHALFTONE)
+ m_f0Shift = OPENJTALK_MAXHALFTONE;
+ else if(f < OPENJTALK_MINHALFTONE)
+ m_f0Shift = OPENJTALK_MINHALFTONE;
+ else
+ m_f0Shift = f;
+
+ /* alpha */
+ f = m_styleWeights[index + m_numModels * 3 + 2];
+ if(f > OPENJTALK_MAXALPHA)
+ HTS_Engine_set_alpha(&m_engine, OPENJTALK_MAXALPHA);
+ else if(f < OPENJTALK_MINALPHA)
+ HTS_Engine_set_alpha(&m_engine, OPENJTALK_MINALPHA);
+ else
+ HTS_Engine_set_alpha(&m_engine, f);
+
+ /* volume */
+ f = m_styleWeights[index + m_numModels * 3 + 3];
+ if(f > OPENJTALK_MAXVOLUME)
+ HTS_Engine_set_volume(&m_engine, OPENJTALK_MAXVOLUME);
+ else if(f < OPENJTALK_MINVOLUME)
+ HTS_Engine_set_volume(&m_engine, OPENJTALK_MINVOLUME);
+ else
+ HTS_Engine_set_volume(&m_engine, f);
+
+ return true;
+}
--- /dev/null
+/* ----------------------------------------------------------------- */
+/* The Toolkit for Building Voice Interaction Systems */
+/* "MMDAgent" developed by MMDAgent Project Team */
+/* http://www.mmdagent.jp/ */
+/* ----------------------------------------------------------------- */
+/* */
+/* Copyright (c) 2009-2011 Nagoya Institute of Technology */
+/* Department of Computer Science */
+/* */
+/* All rights reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the following */
+/* conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright */
+/* notice, this list of conditions and the following disclaimer. */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials provided */
+/* with the distribution. */
+/* - Neither the name of the MMDAgent project team nor the names of */
+/* its contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
+/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
+/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
+/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
+/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
+/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
+/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
+/* POSSIBILITY OF SUCH DAMAGE. */
+/* ----------------------------------------------------------------- */
+
+/* definitions */
+
+#define OPENJTALK_MGCWIN1 "mgc.win1"
+#define OPENJTALK_MGCWIN2 "mgc.win2"
+#define OPENJTALK_MGCWIN3 "mgc.win3"
+#define OPENJTALK_LF0WIN1 "lf0.win1"
+#define OPENJTALK_LF0WIN2 "lf0.win2"
+#define OPENJTALK_LF0WIN3 "lf0.win3"
+#define OPENJTALK_LPFWIN1 "lpf.win1"
+#define OPENJTALK_GVSWITCH "gv-switch.inf"
+#define OPENJTALK_DURTREE "tree-dur.inf"
+#define OPENJTALK_MGCTREE "tree-mgc.inf"
+#define OPENJTALK_LF0TREE "tree-lf0.inf"
+#define OPENJTALK_LPFTREE "tree-lpf.inf"
+#define OPENJTALK_DURPDF "dur.pdf"
+#define OPENJTALK_MGCPDF "mgc.pdf"
+#define OPENJTALK_LF0PDF "lf0.pdf"
+#define OPENJTALK_LPFPDF "lpf.pdf"
+#define OPENJTALK_MGCGVTREE "tree-gv-mgc.inf"
+#define OPENJTALK_LF0GVTREE "tree-gv-lf0.inf"
+#define OPENJTALK_MGCGVPDF "gv-mgc.pdf"
+#define OPENJTALK_LF0GVPDF "gv-lf0.pdf"
+
+#define OPENJTALK_MINLF0VAL log(10.0)
+
+#define OPENJTALK_GAMMA 0
+#define OPENJTALK_LOGGAIN false
+#define OPENJTALK_SAMPLINGRATE 48000
+#define OPENJTALK_FPERIOD 240
+#define OPENJTALK_HALFTONE 0.0
+#define OPENJTALK_ALPHA 0.55
+#define OPENJTALK_VOLUME 1.0
+#define OPENJTALK_AUDIOBUFFSIZE 4800
+
+#define OPENJTALK_MAXFPERIOD 48000
+#define OPENJTALK_MINFPERIOD 1
+#define OPENJTALK_MAXHALFTONE 24.0
+#define OPENJTALK_MINHALFTONE -24.0
+#define OPENJTALK_MAXALPHA 1.0
+#define OPENJTALK_MINALPHA 0.0
+#define OPENJTALK_MAXVOLUME 10.0
+#define OPENJTALK_MINVOLUME 0.0
+
+/* Open_JTalk: Japanese TTS system */
+class Open_JTalk
+{
+private:
+
+ Mecab m_mecab; /* text analyzer */
+ NJD m_njd; /* container for Naist Japanese Dictionary */
+ JPCommon m_jpcommon; /* dictionary-independent container */
+ HTS_Engine m_engine; /* speech synthesizer */
+
+ double m_f0Shift; /* pitch parameter */
+ int m_numModels; /* number of models */
+ double *m_styleWeights; /* weights of speaking styles */
+ int m_numStyles; /* number of speaking styles */
+
+ /* initialize: initialize system */
+ void initialize();
+
+ /* clear: free system */
+ void clear();
+
+public:
+
+ /* Open_JTalk: constructor */
+ Open_JTalk();
+
+ /* ~Open_JTalk: destructor */
+ ~Open_JTalk();
+
+ /* load: load dictionary and models */
+ bool load(const char *dicDir, char **modelDir, int numModels, double *styleWeights, int numStyles);
+
+ /* prepare: text analysis, decision of state durations, and parameter generation */
+ void prepare(const char *str);
+
+ /* getPhonemeSequence: get phoneme sequence */
+ void getPhonemeSequence(char *str);
+
+ /* synthesis: speech synthesis */
+ void synthesis();
+
+ /* stop: stop speech synthesis */
+ void stop();
+
+ /* setStyle: set style interpolation weight */
+ bool setStyle(int val);
+};
--- /dev/null
+/* ----------------------------------------------------------------- */
+/* The Toolkit for Building Voice Interaction Systems */
+/* "MMDAgent" developed by MMDAgent Project Team */
+/* http://www.mmdagent.jp/ */
+/* ----------------------------------------------------------------- */
+/* */
+/* Copyright (c) 2009-2011 Nagoya Institute of Technology */
+/* Department of Computer Science */
+/* */
+/* All rights reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the following */
+/* conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright */
+/* notice, this list of conditions and the following disclaimer. */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials provided */
+/* with the distribution. */
+/* - Neither the name of the MMDAgent project team nor the names of */
+/* its contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
+/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
+/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
+/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
+/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
+/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
+/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
+/* POSSIBILITY OF SUCH DAMAGE. */
+/* ----------------------------------------------------------------- */
+
+/* headers */
+
+#include "MMD_AgentDammiy.h"
+
+#include "mecab.h"
+#include "njd.h"
+#include "jpcommon.h"
+#include "HTS_engine.h"
+
+#include "text2mecab.h"
+#include "mecab2njd.h"
+#include "njd2jpcommon.h"
+
+#include "njd_set_pronunciation.h"
+#include "njd_set_digit.h"
+#include "njd_set_accent_phrase.h"
+#include "njd_set_accent_type.h"
+#include "njd_set_unvoiced_vowel.h"
+#include "njd_set_long_vowel.h"
+
+#include "Open_JTalk.h"
+#include "Open_JTalk_Thread.h"
+#include "Open_JTalk_Manager.h"
+
+/* Open_JTalk_Event_initialize: initialize input message buffer */
+static void Open_JTalk_Event_initialize(Open_JTalk_Event *e, const char *str)
+{
+ if (str != NULL)
+ e->event = MMDAgent_strdup(str);
+ else
+ e->event = NULL;
+ e->next = NULL;
+}
+
+/* Open_JTalk_Event_clear: free input message buffer */
+static void Open_JTalk_Event_clear(Open_JTalk_Event *e)
+{
+ if (e->event != NULL)
+ free(e->event);
+ Open_JTalk_Event_initialize(e, NULL);
+}
+
+/* Open_JTalk_EventQueue_initialize: initialize queue */
+static void Open_JTalk_EventQueue_initialize(Open_JTalk_EventQueue *q)
+{
+ q->head = NULL;
+ q->tail = NULL;
+}
+
+/* Open_JTalk_EventQueue_clear: free queue */
+static void Open_JTalk_EventQueue_clear(Open_JTalk_EventQueue *q)
+{
+ Open_JTalk_Event *tmp1, *tmp2;
+
+ for (tmp1 = q->head; tmp1 != NULL; tmp1 = tmp2) {
+ tmp2 = tmp1->next;
+ Open_JTalk_Event_clear(tmp1);
+ free(tmp1);
+ }
+ Open_JTalk_EventQueue_initialize(q);
+}
+
+/* Open_JTalk_EventQueue_enqueue: enqueue */
+static void Open_JTalk_EventQueue_enqueue(Open_JTalk_EventQueue *q, const char *str)
+{
+ if(MMDAgent_strlen(str) <= 0)
+ return;
+
+ if (q->tail == NULL) {
+ q->tail = (Open_JTalk_Event *) calloc(1, sizeof (Open_JTalk_Event));
+ Open_JTalk_Event_initialize(q->tail, str);
+ q->head = q->tail;
+ } else {
+ q->tail->next = (Open_JTalk_Event *) calloc(1, sizeof (Open_JTalk_Event));
+ Open_JTalk_Event_initialize(q->tail->next, str);
+ q->tail = q->tail->next;
+ }
+}
+
+/* Open_JTalk_EventQueue_dequeue: dequeue */
+static void Open_JTalk_EventQueue_dequeue(Open_JTalk_EventQueue *q, char **str)
+{
+ Open_JTalk_Event *tmp;
+
+ if (q->head == NULL) {
+ *str = NULL;
+ return;
+ }
+ *str = MMDAgent_strdup(q->head->event);
+
+ tmp = q->head->next;
+ Open_JTalk_Event_clear(q->head);
+ free(q->head);
+ q->head = tmp;
+ if (tmp == NULL)
+ q->tail = NULL;
+}
+
+/* mainThread: main thread */
+static void mainThread(void *param)
+{
+ Open_JTalk_Manager *open_jtalk_manager = (Open_JTalk_Manager *) param;
+ open_jtalk_manager->run();
+}
+
+/* Open_JTalk_Manager::initialize: initialize */
+void Open_JTalk_Manager::initialize()
+{
+ m_mmdagent = NULL;
+
+ m_mutex = NULL;
+ m_cond = NULL;
+ m_thread = -1;
+
+ m_count = 0;
+
+ m_list = NULL;
+
+ m_dicDir = NULL;
+ m_config = NULL;
+
+ m_kill = false;
+
+ Open_JTalk_EventQueue_initialize(&m_bufferQueue);
+}
+
+/* Open_JTalk_Manager::clear clear */
+void Open_JTalk_Manager::clear()
+{
+ Open_JTalk_Link *tmp1, *tmp2;
+
+ m_kill = true;
+
+ /* stop and release all thread */
+ for(tmp1 = m_list; tmp1; tmp1 = tmp2) {
+ tmp2 = tmp1->next;
+ tmp1->open_jtalk_thread.stopAndRelease();
+ delete tmp1;
+ }
+
+ /* wait */
+ if(m_cond != NULL)
+ glfwSignalCond(m_cond);
+
+ if(m_mutex != NULL || m_cond != NULL || m_thread >= 0) {
+ if(m_thread >= 0) {
+ glfwWaitThread(m_thread, GLFW_WAIT);
+ glfwDestroyThread(m_thread);
+ }
+ if(m_cond != NULL)
+ glfwDestroyCond(m_cond);
+ if(m_mutex != NULL)
+ glfwDestroyMutex(m_mutex);
+ glfwTerminate();
+ }
+
+ if(m_dicDir)
+ free(m_dicDir);
+ if(m_config)
+ free(m_config);
+
+ Open_JTalk_EventQueue_clear(&m_bufferQueue);
+
+ initialize();
+}
+
+/* Open_JTalk_Manager::Open_JTalk_Manager: constructor */
+Open_JTalk_Manager::Open_JTalk_Manager()
+{
+ initialize();
+}
+
+/* Open_JTalk_Manager::~Open_JTalk_Manager: destructor */
+Open_JTalk_Manager::~Open_JTalk_Manager()
+{
+ clear();
+}
+
+/* Open_JTalk_Manager::loadAndStart: load and start thread */
+void Open_JTalk_Manager::loadAndStart(MMDAgent *mmdagent, const char *dicDir, const char *config)
+{
+ clear();
+
+ m_mmdagent = mmdagent;
+ m_dicDir = MMDAgent_strdup(dicDir);
+ m_config = MMDAgent_strdup(config);
+
+ if(m_mmdagent == NULL || m_dicDir == NULL || m_config == NULL) {
+ clear();
+ return;
+ }
+
+ glfwInit();
+ m_mutex = glfwCreateMutex();
+ m_cond = glfwCreateCond();
+ m_thread = glfwCreateThread(mainThread, this);
+ if(m_mutex == NULL || m_cond == NULL || m_thread < 0) {
+ clear();
+ return;
+ }
+}
+
+/* Open_JTalk_Manager::stopAndRelease: stop and release thread */
+void Open_JTalk_Manager::stopAndRelease()
+{
+ clear();
+}
+
+/* Open_JTalk_Manager::run: main loop */
+void Open_JTalk_Manager::run()
+{
+ int i;
+ Open_JTalk_Link *link;
+ char *buff, *save;
+ char *chara, *style, *text;
+ bool ret = true;
+
+ /* create initial threads */
+ for(i = 0; i < OPENJTALKMANAGER_INITIALNTHREAD; i++) {
+ link = new Open_JTalk_Link;
+ if(link->open_jtalk_thread.loadAndStart(m_mmdagent, m_dicDir, m_config) == false)
+ ret = false;
+ link->next = m_list;
+ m_list = link;
+ }
+
+ if(ret == false)
+ return;
+
+ while(m_kill == false) {
+ glfwLockMutex(m_mutex);
+ while(m_count <= 0) {
+ glfwWaitCond(m_cond, m_mutex, GLFW_INFINITY);
+ if(m_kill == true)
+ return;
+ }
+ Open_JTalk_EventQueue_dequeue(&m_bufferQueue, &buff);
+ m_count--;
+ glfwUnlockMutex(m_mutex);
+
+ if(buff != NULL) {
+ chara = MMDAgent_strtok(buff, "|", &save);
+ style = MMDAgent_strtok(NULL, "|", &save);
+ text = MMDAgent_strtok(NULL, "|", &save);
+
+ if(chara != NULL && style != NULL && text != NULL) {
+ /* check character */
+ for(i = 0, link = m_list; link; link = link->next, i++)
+ if(link->open_jtalk_thread.checkCharacter(chara) == true)
+ break;
+ if(link) {
+ if(link->open_jtalk_thread.isSpeaking() == true)
+ link->open_jtalk_thread.stop(); /* if the same character is speaking, stop immediately */
+ } else {
+ for(i = 0, link = m_list; link; link = link->next, i++)
+ if(link->open_jtalk_thread.isRunning() == true && link->open_jtalk_thread.isSpeaking() == false)
+ break;
+ if(link == NULL) {
+ link = new Open_JTalk_Link;
+ link->open_jtalk_thread.loadAndStart(m_mmdagent, m_dicDir, m_config);
+ link->next = m_list;
+ m_list = link;
+ }
+ }
+ /* set */
+ link->open_jtalk_thread.synthesis(chara, style, text);
+ }
+ free(buff); /* free buffer */
+ }
+ }
+}
+
+/* Open_JTalk_Manager::isRunning: check running */
+bool Open_JTalk_Manager::isRunning()
+{
+ if(m_kill == true || m_mutex == NULL || m_cond == NULL || m_thread < 0)
+ return false;
+ else
+ return true;
+}
+
+/* Open_JTalk_Manager::synthesis: start synthesis */
+void Open_JTalk_Manager::synthesis(const char *str)
+{
+ /* check */
+ if(isRunning() == false || MMDAgent_strlen(str) <= 0)
+ return;
+
+ /* wait buffer mutex */
+ glfwLockMutex(m_mutex);
+
+ /* enqueue character name, speaking style, and text */
+ Open_JTalk_EventQueue_enqueue(&m_bufferQueue, str);
+ m_count++;
+
+ /* start synthesis event */
+ if(m_count <= 1)
+ glfwSignalCond(m_cond);
+
+ /* release buffer mutex */
+ glfwUnlockMutex(m_mutex);
+}
+
+/* Open_JTalk_Manager::stop: stop synthesis */
+void Open_JTalk_Manager::stop(const char *str)
+{
+ Open_JTalk_Link *link;
+
+ for(link = m_list; link; link = link->next) {
+ if(link->open_jtalk_thread.checkCharacter(str)) {
+ link->open_jtalk_thread.stop();
+ return;
+ }
+ }
+}
--- /dev/null
+/* ----------------------------------------------------------------- */
+/* The Toolkit for Building Voice Interaction Systems */
+/* "MMDAgent" developed by MMDAgent Project Team */
+/* http://www.mmdagent.jp/ */
+/* ----------------------------------------------------------------- */
+/* */
+/* Copyright (c) 2009-2011 Nagoya Institute of Technology */
+/* Department of Computer Science */
+/* */
+/* All rights reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the following */
+/* conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright */
+/* notice, this list of conditions and the following disclaimer. */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials provided */
+/* with the distribution. */
+/* - Neither the name of the MMDAgent project team nor the names of */
+/* its contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
+/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
+/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
+/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
+/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
+/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
+/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
+/* POSSIBILITY OF SUCH DAMAGE. */
+/* ----------------------------------------------------------------- */
+
+/* definitions */
+
+#define OPENJTALKMANAGER_INITIALNTHREAD 1 /* initial number of thread */
+
+/* Open_JTalk_Link: thread list for Open JTalk */
+typedef struct _Open_JTalk_Link {
+ Open_JTalk_Thread open_jtalk_thread;
+ struct _Open_JTalk_Link *next;
+} Open_JTalk_Link;
+
+/* Open_JTalk_Event: input message buffer */
+typedef struct _Open_JTalk_Event {
+ char *event;
+ struct _Open_JTalk_Event *next;
+} Open_JTalk_Event;
+
+/* Open_JTalk_EventQueue: queue of Open_JTalk_Event */
+typedef struct _Open_JTalk_EventQueue {
+ Open_JTalk_Event *head;
+ Open_JTalk_Event *tail;
+} Open_JTalk_EventQueue;
+
+/* Open_JTalk_Manager: multi thread manager for Open JTalk */
+class Open_JTalk_Manager
+{
+private:
+
+ MMDAgent *m_mmdagent;
+
+ GLFWmutex m_mutex;
+ GLFWcond m_cond;
+ GLFWthread m_thread;
+
+ int m_count;
+
+ bool m_kill;
+
+ Open_JTalk_EventQueue m_bufferQueue;
+ Open_JTalk_Link *m_list;
+
+ char *m_dicDir;
+ char *m_config;
+
+ /* initialize: initialize */
+ void initialize();
+
+ /* clear: clear */
+ void clear();
+
+public:
+
+ /* Open_JTalk_Manager: constructor */
+ Open_JTalk_Manager();
+
+ /* ~Open_JTalk_Manager: destructor */
+ ~Open_JTalk_Manager();
+
+ /* loadAndStart: load and start thread */
+ void loadAndStart(MMDAgent *mmdagent, const char *dicDir, const char *config);
+
+ /* stopAndRelease: stop and release thread */
+ void stopAndRelease();
+
+ /* run: main loop */
+ void run();
+
+ /* isRunning: check running */
+ bool isRunning();
+
+ /* synthesis: start synthesis */
+ void synthesis(const char *str);
+
+ /* stop: stop synthesis */
+ void stop(const char *str);
+};
--- /dev/null
+/* ----------------------------------------------------------------- */
+/* The Toolkit for Building Voice Interaction Systems */
+/* "MMDAgent" developed by MMDAgent Project Team */
+/* http://www.mmdagent.jp/ */
+/* ----------------------------------------------------------------- */
+/* */
+/* Copyright (c) 2009-2011 Nagoya Institute of Technology */
+/* Department of Computer Science */
+/* */
+/* All rights reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the following */
+/* conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright */
+/* notice, this list of conditions and the following disclaimer. */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials provided */
+/* with the distribution. */
+/* - Neither the name of the MMDAgent project team nor the names of */
+/* its contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
+/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
+/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
+/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
+/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
+/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
+/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
+/* POSSIBILITY OF SUCH DAMAGE. */
+/* ----------------------------------------------------------------- */
+
+/* headers */
+
+#include <locale.h>
+
+#include "MMD_AgentDammiy.h"
+
+#include "mecab.h"
+#include "njd.h"
+#include "jpcommon.h"
+#include "HTS_engine.h"
+
+#include "text2mecab.h"
+#include "mecab2njd.h"
+#include "njd2jpcommon.h"
+
+#include "njd_set_pronunciation.h"
+#include "njd_set_digit.h"
+#include "njd_set_accent_phrase.h"
+#include "njd_set_accent_type.h"
+#include "njd_set_unvoiced_vowel.h"
+#include "njd_set_long_vowel.h"
+
+#include "Open_JTalk.h"
+#include "Open_JTalk_Thread.h"
+
+/* mainThread: main thread */
+static void mainThread(void *param)
+{
+ Open_JTalk_Thread *open_jtalk_thread = (Open_JTalk_Thread *) param;
+ open_jtalk_thread->run();
+}
+
+/* Open_JTalk_Thread::initialize: initialize thread */
+void Open_JTalk_Thread::initialize()
+{
+ m_mmdagent = NULL;
+
+ m_mutex = NULL;
+ m_cond = NULL;
+ m_thread = -1;
+
+ m_count = 0;
+
+ m_speaking = false;
+ m_kill = false;
+
+ m_charaBuff = NULL;
+ m_styleBuff = NULL;
+ m_textBuff = NULL;
+
+ m_numModels = 0;
+ m_modelNames = NULL;
+ m_numStyles = 0;
+ m_styleNames = NULL;
+}
+
+/* Open_JTalk_Thread::clear: free thread */
+void Open_JTalk_Thread::clear()
+{
+ int i;
+
+ stop();
+ m_kill = true;
+
+ /* wait */
+ if (m_cond != NULL)
+ glfwSignalCond(m_cond);
+
+ if(m_mutex != NULL || m_cond != NULL || m_thread >= 0) {
+ if(m_thread >= 0) {
+ glfwWaitThread(m_thread, GLFW_WAIT);
+ glfwDestroyThread(m_thread);
+ }
+ if(m_cond != NULL)
+ glfwDestroyCond(m_cond);
+ if(m_mutex != NULL)
+ glfwDestroyMutex(m_mutex);
+ glfwTerminate();
+ }
+
+ if(m_charaBuff) free(m_charaBuff);
+ if(m_styleBuff) free(m_styleBuff);
+ if(m_textBuff) free(m_textBuff);
+
+ /* free model names */
+ if (m_numModels > 0) {
+ for (i = 0; i < m_numModels; i++)
+ free(m_modelNames[i]);
+ free(m_modelNames);
+ }
+
+ /* free style names */
+ if (m_numStyles > 0) {
+ for (i = 0; i < m_numStyles; i++)
+ free(m_styleNames[i]);
+ free(m_styleNames);
+ }
+
+ initialize();
+}
+
+/* Open_JTalk_Thread::Open_JTalk_Thread: thread constructor */
+Open_JTalk_Thread::Open_JTalk_Thread()
+{
+ initialize();
+}
+
+/* Open_JTalk_Thread::~Open_JTalk_Thread: thread destructor */
+Open_JTalk_Thread::~Open_JTalk_Thread()
+{
+ clear();
+}
+
+/* Open_JTalk_Thread::loadAndStart: load models and start thread */
+bool Open_JTalk_Thread::loadAndStart(MMDAgent *mmdagent, const char *dicDir, const char *config)
+{
+ int i, j, k;
+ char buff[MMDAGENT_MAXBUFLEN];
+ FILE *fp;
+ bool err = false;
+ double *weights;
+
+ /* load config file */
+ fp = MMDAgent_fopen(config, "r");
+ if (fp == NULL)
+ return false;
+
+ /* number of speakers */
+ i = MMDAgent_fgettoken(fp, buff);
+ if (i <= 0) {
+ fclose(fp);
+ clear();
+ return false;
+ }
+ m_numModels = MMDAgent_str2int(buff);
+ if (m_numModels <= 0) {
+ fclose(fp);
+ clear();
+ return false;
+ }
+
+ /* model directory names */
+ m_modelNames = (char **) malloc(sizeof(char *) * m_numModels);
+ for (i = 0; i < m_numModels; i++) {
+ j = MMDAgent_fgettoken(fp, buff);
+ if (j <= 0)
+ err = true;
+ m_modelNames[i] = MMDAgent_strdup(buff);
+ }
+ if (err) {
+ fclose(fp);
+ clear();
+ return false;
+ }
+
+ /* number of speaking styles */
+ i = MMDAgent_fgettoken(fp, buff);
+ if (i <= 0) {
+ fclose(fp);
+ clear();
+ return false;
+ }
+ m_numStyles = MMDAgent_str2int(buff);
+ if (m_numStyles <= 0) {
+ m_numStyles = 0;
+ fclose(fp);
+ clear();
+ return false;
+ }
+
+ /* style names and weights */
+ m_styleNames = (char **) calloc(m_numStyles, sizeof(char *));
+ weights = (double *) calloc((3 * m_numModels + 4) * m_numStyles, sizeof(double));
+ for (i = 0; i < m_numStyles; i++) {
+ j = MMDAgent_fgettoken(fp, buff);
+ if(j <= 0)
+ err = true;
+ m_styleNames[i] = MMDAgent_strdup(buff);
+ for (j = 0; j < 3 * m_numModels + 4; j++) {
+ k = MMDAgent_fgettoken(fp, buff);
+ if (k <= 0)
+ err = true;
+ weights[(3 * m_numModels + 4) * i + j] = MMDAgent_str2float(buff);
+ }
+ }
+ fclose(fp);
+ if(err) {
+ free(weights);
+ clear();
+ return false;
+ }
+
+ /* load models for TTS */
+ if (m_openJTalk.load(dicDir, m_modelNames, m_numModels, weights, m_numStyles) != true) {
+ free(weights);
+ clear();
+ return false;
+ }
+ setlocale(LC_CTYPE, "japanese");
+
+ free(weights);
+
+ m_mmdagent = mmdagent;
+
+ /* start thread */
+ glfwInit();
+ m_mutex = glfwCreateMutex();
+ m_cond = glfwCreateCond();
+ m_thread = glfwCreateThread(mainThread, this);
+ if(m_mutex == NULL || m_cond == NULL || m_thread < 0) {
+ clear();
+ return false;
+ }
+
+ return true;
+}
+
+/* Open_JTalk_Thread::stopAndRelease: stop thread and free Open JTalk */
+void Open_JTalk_Thread::stopAndRelease()
+{
+ clear();
+}
+
+/* Open_JTalk_Thread::run: main thread loop for TTS */
+void Open_JTalk_Thread::run()
+{
+ char lip[MMDAGENT_MAXBUFLEN];
+ char *chara, *style, *text;
+ int index;
+
+ while (m_kill == false) {
+ /* wait text */
+ glfwLockMutex(m_mutex);
+ while(m_count <= 0) {
+ glfwWaitCond(m_cond, m_mutex, GLFW_INFINITY);
+ if(m_kill == true)
+ return;
+ }
+ chara = MMDAgent_strdup(m_charaBuff);
+ style = MMDAgent_strdup(m_styleBuff);
+ text = MMDAgent_strdup(m_textBuff);
+ m_count--;
+ glfwUnlockMutex(m_mutex);
+
+ m_speaking = true;
+
+ /* search style index */
+ for (index = 0; index < m_numStyles; index++)
+ if (MMDAgent_strequal(m_styleNames[index], style))
+ break;
+ if (index >= m_numStyles) /* unknown style */
+ index = 0;
+
+ /* send SYNTH_EVENT_START */
+ m_mmdagent->sendEventMessage(OPENJTALKTHREAD_EVENTSTART, chara);
+
+ /* synthesize */
+ m_openJTalk.setStyle(index);
+ m_openJTalk.prepare(text);
+ m_openJTalk.getPhonemeSequence(lip);
+ if (MMDAgent_strlen(lip) > 0) {
+ m_mmdagent->sendCommandMessage(OPENJTALKTHREAD_COMMANDSTARTLIP, "%s|%s", chara, lip);
+ m_openJTalk.synthesis();
+ }
+
+ /* send SYNTH_EVENT_STOP */
+ m_mmdagent->sendEventMessage(OPENJTALKTHREAD_EVENTSTOP, chara);
+
+ if(chara) free(chara);
+ if(style) free(style);
+ if(text) free(text);
+ m_speaking = false;
+ }
+}
+
+/* Open_JTalk_Thread::isRunning: check running */
+bool Open_JTalk_Thread::isRunning()
+{
+ if(m_kill == true || m_mutex == NULL || m_cond == NULL || m_thread < 0)
+ return false;
+ else
+ return true;
+}
+
+/* Open_JTalk_Thread::isSpeaking: check speaking */
+bool Open_JTalk_Thread::isSpeaking()
+{
+ return m_speaking;
+}
+
+/* checkCharacter: check speaking character */
+bool Open_JTalk_Thread::checkCharacter(const char *chara)
+{
+ bool ret;
+
+ /* check */
+ if(isRunning() == false)
+ return false;
+
+ /* wait buffer mutex */
+ glfwLockMutex(m_mutex);
+
+ /* save character name, speaking style, and text */
+ ret = MMDAgent_strequal(m_charaBuff, chara);
+
+ /* release buffer mutex */
+ glfwUnlockMutex(m_mutex);
+
+ return ret;
+}
+
+/* Open_JTalk_Thread::synthesis: start synthesis */
+void Open_JTalk_Thread::synthesis(const char *chara, const char *style, const char *text)
+{
+ /* check */
+ if(isRunning() == false)
+ return;
+ if(MMDAgent_strlen(chara) <= 0 || MMDAgent_strlen(style) <= 0 || MMDAgent_strlen(text) <= 0)
+ return;
+
+ /* wait buffer mutex */
+ glfwLockMutex(m_mutex);
+
+ /* save character name, speaking style, and text */
+ if(m_charaBuff) free(m_charaBuff);
+ if(m_styleBuff) free(m_styleBuff);
+ if(m_textBuff) free(m_textBuff);
+ m_charaBuff = MMDAgent_strdup(chara);
+ m_styleBuff = MMDAgent_strdup(style);
+ m_textBuff = MMDAgent_strdup(text);
+ m_count++;
+
+ /* start synthesis thread */
+ if(m_count <= 1)
+ glfwSignalCond(m_cond);
+
+ /* release buffer mutex */
+ glfwUnlockMutex(m_mutex);
+}
+
+/* Open_JTalk_Thread::stop: barge-in function */
+void Open_JTalk_Thread::stop()
+{
+ if(isRunning() == true) {
+ m_openJTalk.stop();
+
+ /* wait buffer mutex */
+ glfwLockMutex(m_mutex);
+
+ /* stop lip sync */
+ m_mmdagent->sendCommandMessage(OPENJTALKTHREAD_COMMANDSTOPLIP, m_charaBuff);
+
+ /* release buffer mutex */
+ glfwUnlockMutex(m_mutex);
+
+ }
+}
--- /dev/null
+/* ----------------------------------------------------------------- */
+/* The Toolkit for Building Voice Interaction Systems */
+/* "MMDAgent" developed by MMDAgent Project Team */
+/* http://www.mmdagent.jp/ */
+/* ----------------------------------------------------------------- */
+/* */
+/* Copyright (c) 2009-2011 Nagoya Institute of Technology */
+/* Department of Computer Science */
+/* */
+/* All rights reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the following */
+/* conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright */
+/* notice, this list of conditions and the following disclaimer. */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials provided */
+/* with the distribution. */
+/* - Neither the name of the MMDAgent project team nor the names of */
+/* its contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
+/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
+/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
+/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
+/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
+/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
+/* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
+/* POSSIBILITY OF SUCH DAMAGE. */
+/* ----------------------------------------------------------------- */
+
+/* definitions */
+
+#define OPENJTALKTHREAD_EVENTSTART "SYNTH_EVENT_START"
+#define OPENJTALKTHREAD_EVENTSTOP "SYNTH_EVENT_STOP"
+#define OPENJTALKTHREAD_COMMANDSTARTLIP "LIPSYNC_START"
+#define OPENJTALKTHREAD_COMMANDSTOPLIP "LIPSYNC_STOP"
+
+/* Open_JTalk_Thread: thread for Open JTalk */
+class Open_JTalk_Thread
+{
+private:
+
+ MMDAgent *m_mmdagent;
+
+ GLFWmutex m_mutex;
+ GLFWcond m_cond;
+ GLFWthread m_thread;
+
+ int m_count;
+
+ bool m_speaking;
+ bool m_kill;
+
+ char *m_charaBuff;
+ char *m_styleBuff;
+ char *m_textBuff;
+
+ Open_JTalk m_openJTalk; /* Japanese TTS system */
+ int m_numModels; /* number of models */
+ char **m_modelNames; /* model names */
+ int m_numStyles; /* number of styles */
+ char **m_styleNames; /* style names */
+
+ /* initialize: initialize thread */
+ void initialize();
+
+ /* clear: free thread */
+ void clear();
+
+public:
+
+ /* Open_JTalk_Thraed: thread constructor */
+ Open_JTalk_Thread();
+
+ /* ~Open_JTalk_Thread: thread destructor */
+ ~Open_JTalk_Thread();
+
+ /* loadAndStart: load models and start thread */
+ bool loadAndStart(MMDAgent *mmdagent, const char *dicDir, const char *config);
+
+ /* stopAndRelease: stop thread and free Open JTalk */
+ void stopAndRelease();
+
+ /* run: main thread loop for TTS */
+ void run();
+
+ /* isRunning: check running */
+ bool isRunning();
+
+ /* isSpeaking: check speaking */
+ bool isSpeaking();
+
+ /* checkCharacter: check speaking character */
+ bool checkCharacter(const char *chara);
+
+ /* synthesis: start synthesis */
+ void synthesis(const char *chara, const char *style, const char *text);
+
+ /* stop: stop synthesis */
+ void stop();
+};
--- /dev/null
+===============================================================================
+ HTS Voice "Mei (Normal)" version 1.1
+ release August 3, 2011
+
+
+The work is released as a part of MMDAgent (http://www.mmdagent.jp/).
+
+*******************************************************************************
+ Copying
+*******************************************************************************
+
+# ----------------------------------------------------------------- #
+# HTS Voice "Mei (Normal)" #
+# released by MMDAgent Project Team #
+# http://www.mmdagent.jp/ #
+# ----------------------------------------------------------------- #
+# #
+# Copyright (c) 2009-2011 Nagoya Institute of Technology #
+# Department of Computer Science #
+# #
+# Some rights reserved. #
+# #
+# This work is licensed under the Creative Commons Attribution 3.0 #
+# license. #
+# #
+# You are free: #
+# * to Share - to copy, distribute and transmit the work #
+# * to Remix - to adapt the work #
+# Under the following conditions: #
+# * Attribution - You must attribute the work in the manner #
+# specified by the author or licensor (but not in any way that #
+# suggests that they endorse you or your use of the work). #
+# With the understanding that: #
+# * Waiver - Any of the above conditions can be waived if you get #
+# permission from the copyright holder. #
+# * Public Domain - Where the work or any of its elements is in #
+# the public domain under applicable law, that status is in no #
+# way affected by the license. #
+# * Other Rights - In no way are any of the following rights #
+# affected by the license: #
+# - Your fair dealing or fair use rights, or other applicable #
+# copyright exceptions and limitations; #
+# - The author's moral rights; #
+# - Rights other persons may have either in the work itself or #
+# in how the work is used, such as publicity or privacy #
+# rights. #
+# * Notice - For any reuse or distribution, you must make clear to #
+# others the license terms of this work. The best way to do this #
+# is with a link to this web page. #
+# #
+# See http://creativecommons.org/ for details. #
+# ----------------------------------------------------------------- #
+
+See also "COPYRIGHT.txt" file in the current directory for details.
+
+*******************************************************************************
+ Acknowledgements
+*******************************************************************************
+
+Keiichi Tokuda
+Akinobu Lee
+Keiichiro Oura
+
+*******************************************************************************
+ Who we are
+*******************************************************************************
+
+The MMDAgent project team is a voluntary group for developing the Toolkit for
+Building Voice Interaction System. Current members are
+
+ Keiichi Tokuda http://www.sp.nitech.ac.jp/~tokuda/
+ Akinobu Lee http://www.sp.nitech.ac.jp/~ri/
+ Keiichiro Oura http://www.sp.nitech.ac.jp/~uratec/
+
+and the members are dynamically changing. The current formal contact address of
+MMDAgent project team and a mailing list for MMDAgent users can be found at
+http://www.mmdagent.jp/
+===============================================================================
--- /dev/null
+========================================================================
+ コンソール アプリケーション: open_jtalk_test プロジェクトの概要
+========================================================================
+
+この open_jtalk_test アプリケーションは、AppWizard により作成されました。
+
+このファイルには、open_jtalk_test
+アプリケーションを構成する各ファイルの内容の概要が含まれています。
+
+
+open_jtalk_test.vcxproj
+ これは、アプリケーション ウィザードを使用して生成された VC++
+ プロジェクトのメイン プロジェクト ファイルです。
+ ファイルを生成した Visual C++ のバージョンに関する情報と、アプリケーション
+ ウィザードで選択されたプラットフォーム、
+ 構成、およびプロジェクト機能に関する情報が含まれています。
+
+open_jtalk_test.vcxproj.filters
+ これは、アプリケーション ウィザードで生成された VC++ プロジェクトのフィルター
+ ファイルです。
+ このファイルには、プロジェクト内のファイルとフィルターとの間の関連付けに関する
+ 情報が含まれています。 この関連付けは、特定のノー
+ ドで同様の拡張子を持つファイルのグループ化を
+ 示すために IDE で使用されます (たとえば、".cpp" ファイルは "ソース ファイル"
+ フィルターに関連付けられています)。
+
+open_jtalk_test.cpp
+ これは、メインのアプリケーション ソース ファイルです。
+
+/////////////////////////////////////////////////////////////////////////////
+その他の標準ファイル :
+
+StdAfx.h、StdAfx.cpp
+ これらのファイルは、open_jtalk_test.pch
+ という名前のプリコンパイル済みヘッダー (PCH) ファイルと、StdAfx.obj
+ という名前のプリコンパイル済みの型ファイルを構築するために使用されます。
+
+/////////////////////////////////////////////////////////////////////////////
+その他のメモ :
+
+AppWizard では "TODO:"
+コメントを使用して、ユーザーが追加またはカスタマイズする必要のあるソース
+コードを示します。
+
+/////////////////////////////////////////////////////////////////////////////
--- /dev/null
+// open_jtalk_test.cpp : \83R\83\93\83\\81[\83\8b \83A\83v\83\8a\83P\81[\83V\83\87\83\93\82Ì\83G\83\93\83g\83\8a \83|\83C\83\93\83g\82ð\92è\8b`\82µ\82Ü\82·\81B
+//
+
+#include "stdafx.h"
+#include <Open_JTalk.h>
+
+int _tmain(int argc, _TCHAR* argv[])
+{
+
+ Open_JTalk open_jtalk;
+ //open_jtalk.load(
+ return 0;
+}
+
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{2EE744C8-848A-4BE8-907F-AAE6AF61655B}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>open_jtalk_test</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LinkIncremental>true</LinkIncremental>
+ <IncludePath>$(solutiondir)open_jtalk_lib\open_jtalk_manager\;$(IncludePath)</IncludePath>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <None Include="ReadMe.txt" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="stdafx.h" />
+ <ClInclude Include="targetver.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="open_jtalk_test.cpp" />
+ <ClCompile Include="stdafx.cpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="ソース ファイル">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ <Filter Include="ヘッダー ファイル">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+ </Filter>
+ <Filter Include="リソース ファイル">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="ReadMe.txt" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="stdafx.h">
+ <Filter>ヘッダー ファイル</Filter>
+ </ClInclude>
+ <ClInclude Include="targetver.h">
+ <Filter>ヘッダー ファイル</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="stdafx.cpp">
+ <Filter>ソース ファイル</Filter>
+ </ClCompile>
+ <ClCompile Include="open_jtalk_test.cpp">
+ <Filter>ソース ファイル</Filter>
+ </ClCompile>
+ </ItemGroup>
+</Project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+</Project>
\ No newline at end of file
--- /dev/null
+// stdafx.cpp : \95W\8f\80\83C\83\93\83N\83\8b\81[\83h open_jtalk_test.pch \82Ì\82Ý\82ð
+// \8aÜ\82Þ\83\\81[\83X \83t\83@\83C\83\8b\82Í\81A\83v\83\8a\83R\83\93\83p\83C\83\8b\8dÏ\82Ý\83w\83b\83_\81[\82É\82È\82è\82Ü\82·\81B
+// stdafx.obj \82É\82Í\83v\83\8a\83R\83\93\83p\83C\83\8b\8dÏ\82Ý\8c^\8fî\95ñ\82ª\8aÜ\82Ü\82ê\82Ü\82·\81B
+
+#include "stdafx.h"
+
+// TODO: \82±\82Ì\83t\83@\83C\83\8b\82Å\82Í\82È\82\81ASTDAFX.H \82Å\95K\97v\82È
+// \92Ç\89Á\83w\83b\83_\81[\82ð\8eQ\8fÆ\82µ\82Ä\82\82¾\82³\82¢\81B
--- /dev/null
+// stdafx.h : \95W\8f\80\82Ì\83V\83X\83e\83\80 \83C\83\93\83N\83\8b\81[\83h \83t\83@\83C\83\8b\82Ì\83C\83\93\83N\83\8b\81[\83h \83t\83@\83C\83\8b\81A\82Ü\82½\82Í
+// \8eQ\8fÆ\89ñ\90\94\82ª\91½\82\81A\82©\82Â\82 \82Ü\82è\95Ï\8dX\82³\82ê\82È\82¢\81A\83v\83\8d\83W\83F\83N\83g\90ê\97p\82Ì\83C\83\93\83N\83\8b\81[\83h \83t\83@\83C\83\8b
+// \82ð\8bL\8fq\82µ\82Ü\82·\81B
+//
+
+#pragma once
+
+#include "targetver.h"
+
+#include <stdio.h>
+#include <tchar.h>
+
+
+
+// TODO: \83v\83\8d\83O\83\89\83\80\82É\95K\97v\82È\92Ç\89Á\83w\83b\83_\81[\82ð\82±\82±\82Å\8eQ\8fÆ\82µ\82Ä\82\82¾\82³\82¢\81B
--- /dev/null
+#pragma once
+
+// SDKDDKVer.h \82ð\83C\83\93\83N\83\8b\81[\83h\82·\82é\82Æ\81A\97\98\97p\82Å\82«\82é\8dÅ\82à\8fã\88Ê\82Ì Windows \83v\83\89\83b\83g\83t\83H\81[\83\80\82ª\92è\8b`\82³\82ê\82Ü\82·\81B
+
+// \88È\91O\82Ì Windows \83v\83\89\83b\83g\83t\83H\81[\83\80\97p\82É\83A\83v\83\8a\83P\81[\83V\83\87\83\93\82ð\83r\83\8b\83h\82·\82é\8fê\8d\87\82Í\81AWinSDKVer.h \82ð\83C\83\93\83N\83\8b\81[\83h\82µ\81A
+// SDKDDKVer.h \82ð\83C\83\93\83N\83\8b\81[\83h\82·\82é\91O\82É\81A\83T\83|\81[\83g\91Î\8fÛ\82Æ\82·\82é\83v\83\89\83b\83g\83t\83H\81[\83\80\82ð\8e¦\82·\82æ\82¤\82É _WIN32_WINNT \83}\83N\83\8d\82ð\90Ý\92è\82µ\82Ü\82·\81B
+
+#include <SDKDDKVer.h>
///
///\83R\83\93\83X\83g\83\89\83N\83^
///
-CMeiNormal::CMeiNormal()
-{}
+CMeiNormal::CMeiNormal(const TChar_P voiceDataDir,const TChar_P dictionaryDataDir)
+{
+ Initialize();
+ Load(voiceDataDir,dictionaryDataDir);
+
+}
///
void CMeiNormal::Load(const TChar_P voiceDataDir,const TChar_P dictionaryDataDir){
+
+ static char *mgc_winList[] = {"mgc.win1","mgc.win2","mgc.win3"};
+ static char *lf0_winList[] = {"lf0.win1","lf0.win2","lf0.win3"};
+ static char *lpf_winList[] = {"lpf.win1"};
+ COpenJtalkCore::Load(
+ voiceDataDir,dictionaryDataDir,
+ "dur.pdf","tree-dur.inf",
+ "mgc.pdf","tree-mgc.inf",mgc_winList,sizeof(mgc_winList)/sizeof(mgc_winList[0]),
+ "lf0.pdf","tree-lf0.inf",lf0_winList,sizeof(lf0_winList)/sizeof(lf0_winList[0]),
+ "lpf.pdf","tree-lpf.inf",lpf_winList,sizeof(lpf_winList)/sizeof(lpf_winList[0]),
+ "gv-mgc.pdf","tree-gv-mgc.inf",
+ "gv-lf0.pdf","tree-gv-lf0.inf",
+ NULL,NULL,
+ "gv-switch.inf"
+ );
- //COpenJtalkCore::Load(voiceDataDir,dictionaryDataDir,"dur.pdf","tree-dur.inf","mgc.pdf",
return;
}
class CMeiNormal:public COpenJtalkCore{
+ public:
+
///
///\83R\83\93\83X\83g\83\89\83N\83^
///
- CMeiNormal();
+ CMeiNormal(const TChar_P voiceDataDir,const TChar_P dictionaryDataDir);
///
COpenJtalkCore::COpenJtalkCore():
-manageFlag(false){}
+manageFlag(false){
+
+ this->synthesisThreadHandle = (HANDLE)_beginthreadex(NULL,0,COpenJtalkCore::SynthesisThreadFunction,this,0,NULL);
+ this->synthesisEventObject = ::CreateEvent(NULL,false,false,NULL);
+ this->endEventObject = ::CreateEvent(NULL,true,false,NULL);
+
+}
COpenJtalkCore::~COpenJtalkCore(){
if(this->manageFlag == true)this->Clear();
+
+ ::SetEvent(this->endEventObject);
+ int errcount = 0;
+ while(::WaitForSingleObject(this->synthesisThreadHandle,3000) == WAIT_TIMEOUT){
+ errcount++;
+ if(errcount > 3){
+
+ _exit(-1);
+ }
+
+ }
+
+ ::CloseHandle(this->synthesisThreadHandle);
+ ::CloseHandle(this->synthesisEventObject);
+ ::CloseHandle(this->endEventObject);
+
}
void COpenJtalkCore::Initialize( HTS_Boolean use_lpf, int sampling_rate,
CStringA dictionaryDataDir(in_dictinalyDataDir); //\8e«\8f\91\83f\81[\83^\83f\83B\83\8c\83N\83g\83\8a
CStringA voiceDataDir(in_voiceDataDir); //\89¹\90º\81[\83f\81[\83^\83f\83B\83\8c\83N\83g\83\8a
- std::vector<Char_P> ws_mgcList(num_ws_mgc);
-
+ std::vector<Char_P> ws_mgcList;
+ std::vector<std::string> ws_mgcBuffList;
+
for(int ws_mgc_index = 0;ws_mgc_index < num_ws_mgc;++ws_mgc_index){
- ws_mgcList.push_back((char *)(const char*)(voiceDataDir + fn_ws_mgc[ws_mgc_index]));
+ ws_mgcBuffList.push_back((const char*)(voiceDataDir + fn_ws_mgc[ws_mgc_index]));
+ ws_mgcList.push_back(&ws_mgcBuffList.back()[0]);
}
- std::vector<Char_P> ws_lf0List(num_ws_lf0);
-
+ std::vector<Char_P> ws_lf0List;
+ std::vector<std::string> ws_lf0BuffList;
for(int ws_lf0Index = 0;ws_lf0Index < num_ws_lf0;++ws_lf0Index){
- ws_mgcList.push_back((char *)(const char*)(voiceDataDir + fn_ws_mgc[ws_lf0Index]));
+ ws_lf0BuffList.push_back((const char*)(voiceDataDir + fn_ws_mgc[ws_lf0Index]));
+ ws_lf0List.push_back(&ws_lf0BuffList.back()[0]);
}
- std::vector<Char_P> ws_lpfList(num_ws_lpf);
-
+ std::vector<Char_P> ws_lpfList;
+ std::vector<std::string> ws_lpfBuffList;
for(int ws_lpfIndex = 0;ws_lpfIndex < num_ws_lpf;++ws_lpfIndex){
- ws_mgcList.push_back((char *)(const char*)(voiceDataDir + fn_ws_mgc[ws_lpfIndex]));
+ ws_lpfBuffList.push_back((const char*)(voiceDataDir + fn_ws_mgc[ws_lpfIndex]));
+ ws_lpfList.push_back(&ws_lpfBuffList.back()[0]);
}
::OpenJTalk_load(&this->openJtalk_internal,
(char *)(const char*)(dictionaryDataDir),
- (char *)(const char*)(voiceDataDir +fn_ms_dur),
- (char *)(const char*)(voiceDataDir +fn_ts_dur),
- (char *)(const char*)(voiceDataDir +fn_ms_mgc),
- (char *)(const char*)(voiceDataDir +fn_ts_mgc),
+ fn_ms_dur != NULL ?(char *)(const char*)(voiceDataDir +fn_ms_dur) : NULL,
+ fn_ts_dur != NULL ? (char *)(const char*)(voiceDataDir +fn_ts_dur) : NULL,
+ fn_ms_mgc != NULL ? (char *)(const char*)(voiceDataDir +fn_ms_mgc) : NULL,
+ fn_ts_mgc != NULL ? (char *)(const char*)(voiceDataDir +fn_ts_mgc) : NULL,
&ws_mgcList[0],
num_ws_mgc,
- (char *)(const char*)(voiceDataDir +fn_ms_lf0),
- (char *)(const char*)(voiceDataDir +fn_ts_lf0),
+ fn_ms_lf0 != NULL ?(char *)(const char*)(voiceDataDir +fn_ms_lf0) : NULL,
+ fn_ts_lf0 != NULL ? (char *)(const char*)(voiceDataDir +fn_ts_lf0) : NULL,
&ws_mgcList[0],
num_ws_lf0,
- (char *)(const char*)(voiceDataDir +fn_ms_lpf),
- (char *)(const char*)(voiceDataDir +fn_ts_lpf),
+ fn_ms_lpf != NULL ? (char *)(const char*)(voiceDataDir +fn_ms_lpf) : NULL,
+ fn_ts_lpf != NULL ? (char *)(const char*)(voiceDataDir +fn_ts_lpf) : NULL,
&ws_lpfList[0],
num_ws_lpf,
- (char *)(const char*)(voiceDataDir +fn_ms_gvm),
- (char *)(const char*)(voiceDataDir +fn_ts_gvm),
- (char *)(const char*)(voiceDataDir +fn_ms_gvl),
- (char *)(const char*)(voiceDataDir +fn_ts_gvl),
- (char *)(const char*)(voiceDataDir +fn_ms_gvf),
- (char *)(const char*)(voiceDataDir +fn_ts_gvf),
- fn_gv_switch
+ fn_ms_gvm != NULL ? (char *)(const char*)(voiceDataDir +fn_ms_gvm) : NULL,
+ fn_ts_gvm != NULL ? (char *)(const char*)(voiceDataDir +fn_ts_gvm) : NULL,
+ fn_ms_gvl != NULL ? (char *)(const char*)(voiceDataDir +fn_ms_gvl) : NULL,
+ fn_ts_gvl != NULL ? (char *)(const char*)(voiceDataDir +fn_ts_gvl) : NULL,
+ fn_ms_gvf != NULL ? (char *)(const char*)(voiceDataDir +fn_ms_gvf) : NULL,
+ fn_ts_gvf != NULL ? (char *)(const char*)(voiceDataDir +fn_ts_gvf) : NULL,
+ fn_gv_switch != NULL ? (char *)(const char*)(voiceDataDir +fn_gv_switch) : NULL
+
);
}
}
-void COpenJtalkCore::Synthesis( Char_P txt, FILE * wavfp, FILE * logfp){
- ::OpenJTalk_synthesis(&this->openJtalk_internal,txt,wavfp,logfp);
+void COpenJtalkCore::Synthesis( const TChar_P txt, FILE * wavfp, FILE * logfp){
+ CStringA txtA(txt);
+ ::OpenJTalk_synthesis(&this->openJtalk_internal,(Char_P)(const char*)txtA,wavfp,logfp);
+}
+
+void COpenJtalkCore::Synthesis(const TChar_P txt){
+
+ Synthesis(txt,NULL,NULL);
+
}
+void COpenJtalkCore::SynthesisAsync(const TChar_P txt){
+
+ this->synthesisQueueCS.Lock();
+
+ if(this->synthesisQueue.size() > 3)this->synthesisQueue.pop();
+
+ this->synthesisQueue.push(txt);
+
+ this->synthesisQueueCS.Unlock();
+
+}
+
void COpenJtalkCore::Clear(){
::OpenJTalk_clear(&this->openJtalk_internal);
this->manageFlag = false;
}
+unsigned WINAPI COpenJtalkCore::SynthesisThreadFunction(void *userData){
+
+ auto &self = *(COpenJtalkCore*)userData;
+
+ HANDLE eventList[2] = {self.synthesisEventObject,self.endEventObject};
+
+ DWORD dwRslt;
+
+ do{
+ dwRslt = ::WaitForMultipleObjects(sizeof(eventList) / sizeof(eventList[0]),eventList,false,INFINITE);
+
+ if(dwRslt- WAIT_OBJECT_0 == 1)break;
+
+ CString synthesisString;
+
+ self.synthesisQueueCS.Lock();
+
+ synthesisString = self.synthesisQueue.back();
+ self.synthesisQueue.pop();
+
+ self.synthesisQueueCS.Unlock();
+
+ self.Synthesis((const TChar_P)(const wchar_t*)synthesisString);
+
+
+ } while(true);
+
+ _endthreadex(0);
+
+ return 0;
+}
+
}
}
\ No newline at end of file
#pragma once
+#include <queue>
namespace speaker{
namespace openJtalk{
///OpenJtalk\82ð\83\89\83b\83v\82µ\82½\83N\83\89\83X
///\83f\83B\83\8c\83N\83g\83\8a\82Ì\88µ\82¢\82Ì\8aÈ\88Õ\89»\82Æ\83I\83u\83W\83F\83N\83g\82ð\83f\83X\83g\83\89\83N\83^\82Å\8e©\93®\94j\8aü\82³\82ê\82é\82æ\82¤\82É\82µ\82½\82à\82Ì
///
- class COpenJtalkCore{
+ class COpenJtalkCore:public ISpeaker{
private:
OpenJTalk openJtalk_internal; //\93à\95\94\83I\83u\83W\83F\83N\83g
bool manageFlag; //\8aÇ\97\9d\83t\83\89\83O
-
-
+ CComAutoCriticalSection synthesisQueueCS;
+ std::queue<CString> synthesisQueue;
+ HANDLE synthesisThreadHandle; //\93Ç\82Ý\8fã\82°\83X\83\8c\83b\83h\83n\83\93\83h\83\8b
+ HANDLE synthesisEventObject;
+ HANDLE endEventObject;
protected:
///
///\83R\83\93\83X\83g\83\89\83N\83^
///
virtual ~COpenJtalkCore();
- //\83R\83s\81[\83K\81[\83h
- private:
- COpenJtalkCore (const COpenJtalkCore&);
- COpenJtalkCore& operator=(const COpenJtalkCore&);
+
protected:
///
///
///\89¹\90º\8d\87\90¬
///
- void Synthesis( Char_P txt, FILE * wavfp, FILE * logfp);
+ void Synthesis( const TChar_P txt, FILE * wavfp, FILE * logfp);
-
+ ///
+ ///\89¹\90º\8d\87\90¬\83C\83\93\83^\81[\83t\83F\81[\83X\8eÀ\91\95
+ ///
+ void Synthesis(const TChar_P txt);
+
+
+ ///
+ ///\94ñ\93¯\8aú\93Ç\82Ý\8fã\82°\83C\83\93\83^\81[\83t\83F\81[\83X\8eÀ\91\95
+ ///
+ void SynthesisAsync(const TChar_P txt);
+
///
///\83I\83u\83W\83F\83N\83g\82Ì\83N\83\8a\83A
///
void Clear();
+
+ private:
+ ///
+ ///\94ñ\93¯\8aú\93Ç\82Ý\8fã\82°\97p\82Ì\83X\83\8c\83b\83h\8aÖ\90\94
+ ///
+ static unsigned WINAPI SynthesisThreadFunction(void *userData);
};
--- /dev/null
+#include "stdafx.h"
+#include "speaker_include.h"
+
+namespace speaker{
+
+ ISpeaker::ISpeaker(){}
+ ISpeaker &ISpeaker::GetMeiNormal(const TChar_P voiceDataDir,const TChar_P dictinaryDataDir){
+
+ static openJtalk::CMeiNormal mei_normal(voiceDataDir,dictinaryDataDir);
+
+
+ return mei_normal;
+
+ }
+}
\ No newline at end of file
--- /dev/null
+#pragma once
+
+#include "speaker_define.h"
+
+namespace speaker{
+class ISpeaker{
+
+protected:
+ ISpeaker();
+
+ //\83R\83s\81[\83K\81[\83h
+private:
+ ISpeaker (const ISpeaker&);
+ ISpeaker& operator=(const ISpeaker&);
+
+public:
+
+ ///
+ ///\93Ç\82Ý\8fã\82°
+ ///
+ virtual void Synthesis(const TChar_P txt) = 0;
+
+ ///
+ ///\94ñ\93¯\8aú\82Å\93Ç\82Ý\8fã\82°
+ ///
+ virtual void SynthesisAsync(const TChar_P txt) = 0;
+
+ ///
+ ///\83I\83u\83W\83F\83N\83g\8aJ\95ú
+ ///
+ virtual void Clear() = 0;
+
+
+ ///
+ ///\83\81\83C\8eæ\93¾
+ ///
+ static ISpeaker &GetMeiNormal(const TChar_P voiceDataDir,const TChar_P dictinaryDataDir);
+
+};
+
+}
\ No newline at end of file
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>WIN32;OPENJTALK_STATIC_MACRO;_DEBUG;_LIB;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>WIN32;OPENJTALK_STATIC_MACRO;NDEBUG;_LIB;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<ItemGroup>
<ClInclude Include="mei_normal.h" />
<ClInclude Include="open_jtalk_core.h" />
+ <ClInclude Include="speaker.h" />
<ClInclude Include="speaker_define.h" />
<ClInclude Include="speaker_include.h" />
<ClInclude Include="stdafx.h" />
<ItemGroup>
<ClCompile Include="mei_normal.cpp" />
<ClCompile Include="open_jtalk_core.cpp" />
+ <ClCompile Include="speaker.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<ClInclude Include="mei_normal.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
+ <ClInclude Include="speaker.h">
+ <Filter>ヘッダー ファイル</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<ClCompile Include="mei_normal.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
+ <ClCompile Include="speaker.cpp">
+ <Filter>ソース ファイル</Filter>
+ </ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
#include <open_jtalk_lib.h>
-#include "speaker_define.h"
+#include "speaker_define.h"
+#include "speaker.h"
#include "open_jtalk_core.h"
#include "mei_normal.h"
\ No newline at end of file
// TODO: \83v\83\8d\83O\83\89\83\80\82É\95K\97v\82È\92Ç\89Á\83w\83b\83_\81[\82ð\82±\82±\82Å\8eQ\8fÆ\82µ\82Ä\82\82¾\82³\82¢\81B
#include <atlstr.h>
+#include <atlcore.h>
#include <vector>
+#include <queue>