public IActionResult SpeakerSetting(string voice_db)
        {
            SpeakerSettingModel model = Setting.Speaker.Clone();

            model.VoiceDbName = voice_db ?? Setting.Speaker.VoiceDbName;

            // 話者名のリストを取得する
            string[] voice_names = null;
            Setting.Lock();
            try
            {
                if ((model.VoiceDbName != null) && (0 < model.VoiceDbName.Length))
                {
                    AitalkWrapper.LoadVoice(model.VoiceDbName);
                    voice_names = AitalkWrapper.Parameter.VoiceNames;
                }
            }
            catch (Exception) { }
            finally
            {
                Setting.Unlock();
            }

            // 音声ライブラリと話者のリストを作成してビューに渡す
            ViewData["VoiceDbListItems"] = GenerateSelectListItems(AitalkWrapper.VoiceDbList);
            ViewData["SpeakerListItems"] = GenerateSelectListItems(voice_names);
            return(View(model));
        }
        /// <summary>
        /// 話者リストを取得する.全ライブラリをロードするので時間がかかる.
        /// </summary>
        /// <returns></returns>
        public IActionResult GetSpeakers()
        {
            var libname2speaker = new Dictionary <string, string[]>();

            Setting.Lock();
            foreach (var libname in AitalkWrapper.VoiceDbList)
            {
                AitalkWrapper.LoadVoice(libname);
                var voice_names = AitalkWrapper.Parameter.VoiceNames;
                libname2speaker.Add(libname, voice_names);
            }
            _ = Setting.ApplySpeakerSetting(Setting.Speaker);
            Setting.Unlock();
            return(Ok(libname2speaker));
        }
示例#3
0
        /// <summary>
        /// 新しい話者設定値を適用する。
        /// </summary>
        /// <param name="setting">新しい話者設定値</param>
        /// <returns>エラーメッセージ、もしくはnull</returns>
        public static string ApplySpeakerSetting(SpeakerSettingModel setting)
        {
            Speaker = setting;
            try
            {
                // ボイスライブラリを読み込む
                if (0 < Speaker.VoiceDbName.Length)
                {
                    // 指定されたボイスライブラリを読み込む
                    string voice_db_name = Speaker.VoiceDbName;
                    AitalkWrapper.LoadVoice(voice_db_name);

                    // 話者が指定されているときはその話者を選択する
                    if (0 < Speaker.SpeakerName.Length)
                    {
                        AitalkWrapper.Parameter.CurrentSpeakerName = Speaker.SpeakerName;
                    }
                }
                else
                {
                    // 未指定の場合、初めに見つけたものを読み込む
                    string voice_db_name = AitalkWrapper.VoiceDbList.FirstOrDefault() ?? "";
                    AitalkWrapper.LoadVoice(voice_db_name);
                }

                // 話者パラメータの初期値を記憶する
                DefaultSpeakerParameter = new SpeakerModel
                {
                    Volume        = AitalkWrapper.Parameter.VoiceVolume,
                    Speed         = AitalkWrapper.Parameter.VoiceSpeed,
                    Pitch         = AitalkWrapper.Parameter.VoicePitch,
                    Emphasis      = AitalkWrapper.Parameter.VoiceEmphasis,
                    PauseMiddle   = AitalkWrapper.Parameter.PauseMiddle,
                    PauseLong     = AitalkWrapper.Parameter.PauseLong,
                    PauseSentence = AitalkWrapper.Parameter.PauseSentence
                };

                return(null);
            }
            catch (AitalkException ex)
            {
                return(ex.Message);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
示例#4
0
        /// <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();
            }
        }