/// <summary> /// 新しいシステム設定値を適用する。 /// </summary> /// <param name="setting">新しいシステム設定値</param> /// <returns>エラーメッセージ、もしくはnull</returns> public static string ApplySystemSetting(SystemSettingModel setting) { System = setting; IconByteArray = null; try { // インストールディレクトリと実行ファイルの存在を確認する if (Directory.Exists(System.InstallPath) == false) { return("インストールディレクトリが存在しません。"); } string exe_path = $"{System.InstallPath}\\{System.VoiceroidEditorExe}"; if (File.Exists(exe_path) == false) { return("VOICEROID2エディタの実行ファイルが存在しません。"); } // アイコンを取得する try { using (var icon = Icon.ExtractAssociatedIcon(exe_path)) using (var bitmap = icon.ToBitmap()) using (var stream = new MemoryStream()) { bitmap.Save(stream, ImageFormat.Png); IconByteArray = stream.ToArray(); } } catch (Exception) { } // AITalkを初期化する AitalkWrapper.Initialize(System.InstallPath, System.AuthCodeSeed); // 言語ライブラリを読み込む if ((System.LanguageName != null) && (0 < System.LanguageName.Length)) { // 指定された言語ライブラリを読み込む AitalkWrapper.LoadLanguage(System.LanguageName); } else { // 未指定の場合、初めに見つけたものを読み込む string language_name = AitalkWrapper.LanguageList.FirstOrDefault() ?? ""; AitalkWrapper.LoadLanguage(language_name); } // フレーズ辞書が指定されていれば読み込む if (File.Exists(System.PhraseDictionaryPath)) { AitalkWrapper.ReloadPhraseDictionary(System.PhraseDictionaryPath); } // 単語辞書が指定されていれば読み込む if (File.Exists(System.WordDictionaryPath)) { AitalkWrapper.ReloadWordDictionary(System.WordDictionaryPath); } // 記号ポーズ辞書が指定されていれば読み込む if (File.Exists(System.SymbolDictionaryPath)) { AitalkWrapper.ReloadSymbolDictionary(System.SymbolDictionaryPath); } return(null); } catch (AitalkException ex) { return(ex.Message); } catch (Exception ex) { return(ex.Message); } }
/// <summary> /// HTTPサーバーを起動するモード /// </summary> private void StartServer() { #if DEBUG // Debugビルドの場合、ログファイルを出力する Trace.Listeners.Add(new TextWriterTraceListener("trace.log")); Trace.AutoFlush = true; #endif // AITalkを初期化する AitalkWrapper.Initialize(Config.InstallPath, Config.AuthCodeSeed); try { // 言語ライブラリを読み込む AitalkWrapper.LoadLanguage(Config.LanguageName); // フレーズ辞書が設定されていれば読み込む if (File.Exists(Config.PhraseDictionaryPath)) { AitalkWrapper.ReloadPhraseDictionary(Config.PhraseDictionaryPath); } // 単語辞書が設定されていれば読み込む if (File.Exists(Config.WordDictionaryPath)) { AitalkWrapper.ReloadWordDictionary(Config.WordDictionaryPath); } // 記号ポーズ辞書が設定されていれば読み込む if (File.Exists(Config.SymbolDictionaryPath)) { AitalkWrapper.ReloadSymbolDictionary(Config.SymbolDictionaryPath); } // ボイスライブラリを読み込む AitalkWrapper.LoadVoice(Config.VoiceDbName); // 話者を設定する AitalkWrapper.Parameter.CurrentSpeakerName = Config.VoiceName; // 処理を別スレッドで実行する Task task = Task.Factory.StartNew(Run); // トレイアイコンを作成する // アイコンはVOICEROIDエディタのものを使用するが、ダメならこの実行ファイルのものを使用する NotifyIcon notify_icon = new NotifyIcon(); try { notify_icon.Icon = Icon.ExtractAssociatedIcon($"{Config.InstallPath}\\{Config.VoiceroidEditorExe}"); } catch (Exception) { notify_icon.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); } notify_icon.Text = $"{Caption} : {Config.VoiceName}\nListening at {Config.ListeningAddress}"; notify_icon.Visible = true; // トレイアイコンのコンテキストメニューを作成する ContextMenu menu = new ContextMenu(); menu.MenuItems.Add(new MenuItem("Exit", new EventHandler((object sender, EventArgs e) => { StopServerCancelToken.Cancel(); task.Wait(); notify_icon.Visible = false; Application.Exit(); Environment.Exit(1); }))); notify_icon.ContextMenu = menu; // メッセージループを開始する Application.Run(); } finally { AitalkWrapper.Finish(); } }