/// <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);
    }
        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);
        }
Example #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));
        }
Example #4
0
        public string GetYomi(string str)
        {
            string yomi = String.Empty;
            Guid   pclsid;
            int    res;

            // 文字列の CLSID から CLSID へのポインタを取得する
            res = CLSIDFromString("MSIME.Japan", out pclsid);

            if (res != S_OK)
            {
                this.Dispose();
                return(yomi);
            }

            Guid   riid = new Guid("019F7152-E6DB-11D0-83C3-00C04FDDB82E ");
            IntPtr ppv;

            res = CoCreateInstance(pclsid, IntPtr.Zero, CLSCTX_SERVER, riid, out ppv);

            if (res != S_OK)
            {
                this.Dispose();
                return(yomi);
            }

            IFELanguage language = Marshal.GetTypedObjectForIUnknown(ppv, typeof(IFELanguage)) as IFELanguage;

            res = language.Open();

            if (res != S_OK)
            {
                this.Dispose();
                return(yomi);
            }

            IntPtr result;

            res = language.GetJMorphResult(FELANG_REQ_REV, FELANG_CMODE_PINYIN | FELANG_CMODE_NOINVISIBLECHAR,
                                           str.Length, str, IntPtr.Zero, out result);

            if (res != S_OK)
            {
                this.Dispose();
                return(yomi);
            }

            yomi = Marshal.PtrToStringUni(Marshal.ReadIntPtr(result, 4), Marshal.ReadInt16(result, 8));

            language.Close();

            return(yomi);
        }
Example #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);
            }
        }
Example #6
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();
            }
        }
Example #7
0
 public void Dispose()
 {
     if (language != null)
     {
         try
         {
             language.Close();
         }
         catch (InvalidCastException)
         {
             // どうでもよさそうなところだが例外が出る時があるので握りつぶす
         }
         finally
         {
             language = null;
             if (FInitialized)
             {
                 DisposeCom();
             }
             GC.SuppressFinalize(this);
         }
     }
 }
Example #8
0
        public void ZhunYin(string input)
        {
            if (!coInitialized)
            {
                CoInitialize(IntPtr.Zero);

                coInitialized = true;
            }



            //textBox2.Clear();

            Guid vGuidIme;

            int vError;

            vError = CLSIDFromString("MSIME.China", out vGuidIme);

            if (vError != S_OK)
            {
                throw new Exception(GetMessage(vError));

                return;
            }

            Guid vGuidLanguage = new Guid("019F7152-E6DB-11D0-83C3-00C04FDDB82E");

            IntPtr vPPV;

            vError = CoCreateInstance(vGuidIme, IntPtr.Zero, CLSCTX_SERVER,

                                      vGuidLanguage, out vPPV);

            if (vError != S_OK)
            {
                //MessageBox.Show(GetMessage(vError));

                return;
            }

            IFELanguage vLanguage =

                Marshal.GetTypedObjectForIUnknown(vPPV, typeof(IFELanguage)) as IFELanguage;

            vError = vLanguage.Open();

            if (vError != S_OK)
            {
                //MessageBox.Show(GetMessage(vError));

                return;
            }

            IntPtr vMorrslt;

            string vInput = "中文";//textBox1.Text;

            vError = vLanguage.GetJMorphResult(FELANG_REQ_REV,

                                               FELANG_CMODE_PINYIN | FELANG_CMODE_NOINVISIBLECHAR,

                                               vInput.Length, vInput, IntPtr.Zero, out vMorrslt);

            if (vError != S_OK)
            {
                //MessageBox.Show(GetMessage(vError));

                return;
            }

            string vPinYin = Marshal.PtrToStringUni(Marshal.ReadIntPtr(vMorrslt, 4),

                                                    Marshal.ReadInt16(vMorrslt, 8));

            //textBox2.AppendText("=" + vPinYin  + "\r\n");

            IntPtr vMonoRubyPos = Marshal.ReadIntPtr(vMorrslt, 28);

            IntPtr vReadIdxWDD = Marshal.ReadIntPtr(vMorrslt, 24);

            int iReadIdxWDD = 0;

            int iMonoRubyPos = Marshal.ReadInt16(vMonoRubyPos);

            vMonoRubyPos = (IntPtr)((int)vMonoRubyPos + 2);

            int i = 0;

            while (i < vInput.Length)
            {
                while (i < Marshal.ReadInt16(vReadIdxWDD))
                {
                    i++;

                    if (i >= Marshal.ReadInt16(vReadIdxWDD))
                    {
                        Console.WriteLine(Marshal.ReadInt16(vMonoRubyPos));

                        string s = vPinYin.Substring(iMonoRubyPos,

                                                     Marshal.ReadInt16(vMonoRubyPos) - iMonoRubyPos);

                        if (s != string.Empty)
                        {
                            s = vInput.Substring(iReadIdxWDD, i - iReadIdxWDD) + "(" + s + ")";
                        }

                        else
                        {
                            s = vInput.Substring(iReadIdxWDD, i - iReadIdxWDD);
                        }

                        //textBox2.AppendText(s + "\r\n");

                        iReadIdxWDD = i;

                        iMonoRubyPos = Marshal.ReadInt16(vMonoRubyPos);

                        break;
                    }

                    vMonoRubyPos = (IntPtr)((int)vMonoRubyPos + 2);

                    vReadIdxWDD = (IntPtr)((int)vReadIdxWDD + 2);
                }

                vMonoRubyPos = (IntPtr)((int)vMonoRubyPos + 2);

                vReadIdxWDD = (IntPtr)((int)vReadIdxWDD + 2);
            }

            CoTaskMemFree(vMorrslt);

            vLanguage.Close();
        }