Esempio n. 1
0
        // HTS_Model_load: load pdf and tree
        public bool Load(HTS_File pdf, HTS_File tree, int vector_length, int num_windows, bool is_msd)
        {
            // check
            if (pdf == null || vector_length == 0 || num_windows == 0)
            {
                return(false);
            }

            // reset
            Initialize();

            // load tree
            if (LoadTree(tree) != true)
            {
                Initialize();
                return(false);
            }

            // load pdf
            if (LoadPdf(pdf, vector_length, num_windows, is_msd) != true)
            {
                Initialize();
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        // HTS_fopen_from_fp: wrapper for fopen
        public static HTS_File Create(HTS_File tFp, int tSize)
        {
            if (tFp == null || tSize <= 0)
            {
                return(null);
            }

            //----------------------------------

            if ((tFp.m_Size - tFp.m_Pointer) < tSize)
            {
                // 足りない(失敗)
                tFp.m_Pointer = tFp.m_Size;
                return(null);
            }

            HTS_File tNewFp = new HTS_File();

            tNewFp.m_Data    = new byte[tSize];
            tNewFp.m_Size    = tNewFp.m_Data.Length;
            tNewFp.m_Pointer = 0;

            Array.Copy(tFp.m_Data, tFp.m_Pointer, tNewFp.m_Data, 0, tSize);

            tFp.m_Pointer += tSize;

            return(tNewFp);
        }
Esempio n. 3
0
        // HTS_fopen_from_data: wrapper for fopen
        public static HTS_File Create(byte[] tData)
        {
            if (tData == null || tData.Length <= 0)
            {
                return(null);
            }

            //----------------------------------

            HTS_File tNewFp = new HTS_File();

            // ここにファイルから取得したデータを格納する
            tNewFp.m_Data    = tData;
            tNewFp.m_Size    = tNewFp.m_Data.Length;
            tNewFp.m_Pointer = 0;

            return(tNewFp);
        }
Esempio n. 4
0
        //---------------------------------------------------------

        // HTS_fopen_from_fn: wrapper for fopen
        public static HTS_File Open(string tPath)
        {
            if (OpenJTalk_StorageAccessor.Exists(tPath) != OpenJTalk_StorageAccessor.Target.File)
            {
                return(null);
            }

            //----------------------------------

            HTS_File tNewFp = new HTS_File();

            // ここにファイルから取得したデータを格納する
            tNewFp.m_Data    = OpenJTalk_StorageAccessor.Load(tPath);
            tNewFp.m_Size    = tNewFp.m_Data.Length;
            tNewFp.m_Pointer = 0;

            return(tNewFp);
        }
Esempio n. 5
0
        //-----------------------------------------------------------

        // 複数の音響モデルを同時にロード出来る
        public bool Load(string[] voices)
        {
            int tNumericOfVoice = voices.Length;

            int      i, j, k, s, e;
            bool     error = false;
            HTS_File fp    = null;
            int      matched_size;

            string[] stream_type_list = null;

            int[]  vector_length = null;
            bool[] is_msd        = null;
            int[]  num_windows   = null;
            bool[] use_gv        = null;

            string gv_off_context = null;

            // temporary values
            string tHtsVoiceVersion;
            int    temp_sampling_frequency;
            int    temp_frame_period;
            int    temp_num_states;
            int    temp_num_streams;
            string temp_stream_type;
            string temp_fullcontext_format;
            string temp_fullcontext_version;

            string temp_gv_off_context;

            int[]    temp_vector_length;
            bool[]   temp_is_msd;
            int[]    temp_num_windows;
            bool[]   temp_use_gv;
            string[] temp_option;

            string temp_duration_pdf;
            string temp_duration_tree;

            string[][] temp_stream_win;
            string[]   temp_stream_pdf;
            string[]   temp_stream_tree;
            string[]   temp_gv_pdf;
            string[]   temp_gv_tree;

            int      start_of_data;
            HTS_File pdf_fp  = null;
            HTS_File tree_fp = null;

            HTS_File[] win_fp            = null;
            HTS_File   gv_off_context_fp = null;

            Initialize();

            if (voices == null || tNumericOfVoice < 1)
            {
                return(false);
            }

            m_NumericOfVoice = tNumericOfVoice;

            for (i = 0; i < m_NumericOfVoice && error == false; i++)
            {
                // open file
                fp = HTS_File.Open(voices[i]);
                if (fp == null)
                {
                    error = true;
                    break;
                }

                // reset GLOBAL options
                tHtsVoiceVersion         = null;
                temp_sampling_frequency  = 0;
                temp_frame_period        = 0;
                temp_num_states          = 0;
                temp_num_streams         = 0;
                temp_stream_type         = null;
                temp_fullcontext_format  = null;
                temp_fullcontext_version = null;
                temp_gv_off_context      = null;

                // 0x0D かもしれない
                string tToken = fp.GetTokenFromFpWithSeparator(0x0A);
                string tValue;
                if (string.IsNullOrEmpty(tToken) == true)
                {
                    error = true;
                    break;
                }


                // load GLOBAL options
                if (tToken != "[GLOBAL]")
                {
                    error = true;
                    break;
                }

                while (true)
                {
                    // 0x0D かもしれない
                    tToken = fp.GetTokenFromFpWithSeparator(0x0A);
                    if (string.IsNullOrEmpty(tToken) == true)
                    {
                        error = true;
                        break;
                    }

                    if (tToken == "[STREAM]")
                    {
                        break;
                    }
                    else
                    if (MatchHeadString(tToken, "HTS_VOICE_VERSION:", out tValue) == true)
                    {
                        tHtsVoiceVersion = tValue;
                    }
                    else
                    if (MatchHeadString(tToken, "SAMPLING_FREQUENCY:", out tValue) == true)
                    {
                        int.TryParse(tValue, out temp_sampling_frequency);
                    }
                    else
                    if (MatchHeadString(tToken, "FRAME_PERIOD:", out tValue) == true)
                    {
                        int.TryParse(tValue, out temp_frame_period);
                    }
                    else
                    if (MatchHeadString(tToken, "NUM_STATES:", out tValue) == true)
                    {
                        int.TryParse(tValue, out temp_num_states);
                    }
                    else
                    if (MatchHeadString(tToken, "NUM_STREAMS:", out tValue) == true)
                    {
                        int.TryParse(tValue, out temp_num_streams);
                    }
                    else
                    if (MatchHeadString(tToken, "STREAM_TYPE:", out tValue) == true)
                    {
                        temp_stream_type = tValue;
                    }
                    else
                    if (MatchHeadString(tToken, "FULLCONTEXT_FORMAT:", out tValue) == true)
                    {
                        temp_fullcontext_format = tValue;
                    }
                    else
                    if (MatchHeadString(tToken, "FULLCONTEXT_VERSION:", out tValue) == true)
                    {
                        temp_fullcontext_version = tValue;
                    }
                    else
                    if (MatchHeadString(tToken, "GV_OFF_CONTEXT:", out tValue) == true)
                    {
                        temp_gv_off_context = tValue;
                    }
                    else
                    if (MatchHeadString(tToken, "COMMENT:", out tValue) == true)
                    {
                        if (string.IsNullOrEmpty(tValue) == false)
                        {
                            Debug.Log("COMMENT:" + tValue);
                        }
                    }
                    else
                    {
                        Debug.LogError("HTS_ModelSet_load: Unknown option " + tToken + ".");
                    }
                }

                // check GLOBAL options
                if (i == 0)
                {
                    // 最初の音響モデルの共通パラメータ部分を全音響モデルの正式な共通パラメータとする
                    m_HtsVoiceVersion         = tHtsVoiceVersion;
                    m_SamplingFrequency       = temp_sampling_frequency;
                    m_FramePeriod             = temp_frame_period;
                    m_NumericOfState          = temp_num_states;
                    m_NumericOfStream         = temp_num_streams;
                    m_StreamType              = temp_stream_type;
                    m_FullcontextLabelFormat  = temp_fullcontext_format;
                    m_FullcontextLabelVersion = temp_fullcontext_version;

                    gv_off_context = temp_gv_off_context;
                }
                else
                {
                    // 2つ目以降の音響モデル(共通パラメータに違いがあれば不正なものとする)
                    if (m_HtsVoiceVersion != tHtsVoiceVersion)
                    {
                        error = true;
                    }
                    if (m_SamplingFrequency != temp_sampling_frequency)
                    {
                        error = true;
                    }
                    if (m_FramePeriod != temp_frame_period)
                    {
                        error = true;
                    }
                    if (m_NumericOfState != temp_num_states)
                    {
                        error = true;
                    }
                    if (m_NumericOfStream != temp_num_streams)
                    {
                        error = true;
                    }
                    if (m_StreamType != temp_stream_type)
                    {
                        error = true;
                    }
                    if (m_FullcontextLabelFormat != temp_fullcontext_format)
                    {
                        error = true;
                    }
                    if (m_FullcontextLabelVersion != temp_fullcontext_version)
                    {
                        error = true;
                    }
                    if (gv_off_context != temp_gv_off_context)
                    {
                        error = true;
                    }

                    tHtsVoiceVersion         = null;
                    temp_stream_type         = null;
                    temp_fullcontext_format  = null;
                    temp_fullcontext_version = null;
                    temp_gv_off_context      = null;
                }

                // find stream names
                if (i == 0)
                {
                    // 最初の音響モデルのみチェックする
                    stream_type_list = m_StreamType.Split(',');
                    if (stream_type_list == null || stream_type_list.Length != m_NumericOfStream)
                    {
                        error = true;
                    }
                }

                if (error != false)
                {
                    if (fp != null)
                    {
                        fp.Close();
                        fp = null;
                    }
                    break;
                }

                // 全音響モデルで共通のパラメータ(num_streams)を使って作業領域を確保する

                // reset STREAM options
                temp_vector_length = new    int[m_NumericOfStream];
                temp_is_msd        = new   bool[m_NumericOfStream];
                temp_num_windows   = new    int[m_NumericOfStream];
                temp_use_gv        = new   bool[m_NumericOfStream];
                temp_option        = new string[m_NumericOfStream];

                // load STREAM options
                while (true)
                {
                    // 0x0D の可能性あり
                    tToken = fp.GetTokenFromFpWithSeparator(0x0A);
                    if (string.IsNullOrEmpty(tToken) == true)
                    {
                        error = true;
                        break;
                    }

                    if (tToken == "[POSITION]")
                    {
                        break;
                    }
                    else
                    if (MatchHeadString(tToken, "VECTOR_LENGTH[", out tValue) == true)
                    {
                        string tLabel;
                        if (GetLabelAndValue(tValue, out tLabel, out tValue) == true)
                        {
                            for (j = 0; j < m_NumericOfStream; j++)
                            {
                                if (stream_type_list[j] == tLabel)
                                {
                                    int.TryParse(tValue, out temp_vector_length[j]);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    if (MatchHeadString(tToken, "IS_MSD[", out tValue) == true)
                    {
                        string tLabel;
                        if (GetLabelAndValue(tValue, out tLabel, out tValue) == true)
                        {
                            for (j = 0; j < m_NumericOfStream; j++)
                            {
                                if (stream_type_list[j] == tLabel)
                                {
                                    temp_is_msd[j] = (tValue == "1") ? true : false;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    if (MatchHeadString(tToken, "NUM_WINDOWS[", out tValue) == true)
                    {
                        string tLabel;
                        if (GetLabelAndValue(tValue, out tLabel, out tValue) == true)
                        {
                            for (j = 0; j < m_NumericOfStream; j++)
                            {
                                if (stream_type_list[j] == tLabel)
                                {
                                    int.TryParse(tValue, out temp_num_windows[j]);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    if (MatchHeadString(tToken, "USE_GV[", out tValue) == true)
                    {
                        string tLabel;
                        if (GetLabelAndValue(tValue, out tLabel, out tValue) == true)
                        {
                            for (j = 0; j < m_NumericOfStream; j++)
                            {
                                if (stream_type_list[j] == tLabel)
                                {
                                    temp_use_gv[j] = (tValue == "1") ? true : false;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    if (MatchHeadString(tToken, "OPTION[", out tValue) == true)
                    {
                        string tLabel;
                        if (GetLabelAndValue(tValue, out tLabel, out tValue) == true)
                        {
                            for (j = 0; j < m_NumericOfStream; j++)
                            {
                                if (stream_type_list[j] == tLabel)
                                {
                                    temp_option[j] = tValue;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("HTS_ModelSet_load: Unknown option " + tToken);
                    }
                }

                // check STREAM options
                if (i == 0)
                {
                    // 最初の音響モデル
                    vector_length = temp_vector_length;
                    is_msd        = temp_is_msd;
                    num_windows   = temp_num_windows;
                    use_gv        = temp_use_gv;
                    m_Option      = temp_option;
                }
                else
                {
                    // 2つ目以降の音響モデル(値が最初の音響モデルと同じになっているかチェックする)
                    for (j = 0; j < m_NumericOfStream; j++)
                    {
                        if (vector_length[j] != temp_vector_length[j])
                        {
                            error = true;
                        }
                    }

                    for (j = 0; j < m_NumericOfStream; j++)
                    {
                        if (is_msd[j] != is_msd[j])
                        {
                            error = true;
                        }
                    }

                    for (j = 0; j < m_NumericOfStream; j++)
                    {
                        if (num_windows[j] != temp_num_windows[j])
                        {
                            error = true;
                        }
                    }

                    for (j = 0; j < m_NumericOfStream; j++)
                    {
                        if (use_gv[j] != temp_use_gv[j])
                        {
                            error = true;
                        }
                    }

                    for (j = 0; j < m_NumericOfStream; j++)
                    {
                        if (m_Option[j] != temp_option[j])
                        {
                            error = true;
                        }
                    }

                    temp_vector_length = null;
                    temp_is_msd        = null;
                    temp_num_windows   = null;
                    temp_use_gv        = null;

                    for (j = 0; j < m_NumericOfStream; j++)
                    {
                        if (temp_option[j] != null)
                        {
                            temp_option[j] = null;
                        }
                    }
                    temp_option = null;
                }
                if (error != false)
                {
                    if (fp != null)
                    {
                        fp.Close();
                        fp = null;
                    }
                    break;
                }

                // reset POSITION
                temp_duration_pdf  = null;
                temp_duration_tree = null;
                temp_stream_win    = new string[m_NumericOfStream][];
                for (j = 0; j < m_NumericOfStream; j++)
                {
                    temp_stream_win[j] = new string[num_windows[j]];
                }
                temp_stream_pdf  = new string[m_NumericOfStream];
                temp_stream_tree = new string[m_NumericOfStream];
                temp_gv_pdf      = new string[m_NumericOfStream];
                temp_gv_tree     = new string[m_NumericOfStream];

                // load POSITION
                while (true)
                {
                    tToken = fp.GetTokenFromFpWithSeparator(0x0A);

                    if (string.IsNullOrEmpty(tToken) == true)
                    {
                        error = true;
                        break;
                    }

                    if (tToken == "[DATA]")
                    {
                        break;
                    }
                    else
                    if (MatchHeadString(tToken, "DURATION_PDF:", out tValue) == true)
                    {
                        temp_duration_pdf = tValue;
                    }
                    else
                    if (MatchHeadString(tToken, "DURATION_TREE:", out tValue) == true)
                    {
                        temp_duration_tree = tValue;
                    }
                    else
                    if (MatchHeadString(tToken, "STREAM_WIN[", out tValue) == true)
                    {
                        string tLabel;
                        if (GetLabelAndValue(tValue, out tLabel, out tValue) == true)
                        {
                            for (j = 0; j < m_NumericOfStream; j++)
                            {
                                if (stream_type_list[j] == tLabel)
                                {
                                    string[] tValues = tValue.Split(',');
                                    if (tValues != null && tValues.Length == num_windows[j])
                                    {
                                        for (k = 0; k < num_windows[j]; k++)
                                        {
                                            temp_stream_win[j][k] = tValues[k];
                                        }
                                    }
                                    else
                                    {
                                        error = true;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    else
                    if (MatchHeadString(tToken, "STREAM_PDF[", out tValue) == true)
                    {
                        string tLabel;
                        if (GetLabelAndValue(tValue, out tLabel, out tValue) == true)
                        {
                            for (j = 0; j < m_NumericOfStream; j++)
                            {
                                if (stream_type_list[j] == tLabel)
                                {
                                    temp_stream_pdf[j] = tValue;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    if (MatchHeadString(tToken, "STREAM_TREE[", out tValue) == true)
                    {
                        string tLabel;
                        if (GetLabelAndValue(tValue, out tLabel, out tValue) == true)
                        {
                            for (j = 0; j < m_NumericOfStream; j++)
                            {
                                if (stream_type_list[j] == tLabel)
                                {
                                    temp_stream_tree[j] = tValue;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    if (MatchHeadString(tToken, "GV_PDF[", out tValue) == true)
                    {
                        string tLabel;
                        if (GetLabelAndValue(tValue, out tLabel, out tValue) == true)
                        {
                            for (j = 0; j < m_NumericOfStream; j++)
                            {
                                if (stream_type_list[j] == tLabel)
                                {
                                    temp_gv_pdf[j] = tValue;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    if (MatchHeadString(tToken, "GV_TREE[", out tValue) == true)
                    {
                        string tLabel;
                        if (GetLabelAndValue(tValue, out tLabel, out tValue) == true)
                        {
                            for (j = 0; j < m_NumericOfStream; j++)
                            {
                                if (stream_type_list[j] == tLabel)
                                {
                                    temp_gv_tree[j] = tValue;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("HTS_ModelSet_load: Unknown option " + tToken);
                    }
                }

                // check POSITION
                if (temp_duration_pdf == null)
                {
                    error = true;
                }

                for (j = 0; j < m_NumericOfStream; j++)
                {
                    for (k = 0; k < num_windows[j]; k++)
                    {
                        if (temp_stream_win[j][k] == null)
                        {
                            error = true;
                        }
                    }
                }

                for (j = 0; j < m_NumericOfStream; j++)
                {
                    if (temp_stream_pdf[j] == null)
                    {
                        error = true;
                    }
                }

                // prepare memory
                if (i == 0)
                {
                    // 最初の音響モデル
                    m_Duration = new HTS_Model[m_NumericOfVoice];
                    for (j = 0; j < m_NumericOfVoice; j++)
                    {
                        m_Duration[j] = new HTS_Model();
                    }

                    m_Window = new HTS_Window[m_NumericOfStream];
                    for (j = 0; j < m_NumericOfStream; j++)
                    {
                        m_Window[j] = new HTS_Window();
                    }

                    m_Stream = new HTS_Model[m_NumericOfVoice][];
                    for (j = 0; j < m_NumericOfVoice; j++)
                    {
                        m_Stream[j] = new HTS_Model[m_NumericOfStream];
                        for (k = 0; k < m_NumericOfStream; k++)
                        {
                            m_Stream[j][k] = new HTS_Model();
                        }
                    }

                    m_Gv = new  HTS_Model[m_NumericOfVoice][];
                    for (j = 0; j < m_NumericOfVoice; j++)
                    {
                        m_Gv[j] = new HTS_Model[m_NumericOfStream];
                        for (k = 0; k < m_NumericOfStream; k++)
                        {
                            m_Gv[j][k] = new HTS_Model();
                        }
                    }
                }
                start_of_data = fp.Tell();

                // load duration
                pdf_fp  = null;
                tree_fp = null;

                if (GetDuration(temp_duration_pdf, out s, out e) == true)
                {
                    fp.Seek(s, HTS_File.SEEK_CUR);
                    pdf_fp = HTS_File.Create(fp, e - s + 1);
                    fp.Seek(start_of_data, HTS_File.SEEK_SET);
                }

                if (GetDuration(temp_duration_tree, out s, out e) == true)
                {
                    fp.Seek(s, HTS_File.SEEK_CUR);
                    tree_fp = HTS_File.Create(fp, e - s + 1);
                    fp.Seek(start_of_data, HTS_File.SEEK_SET);
                }

                // ここの音響モデルのパラメータを展開する
                if (m_Duration[i].Load(pdf_fp, tree_fp, m_NumericOfState, 1, false) != true)
                {
                    error = true;
                }

                pdf_fp.Close();
                tree_fp.Close();

                // load windows(窓は複数の音響モデルで共有?)
                for (j = 0; j < m_NumericOfStream; j++)
                {
                    win_fp = new HTS_File[num_windows[j]];
                    for (k = 0; k < num_windows[j]; k++)
                    {
                        matched_size = 0;
                        if (GetTokenFromStringWithSeparator(temp_stream_win[j][k], ref matched_size, out tToken, '-') == true)
                        {
                            int.TryParse(tToken, out s);
                            tToken = temp_stream_win[j][k].Substring(matched_size);
                            int.TryParse(tToken, out e);

                            fp.Seek(s, HTS_File.SEEK_CUR);
                            win_fp[k] = HTS_File.Create(fp, e - s + 1);
                            fp.Seek(start_of_data, HTS_File.SEEK_SET);
                        }
                    }

                    if (m_Window[j].Load(win_fp, num_windows[j]) == false)
                    {
                        Debug.LogError("Model.Load Error : Window");
                        error = true;
                    }

//					for( k  = 0 ; k <  num_windows[ j ] ; k ++ )
//					{
//						if( win_fp[ k ] != null )
//						{
//							win_fp[ k ].Close() ;
//						}
//					}

                    win_fp = null;
                }

                // load streams
                for (j = 0; j < m_NumericOfStream; j++)
                {
                    pdf_fp  = null;
                    tree_fp = null;

                    matched_size = 0;
                    if (GetTokenFromStringWithSeparator(temp_stream_pdf[j], ref matched_size, out tToken, '-') == true)
                    {
                        int.TryParse(tToken, out s);
                        tToken = temp_stream_pdf[j].Substring(matched_size);
                        int.TryParse(tToken, out e);

                        fp.Seek(s, HTS_File.SEEK_CUR);
                        pdf_fp = HTS_File.Create(fp, e - s + 1);
                        fp.Seek(start_of_data, HTS_File.SEEK_SET);
                    }

                    matched_size = 0;
                    if (GetTokenFromStringWithSeparator(temp_stream_tree[j], ref matched_size, out tToken, '-') == true)
                    {
                        int.TryParse(tToken, out s);
                        tToken = temp_stream_tree[j].Substring(matched_size);
                        int.TryParse(tToken, out e);

                        fp.Seek(s, HTS_File.SEEK_CUR);
                        tree_fp = HTS_File.Create(fp, e - s + 1);
                        fp.Seek(start_of_data, HTS_File.SEEK_SET);
                    }

                    // i は音響モデルインデックス番号
                    if (m_Stream[i][j].Load(pdf_fp, tree_fp, vector_length[j], num_windows[j], is_msd[j]) != true)
                    {
                        Debug.LogError("Model.Load Error");
                        error = true;
                    }

                    if (pdf_fp != null)
                    {
                        pdf_fp.Close();
                    }
                    if (tree_fp != null)
                    {
                        tree_fp.Close();
                    }

                    // 複数の音響モデルのロードループ閉じ
                }

                // load GVs
                for (j = 0; j < m_NumericOfStream; j++)
                {
                    pdf_fp  = null;
                    tree_fp = null;

                    matched_size = 0;
                    if (GetTokenFromStringWithSeparator(temp_gv_pdf[j], ref matched_size, out tToken, '-') == true)
                    {
                        int.TryParse(tToken, out s);
                        tToken = temp_gv_pdf[j].Substring(matched_size);
                        int.TryParse(tToken, out e);

                        fp.Seek(s, HTS_File.SEEK_CUR);
                        pdf_fp = HTS_File.Create(fp, e - s + 1);
                        fp.Seek(start_of_data, HTS_File.SEEK_SET);
                    }

                    matched_size = 0;
                    if (GetTokenFromStringWithSeparator(temp_gv_tree[j], ref matched_size, out tToken, '-') == true)
                    {
                        int.TryParse(tToken, out s);
                        tToken = temp_gv_tree[j].Substring(matched_size);
                        int.TryParse(tToken, out e);

                        fp.Seek(s, HTS_File.SEEK_CUR);
                        tree_fp = HTS_File.Create(fp, e - s + 1);
                        fp.Seek(start_of_data, HTS_File.SEEK_SET);
                    }

                    if (use_gv[j] == true)
                    {
                        if (m_Gv[i][j].Load(pdf_fp, tree_fp, vector_length[j], 1, false) != true)
                        {
                            Debug.LogError("Model.Load Error");
                            error = true;
                        }
                    }

                    if (pdf_fp != null)
                    {
                        pdf_fp.Close();
                    }
                    if (tree_fp != null)
                    {
                        tree_fp.Close();
                    }
                }

                // free
                temp_duration_pdf  = null;
                temp_duration_tree = null;
                temp_stream_win    = null;
                temp_stream_pdf    = null;
                temp_stream_tree   = null;
                temp_gv_pdf        = null;
                temp_gv_tree       = null;

                // fclose
                if (fp != null)
                {
                    fp.Close();
                    fp = null;
                }

                if (error != false)
                {
                    Debug.LogError("Error");
                    break;
                }
            }

            if (gv_off_context != null)
            {
//				sprintf( buff1, "GV-Off { %s }", gv_off_context ) ;
                string ts = "GV-Off { " + gv_off_context + " }";
//				int tl = tb.Length ;
//				if( tl >  ( buff1.Length - 1 ) )
//				{
//					tl  = ( buff1.Length - 1 ) ;
//				}
//				Array.Copy( tb, 0, buff1, 0, tl ) ;
//				buff1[ tl ] = 0 ;

//				gv_off_context_fp = HTS_File.OpenFromData( buff1, HTS_Misc.Strlen( buff1 ) + 1 ) ;
                gv_off_context_fp = HTS_File.Create(ts);

                m_GvOffContext = new HTS_Question();
                if (m_GvOffContext.Load(gv_off_context_fp) == false)
                {
                    Debug.LogError("gv_off_context.Load Error : " + ts);
                }

                gv_off_context_fp.Close();
                gv_off_context = null;
            }

            stream_type_list = null;
            vector_length    = null;
            is_msd           = null;
            num_windows      = null;
            use_gv           = null;

            return(!error);
        }
Esempio n. 6
0
        // HTS_Question_load: Load questions from file
        public bool Load(HTS_File fp)
        {
            if (fp == null)
            {
                return(false);
            }

            string tToken;

            HTS_Pattern pattern, last_pattern;

            Initialize();

            // get question name
            m_Word = fp.GetPatternToken();

            if (string.IsNullOrEmpty(m_Word) == true)
            {
                return(false);
            }

            // get pattern list
            tToken = fp.GetPatternToken();
            if (string.IsNullOrEmpty(tToken) == true)
            {
                Initialize();
                return(false);
            }

            last_pattern = null;
            if (tToken == "{")
            {
                while (true)
                {
                    tToken = fp.GetPatternToken();
                    if (string.IsNullOrEmpty(tToken) == true)
                    {
                        Initialize();
                        return(false);
                    }

                    pattern = new HTS_Pattern();
                    if (m_Head != null)
                    {
                        last_pattern.next = pattern;
                    }
                    else
                    {
                        // first time
                        m_Head = pattern;
                    }

                    pattern.word = tToken;
                    pattern.next = null;

                    tToken = fp.GetPatternToken();
                    if (string.IsNullOrEmpty(tToken) == true)
                    {
                        Initialize();
                        return(false);
                    }

                    if (tToken == "}")
                    {
                        break;
                    }

                    last_pattern = pattern;
                }
            }

            return(true);
        }
Esempio n. 7
0
        // HTS_Model_load_tree: load trees
        private bool LoadTree(HTS_File fp)
        {
            string tToken;

            HTS_Question question, last_question;
            HTS_Tree     tree, last_tree;
            int          state;

            // check
            if (fp == null)
            {
                ntree = 1;
                return(true);
            }

            ntree         = 0;
            last_question = null;
            last_tree     = null;

            while (fp.Eof() == false)
            {
                tToken = fp.GetPatternToken();

                // parse questions
                if (tToken == "QS")
                {
                    question = new HTS_Question();

                    if (question.Load(fp) == false)
                    {
                        Debug.LogError("Question Load falied");
                        question = null;
                        Initialize();
                        return(false);
                    }

                    if (this.question != null)
                    {
                        last_question.next = question;
                    }
                    else
                    {
                        this.question = question;
                    }

                    question.next = null;
                    last_question = question;
                }
                else
                {
                    // tToken が "QE" の場合に更新される事は無いので排他で良い
                    // parse trees
                    state = GetStateNum(tToken);
                    if (state != 0)
                    {
                        tree       = new HTS_Tree();
                        tree.state = state;
                        tree.ParsePattern(tToken);

                        if (tree.Load(fp, this.question) == false)
                        {
                            Debug.LogError("Tree Load falied");
                            tree = null;
                            Initialize();
                            return(false);
                        }

                        if (this.tree != null)
                        {
                            last_tree.next = tree;
                        }
                        else
                        {
                            this.tree = tree;
                        }

                        tree.next = null;
                        last_tree = tree;
                        this.ntree++;
                    }
                    else
                    {
                        Debug.LogWarning("Bad:" + tToken);
                    }
                }
            }

            // No Tree information in tree file
            if (this.tree == null)
            {
                this.ntree = 1;
            }

            return(true);
        }
Esempio n. 8
0
        // HTS_Model_load_pdf: load pdfs
        private bool LoadPdf(HTS_File fp, int vector_length, int num_windows, bool is_msd)
        {
            int[] i = { 0 };
            int   j, k;
            bool  result = true;
            int   len;

            // check
            if (fp == null || this.ntree <= 0)
            {
                Debug.LogError("HTS_Model_load_pdf: File for pdfs is not specified.");
                return(false);
            }

            // read MSD flag
            this.vector_length = vector_length;
            this.num_windows   = num_windows;
            this.is_msd        = is_msd;
            this.npdf          = new int[this.ntree];
//			this.npdf			-= 2 ;	// オフセットのズレが生じる模様
            this.npdf_o = -2;

            // read the number of pdfs
            for (j = 2; j <= this.ntree + 1; j++)
            {
                if (fp.ReadLittleEndian(i, sizeof(int), 1) != 1)
                {
                    result = false;
                    break;
                }
//				this.npdf[ j ] = i ;

                this.npdf[this.npdf_o + j] = i[0];                      // オフセットのズレが生じる模様
            }

            for (j = 2; j <= this.ntree + 1; j++)
            {
//				if( this.npdf[ j ] <= 0 )
                if (this.npdf[this.npdf_o + j] <= 0)                            // オフセットのズレが生じる模様
                {
                    Debug.LogError("HTS_Model_load_pdf: # of pdfs at " + j + "-th state should be positive.");
                    result = false;
                    break;
                }
            }

            if (result == false)
            {
//				this.npdf += 2 ;	// オフセットのズレを元に戻している
                this.npdf = null;
                Initialize();
                return(false);
            }

            this.pdf = new float[this.ntree][][];
//			this.pdf -= 2 ;			// オフセットのズレが生じる模様
            this.pdf_o   = -2;
            this.pdf_o_o = new int[this.ntree];

            // read means and variances
            if (is_msd == true)
            {
                // for MSD
                len = this.vector_length * this.num_windows * 2 + 1;
            }
            else
            {
                len = this.vector_length * this.num_windows * 2;
            }

            for (j = 2; j <= this.ntree + 1; j++)
            {
//				this.pdf[ j ] = new float[ this.npdf[ j ] ][] ;
                this.pdf[this.pdf_o + j] = new float[this.npdf[this.npdf_o + j]][];                             // オフセットのズレが生じる模様

//				this.pdf[ j ] -- ;	// オフセットのズレが生じる模様
                this.pdf_o_o[this.pdf_o + j] = -1;

//				for( k  = 1 ; k <= this.npdf[ j ] ; k ++ )
                for (k = 1; k <= this.npdf[this.npdf_o + j]; k++)                                       // オフセットのズレが生じる模様
                {
//					this.pdf[ j ][ k ] = new float[ len ] ;
                    this.pdf[this.pdf_o + j][this.pdf_o_o[this.pdf_o + j] + k] = new float[len];                                        // オフセットのズレが生じる模様
                    if (fp.ReadLittleEndian(this.pdf[this.pdf_o + j][this.pdf_o_o[this.pdf_o + j] + k], sizeof(float), len) != len)
                    {
                        result = false;
                    }
                }
            }

            if (result == false)
            {
                Initialize();
                return(false);
            }

            return(true);
        }
Esempio n. 9
0
        // HTS_Tree_load: load trees
        public bool Load(HTS_File fp, HTS_Question question)
        {
            string tToken;

            HTS_Node node, last_node;

            if (fp == null)
            {
                return(false);
            }

            tToken = fp.GetPatternToken();
            if (string.IsNullOrEmpty(tToken) == true)
            {
                Initialize();
                return(false);
            }

            node = new HTS_Node();

            this.root = last_node = node;

            if (tToken == "{")
            {
                int v;

                tToken = fp.GetPatternToken();
                while (string.IsNullOrEmpty(tToken) == false && tToken != "}")
                {
                    int.TryParse(tToken, out v);
                    node = HTS_Node.Find(last_node, v);
                    if (node == null)
                    {
                        Debug.LogError("HTS_Tree_load: Cannot find node " + v + " .");
                        Initialize();
                        return(false);
                    }

                    tToken = fp.GetPatternToken();
                    if (string.IsNullOrEmpty(tToken) == true)
                    {
                        Initialize();
                        return(false);
                    }

                    node.quest = HTS_Question.Find(question, tToken);
                    if (node.quest == null)
                    {
                        Debug.LogError("HTS_Tree_load: Cannot find question " + tToken + ".");
                        Initialize();
                        return(false);
                    }

                    node.yes = new HTS_Node();
                    node.no  = new HTS_Node();

                    tToken = fp.GetPatternToken();
                    if (string.IsNullOrEmpty(tToken) == true)
                    {
                        node.quest = null;
                        node.yes   = null;
                        node.no    = null;
                        Initialize();
                        return(false);
                    }

                    if (IsNum(tToken) == true)
                    {
                        int.TryParse(tToken, out v);
                        node.no.index = v;
                    }
                    else
                    {
                        node.no.pdf = Name2num(tToken);
                    }
                    node.no.next = last_node;
                    last_node    = node.no;

                    tToken = fp.GetPatternToken();
                    if (string.IsNullOrEmpty(tToken) == true)
                    {
                        node.quest = null;
                        node.yes   = null;
                        node.no    = null;
                        Initialize();
                        return(false);
                    }

                    if (IsNum(tToken) == true)
                    {
                        int.TryParse(tToken, out v);
                        node.yes.index = v;
                    }
                    else
                    {
                        node.yes.pdf = Name2num(tToken);
                    }
                    node.yes.next = last_node;
                    last_node     = node.yes;

                    // 最後
                    tToken = fp.GetPatternToken();
                }
            }
            else
            {
                node.pdf = Name2num(tToken);
            }

            return(true);
        }