Exemplo n.º 1
0
        static public string ConvertYomigana(string str)
        {
            IFELanguage ifelang = null;
            string      yomigana;

            try
            {
                ifelang = Activator.CreateInstance(Type.GetTypeFromProgID("MSIME.Japan")) as IFELanguage;
                int hr = ifelang.Open();
                if (hr != 0)
                {
                    throw Marshal.GetExceptionForHR(hr);
                }
                hr = ifelang.GetPhonetic(str, 1, -1, out yomigana);
                if (hr != 0)
                {
                    throw Marshal.GetExceptionForHR(hr);
                }

                ifelang.Close();
            }
            catch (COMException ex)
            {
                if (ifelang != null)
                {
                    ifelang.Close();
                }
                throw ex;
            }

            return(yomigana);
        }
    /// <summary>
    /// テキストイベントの文字数に応じて、イベントの長さを求めるメソッド
    /// https://www.pine4.net/Memo/Article/Archives/424
    /// </summary>
    /// <param name="textEvent">変更するTrackEvent</param>
    /// <returns>length of event</returns>
    double CalculateEventLengthBasedOnWordCount(TrackEvent textEvent)
    {
        string      takeName    = textEvent.ActiveTake.Name.Remove(0, TitleNamePrefix.Length);
        IFELanguage ifelang     = null;
        string      allKanaName = String.Empty;

        try
        {
            ifelang = Activator.CreateInstance(Type.GetTypeFromProgID("MSIME.Japan")) as IFELanguage;
            int hr = ifelang.Open();

            if (hr != 0)
            {
                throw Marshal.GetExceptionForHR(hr);
            }

            hr = ifelang.GetPhonetic(takeName, 1, -1, out allKanaName);
            ifelang.Close();
        }
        catch (COMException ex)
        {
            if (ifelang != null)
            {
                ifelang.Close();
            }
        }

        int commaNumber = CountChar(allKanaName, ',') + CountChar(allKanaName, '、');
        int spaceNumber = CountChar(allKanaName, ' ') + CountChar(allKanaName, ' ');

        return((allKanaName.Length - commaNumber - spaceNumber) * TimePerWordCountms + commaNumber * TimePerCommams + ExtraTimems);
    }
Exemplo n.º 3
0
        private Stream ByIME()
        {
            IFELanguage fel = Activator.CreateInstance(Type.GetTypeFromProgID("MSIME.Japan")) as IFELanguage;

            fel.Open();
            string kana = fel.GetPhonetic(textbox.Text, 1, -1);

            fel.Close();
            if (kana == null)
            {
                throw new Exception("文章が長すぎるか、平仮名に変換できません。\n短くシンプルな文章に変更してください。\n\n");
            }

            List <Stream> srcs = new List <Stream>();

            foreach (char c in kana)
            {
                if (kana50.ContainsKey(c.ToString()))
                {
                    srcs.Add(kana50[c.ToString()]);
                }
            }

            if (srcs.Count <= 0)
            {
                srcs.Add(kana50["ん"]);
            }

            return(Concat(srcs));
        }
Exemplo n.º 4
0
        public String GetYomi(String src)
        {
            IFELanguage fel = (IFELanguage)Activator.CreateInstance(Type.GetTypeFromProgID(ProgID));

            fel.Open();
            try {
                IntPtr phonetic;
                fel.GetPhonetic(src, 1, -1, out phonetic);
                try {
                    return(Marshal.PtrToStringBSTR(phonetic));
                }
                finally {
                    Marshal.FreeBSTR(phonetic);
                }
            }
            finally {
                fel.Close();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input">計測したい文字列</param>
        /// <returns></returns>
        /// public static double GetVoiceTime(string input)
        /// {
        ///     double dOut = 0d;
        ///     ServiceControl.StartHost(true);
        ///
        ///     Talker talker = new Talker();
        ///
        ///     // キャスト設定
        ///     talker.Cast = "すずきつづみ";
        ///
        ///     // (例)音量設定
        ///     talker.Volume = 100;
        ///
        ///     dOut = talker.GetTextDuration(input);
        ///
        ///     // ServiceControl.CloseHost();
        ///     // talker.Dispse
        ///
        ///     return dOut;
        /// }

        /*
         * public static bool RemoveFileDirectory(string inputPath)
         * {
         *  try
         *  {
         *      DirectoryInfo target = new DirectoryInfo(inputPath);
         *      //ファイル消す
         *      foreach (FileInfo file in target.GetFiles())
         *      {
         *          file.Delete();
         *      }
         *      //フォルダも消す
         *      foreach (DirectoryInfo dir in target.GetDirectories())
         *      {
         *          dir.Delete(true);
         *      }
         *
         *      return true;
         *  }
         *  catch (Exception ex)
         *  {
         *      return false;
         *  }
         * }
         */
        #endregion

        public static string OutputYomigana(string text)
        {
            IFELanguage ifelang = null;
            string      stryomi = "";

            try
            {
                ifelang = Activator.CreateInstance(Type.GetTypeFromProgID("MSIME.Japan")) as IFELanguage;
                int hr = ifelang.Open();
                if (hr != 0)
                {
                    throw Marshal.GetExceptionForHR(hr);
                }
                //string yomigana;
                hr = ifelang.GetPhonetic(text, 1, -1, out string yomigana);
                if (hr != 0)
                {
                    throw Marshal.GetExceptionForHR(hr);
                }
                else
                {
                    stryomi = yomigana;
                }
                //uint mode = 0;
                //ifelang.GetConversionModeCaps(ref mode);
                ifelang.Close();

                return(stryomi);
            }
            catch (COMException ex)
            {
                if (ifelang != null)
                {
                    ifelang.Close();
                }
                return(stryomi);
            }
        }