OSDN Git Service

読み上げ機能実装途中
[nlite/nlite.git] / speaker / open_jtalk_core.cpp
1 #include "stdafx.h"
2 #include "speaker_include.h"
3
4 namespace speaker{
5 namespace openJtalk{
6
7
8
9 COpenJtalkCore::COpenJtalkCore():
10 manageFlag(false){}
11
12
13 COpenJtalkCore::~COpenJtalkCore(){
14         if(this->manageFlag == true)this->Clear();
15 }
16
17 void COpenJtalkCore::Initialize( HTS_Boolean use_lpf, int sampling_rate,
18                           int fperiod, double alpha, int stage, double beta, int audio_buff_size,
19                           double uv_threshold, HTS_Boolean use_log_gain, double gv_weight_mgc,
20                           double gv_weight_lf0, double gv_weight_lpf){
21                                                           if(this->manageFlag == true)this->Clear();
22                                                           ::OpenJTalk_initialize(&this->openJtalk_internal,use_lpf,sampling_rate,fperiod,alpha,stage,
23                                                                   beta,audio_buff_size,uv_threshold,use_log_gain,gv_weight_mgc,gv_weight_lf0,gv_weight_lpf);
24
25                                                           this->manageFlag = true;
26 }
27
28 void COpenJtalkCore::Load( const TChar_P in_voiceDataDir,const TChar_P in_dictinalyDataDir, Char_P fn_ms_dur, Char_P fn_ts_dur,
29             Char_P fn_ms_mgc, Char_P fn_ts_mgc, Char_P *fn_ws_mgc, int num_ws_mgc,
30             Char_P fn_ms_lf0, Char_P fn_ts_lf0, Char_P *fn_ws_lf0, int num_ws_lf0,
31             Char_P fn_ms_lpf, Char_P fn_ts_lpf, Char_P *fn_ws_lpf, int num_ws_lpf,
32             Char_P fn_ms_gvm, Char_P fn_ts_gvm, Char_P fn_ms_gvl, Char_P fn_ts_gvl,
33             Char_P fn_ms_gvf, Char_P fn_ts_gvf,Char_P fn_gv_switch){
34
35                                 if(this->manageFlag == true){
36
37                                         CStringA dictionaryDataDir(in_dictinalyDataDir);                        //\8e«\8f\91\83f\81[\83^\83f\83B\83\8c\83N\83g\83\8a
38                                         CStringA voiceDataDir(in_voiceDataDir);                         //\89¹\90º\81[\83f\81[\83^\83f\83B\83\8c\83N\83g\83\8a
39
40                                         std::vector<Char_P> ws_mgcList(num_ws_mgc);
41
42
43                                         for(int ws_mgc_index = 0;ws_mgc_index < num_ws_mgc;++ws_mgc_index){
44
45                                                 ws_mgcList.push_back((char *)(const char*)(voiceDataDir + fn_ws_mgc[ws_mgc_index]));
46                                         }
47
48                                         std::vector<Char_P> ws_lf0List(num_ws_lf0);
49
50                                         for(int ws_lf0Index = 0;ws_lf0Index < num_ws_lf0;++ws_lf0Index){
51
52                                                 ws_mgcList.push_back((char *)(const char*)(voiceDataDir + fn_ws_mgc[ws_lf0Index]));
53                                         }
54
55                                         std::vector<Char_P> ws_lpfList(num_ws_lpf);
56
57                                         for(int ws_lpfIndex = 0;ws_lpfIndex < num_ws_lpf;++ws_lpfIndex){
58
59                                                 ws_mgcList.push_back((char *)(const char*)(voiceDataDir + fn_ws_mgc[ws_lpfIndex]));
60                                         }
61
62                                         ::OpenJTalk_load(&this->openJtalk_internal,
63                                                 (char *)(const char*)(dictionaryDataDir),
64                                                 (char *)(const char*)(voiceDataDir +fn_ms_dur),
65                                                 (char *)(const char*)(voiceDataDir +fn_ts_dur),
66                                                 (char *)(const char*)(voiceDataDir +fn_ms_mgc),
67                                                 (char *)(const char*)(voiceDataDir +fn_ts_mgc),
68                                                 &ws_mgcList[0],
69                                                 num_ws_mgc,
70                                                 (char *)(const char*)(voiceDataDir +fn_ms_lf0),
71                                                 (char *)(const char*)(voiceDataDir +fn_ts_lf0),
72                                                 &ws_mgcList[0],
73                                                 num_ws_lf0,
74                                                 (char *)(const char*)(voiceDataDir +fn_ms_lpf),
75                                                 (char *)(const char*)(voiceDataDir +fn_ts_lpf),
76                                                 &ws_lpfList[0],
77                                                 num_ws_lpf,
78                                                 (char *)(const char*)(voiceDataDir +fn_ms_gvm),
79                                                 (char *)(const char*)(voiceDataDir +fn_ts_gvm),
80                                                 (char *)(const char*)(voiceDataDir +fn_ms_gvl),
81                                                 (char *)(const char*)(voiceDataDir +fn_ts_gvl),
82                                                 (char *)(const char*)(voiceDataDir +fn_ms_gvf),
83                                                 (char *)(const char*)(voiceDataDir +fn_ts_gvf),
84                                                 fn_gv_switch
85                                                 );
86                                 }
87 }
88                 
89 void COpenJtalkCore::Synthesis( Char_P txt, FILE * wavfp, FILE * logfp){
90         ::OpenJTalk_synthesis(&this->openJtalk_internal,txt,wavfp,logfp);
91 }
92
93
94 void COpenJtalkCore::Clear(){
95         ::OpenJTalk_clear(&this->openJtalk_internal);
96         this->manageFlag = false;
97 }
98
99 }
100 }