/// <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);
    }
예제 #2
0
        /// <summary>
        /// 初期化する
        /// </summary>
        public void Initialize()
        {
            lock (lockObject)
            {
                try
                {
                    if (this.IFELang == null)
                    {
                        this.IFELang = Activator.CreateInstance(Type.GetTypeFromProgID("MSIME.Japan")) as IFELanguage;

                        if (this.IFELang == null)
                        {
                            this.Logger.Warn("IFELANG IME initialize failed. Disabled IME reverse translation.");
                        }
                        else
                        {
                            var hr = this.IFELang.Open();
                            if (hr != 0)
                            {
                                this.Logger.Warn("IFELANG IME connection failed. Disabled IME reverse translation.");
                                this.IFELang = null;
                            }

                            this.Logger.Trace("IFELANG IME Connected.");
                        }
                    }
                }
                catch (Exception)
                {
                    this.Logger.Warn("IFELANG IME initialize failed due to an unexpected exception. Disabled IME reverse translation.");
                    this.IFELang = null;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 初期化する
        /// </summary>
        public void Initialize()
        {
            lock (lockObject)
            {
                if (this.IFELang == null)
                {
                    this.IFELang = Activator.CreateInstance(Type.GetTypeFromProgID("MSIME.Japan")) as IFELanguage;

                    if (this.IFELang == null)
                    {
                        this.Logger.Error("IFELANG IME initialize faild.");
                    }
                    else
                    {
                        var hr = this.IFELang.Open();
                        if (hr != 0)
                        {
                            this.Logger.Error("IFELANG IME connection faild.");
                            this.IFELang = null;
                        }

                        this.Logger.Trace("IFELANG IME Connected.");
                    }
                }
            }
        }
예제 #4
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);
        }
예제 #5
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));
        }
예제 #6
0
 /// <summary>
 /// Dispose
 /// </summary>
 public void Dispose()
 {
     if (this.IFELang != null)
     {
         this.IFELang.Close();
         this.IFELang = null;
     }
 }
예제 #7
0
        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            if (this.IFELang != null)
            {
                this.IFELang.Close();
                this.IFELang = null;
            }

            GC.SuppressFinalize(this);
        }
예제 #8
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);
        }
예제 #9
0
파일: TSFYomi.cs 프로젝트: windrobin/kumpro
        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();
            }
        }
예제 #10
0
        /// <summary>
        /// 初期化する
        /// </summary>
        public void Initialize()
        {
            lock (lockObject)
            {
                if (this.IFELang == null)
                {
                    this.IFELang = Activator.CreateInstance(Type.GetTypeFromProgID("MSIME.Japan")) as IFELanguage;

                    var hr = IFELang.Open();
                    if (hr != 0)
                    {
                        ActGlobals.oFormActMain.WriteInfoLog(
                            "ACT.TTSYukkuri IFELANG IMEに接続できません");

                        this.IFELang = null;
                    }

                    ActGlobals.oFormActMain.WriteDebugLog(
                        "ACT.TTSYukkuri IFELANG 接続OK");
                }
            }
        }
예제 #11
0
        /// <summary>
        /// 初期化する
        /// </summary>
        public void Initialize()
        {
            lock (lockObject)
            {
                if (this.IFELang == null)
                {
                    this.IFELang = Activator.CreateInstance(Type.GetTypeFromProgID("MSIME.Japan")) as IFELanguage;

                    var hr = IFELang.Open();
                    if (hr != 0)
                    {
                        ActGlobals.oFormActMain.WriteInfoLog(
                            "ACT.TTSYukkuri IFELANG IMEに接続できません");

                        this.IFELang = null;
                    }

                    ActGlobals.oFormActMain.WriteDebugLog(
                        "ACT.TTSYukkuri IFELANG 接続OK");
                }
            }
        }
예제 #12
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);
            }
        }
예제 #13
0
파일: RevConv.cs 프로젝트: gageas/lutea
        //-------------------------------------------------------------------------------------
        // コンストラクタ
        public ImeLanguage()
        {
            int res = CoInitialize(IntPtr.Zero);

            if (res != S_OK)
            {
//                throw new Exception("CoInitialize returned NOT S_OK. code is " + res);
            }
            FInitialized = true;

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

            if (res != S_OK)
            {
                this.DisposeCom();
                throw new Exception("CLSIDFromString returned NOT S_OK. code is " + res);
            }

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

            if (res != S_OK)
            {
                this.DisposeCom();
                throw new Exception("CoCreateInstance returned NOT S_OK. code is " + res);
            }

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

            if (res != S_OK)
            {
                this.DisposeCom();
                throw new Exception("IFELanguage.Open returned NOT S_OK. code is " + res);
            }
        }
예제 #14
0
파일: RevConv.cs 프로젝트: gageas/lutea
 public void Dispose()
 {
     if (language != null)
     {
         try
         {
             language.Close();
         }
         catch (InvalidCastException)
         {
             // どうでもよさそうなところだが例外が出る時があるので握りつぶす
         }
         finally
         {
             language = null;
             if (FInitialized)
             {
                 DisposeCom();
             }
             GC.SuppressFinalize(this);
         }
     }
 }
예제 #15
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();
        }
예제 #16
0
 public CFELanguage()
 {
     thisIFE = (IFELanguage)Activator.CreateInstance(Type.GetTypeFromProgID("MSIME.Japan"));
 }
예제 #17
0
 public CFELanguage(string progID)
 {
     thisIFE = (IFELanguage)Activator.CreateInstance(Type.GetTypeFromProgID(progID));
 }
예제 #18
0
        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            if (this.IFELang != null)
            {
                this.IFELang.Close();
                this.IFELang = null;
            }

            GC.SuppressFinalize(this);
        }