private VoiceBot() { this.state = new BotState(); // TRANSLATORS: Log message. Initializing Rein. Logger.Log(T._("- initialize Bouyomi-chan ...")); this.bouyomichan = new BouyomiChanClient(); this.CheckBouyomichan(); // TRANSLATORS: Log message. Initializing Rein. Logger.Log(T._("- initialize sound devices ...")); try { Rein.AudioConnector.NAudio.Initialize(Config.Instance.MainConfig); } catch (Exception e) { this.Dispose(); // TRANSLATORS: Error message. Initializing Rein. throw new Exception(T._("Could not initialize sound devices. Please check virtual devices installed and valid name set."), e); } try { this.voice = new Rein.AudioConnector.NAudio(Config.Instance.MainConfig); } catch (Exception e) { this.Dispose(); // TRANSLATORS: Error message. Initializing Rein. throw new Exception(T._("Could not initialize recording devices. Please check virtual devices installed and valid name set."), e); } // TRANSLATORS: Log message. Initializing Rein. Logger.Log(T._("- initialize Discord client ...")); this.discord = CreateDiscordClient(); // TRANSLATORS: Log message. Initializing Rein. Logger.Log(T._("- initialize Timer ...")); this.timer = new Timer(this.TickHandler); // TRANSLATORS: Log message. Initializing Rein. Logger.Log(T._("- load plugins ...")); PluginManager.Instance.Load(this); }
protected virtual void Dispose(bool disposing) { try { // TRANSLATORS: Log message. Dispose Rein. Logger.Log(T._("Clean up ...")); // TRANSLATORS: Log message. Dispose Rein. Logger.Log(T._("- unload Bouyomi-chan ...")); if (this.bouyomichan != null) { this.bouyomichan.Dispose(); this.bouyomichan = null; } // TRANSLATORS: Log message. Dispose Rein. Logger.Log(T._("- unload sound devices ...")); // TRANSLATORS: Log message. Dispose Rein. Logger.Log(T._("- unload discord ...")); if (this.discord != null) { this.discord.Dispose(); this.discord = null; } // TRANSLATORS: Log message. Dispose Rein. Logger.Log(T._("Disposing Done!")); GC.SuppressFinalize(this); } catch (Exception e) { // TRANSLATORS: Log message. Dispose Rein. Logger.Log(T._("Could not clean up VoiceBot instance.")); Logger.DebugLog(e.ToString()); } }
/// <summary> /// メッセージを受け取った時の処理 /// </summary> static async Task MessageReceived(SocketMessage arg) { await Task.Run(() => { // 棒読みちゃんに読み上げさせる // using を使うとリソース解放してくれるので Dispose() しなくてすむ using (var bc = new BouyomiChanClient()) { bc.AddTalkTask(arg.Content); } /*/ * // チャンネル一覧にある・ユーザーID一覧にあるなら * if (Properties.Settings.Default.TextChannels.IndexOf(arg.Channel.Id.ToString()) >= 0 || * Properties.Settings.Default.UserIDs.IndexOf(arg.Author.Id.ToString()) >= 0) * { * // 読み上げ * using (var bc = new BouyomiChanClient()) * { * bc.AddTalkTask(arg.Content); * } * } * //*/ }); }
/// <summary> /// 棒読みちゃんで読み上げ /// </summary> private void Bouyomi(string text) { var bouyomiChanClient = new BouyomiChanClient(); bouyomiChanClient.AddTalkTask(text); bouyomiChanClient.Dispose(); }
/// <summary> /// メッセージを受け取った時の処理 /// </summary> private async Task Talk(SocketMessage message) { await Task.Run(() => { // チャンネル一覧に存在するなら foreach (var idInfo in iDList.ChannelIDList) { if (idInfo.ID == message.Channel.Id.ToString()) { // 読み上げ using (var bc = new BouyomiChanClient()) { bc.AddTalkTask(message.Content); } return; } } // ユーザ一覧に存在するなら foreach (var idInfo in iDList.UserIDList) { if (idInfo.ID == message.Author.Id.ToString()) { // 読み上げ using (var bc = new BouyomiChanClient()) { bc.AddTalkTask(message.Content); } return; } } }); }
public FormTest() { InitializeComponent(); //棒読みちゃんに接続 BouyomiChan = new BouyomiChanClient(); }
/// <summary> /// 初期化 /// </summary> private void init() { if (disposed) { return; } // 棒読みちゃんクライアント bouyomiChanClient = new BouyomiChanClient(); }
public void init() { try { bcc = new BouyomiChanClient(); } catch { bcc = null; } }
/// <summary> /// 使用中のリソースをすべてクリーンアップします。 /// </summary> /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param> protected virtual void Dispose(bool disposing) { if (!disposed) { // 棒読みちゃんクライアント破棄処理 if (bouyomiChanClient != null) { bouyomiChanClient.Dispose(); bouyomiChanClient = null; } disposed = true; } }
/// <summary> /// メッセージを受け取った時の処理 /// </summary> static async Task Talk(SocketMessage arg) { await Task.Run(() => { // チャンネル一覧にある・ユーザーID一覧にあるなら if (Properties.Settings.Default.TextChannels.IndexOf(arg.Channel.Id.ToString()) >= 0 || Properties.Settings.Default.UserIDs.IndexOf(arg.Author.Id.ToString()) >= 0) { // 読み上げ using (var bc = new BouyomiChanClient()) { bc.AddTalkTask(arg.Content); } } }); }
/// <summary> /// 非同期Mainメソッド /// </summary> static async Task MainAsync() { // トークンのチェック await CheckTokenAsync(); // ログイン処理 Console.WriteLine("ログイン中…"); var client = new DiscordSocketClient(); await client.LoginAsync(TokenType.User, Properties.Settings.Default.Token); await client.StartAsync(); Console.WriteLine("ログイン完了"); // 始めのあいさつ(大事) var task = Task.Run(() => { using (var start = new BouyomiChanClient()) { start.AddTalkTask("棒読みちゃん起動~!"); } }); // メッセージ受信時のイベントを追加 client.MessageReceived += Talk; // 各種コマンド InputCommand(); // 終わりのあいさつ(大事) task = Task.Run(() => { using (var end = new BouyomiChanClient()) { end.AddTalkTask("棒読みちゃん終了~!"); } }); Console.WriteLine("キー入力で終了"); Console.ReadLine(); }
private VoiceBot() { this.state = new BotState(); // TRANSLATORS: Log message. Initializing Nursery. Logger.Log(T._("- initialize Bouyomi-chan ...")); this.bouyomichan = new BouyomiChanClient(); try { this.bouyomichan.ClearTalkTasks(); } catch (Exception e) { this.Dispose(); // TRANSLATORS: Error message. Initializing Nursery. throw new Exception(T._("Could not load Bouyomi-chan. Please check Bouyomi-chan awaking."), e); } // TRANSLATORS: Log message. Initializing Nursery. Logger.Log(T._("- initialize sound devices ...")); try { BassWrapper.Initialize(Config.Instance.MainConfig); } catch (Exception e) { this.Dispose(); // TRANSLATORS: Error message. Initializing Nursery. throw new Exception(T._("Could not initialize sound devices. Please check virtual devices installed and valid name set."), e); } try { this.voice = new VoiceChat(Config.Instance.MainConfig); } catch (Exception e) { this.Dispose(); // TRANSLATORS: Error message. Initializing Nursery. throw new Exception(T._("Could not initialize recording devices. Please check virtual devices installed and valid name set."), e); } // TRANSLATORS: Log message. Initializing Nursery. Logger.Log(T._("- initialize Discord client ...")); this.discord = new DiscordSocketClient(); // TRANSLATORS: Log message. Initializing Nursery. Logger.Log(T._("- load plugins ...")); PluginManager.Instance.Load(this); }
// 読み上げ 開始/停止 ボタンを押したときの処理 // チェックボックスにチェックが入っているかどうかを、スイッチのON/OFFに見立ててトグル式のボタンにできる // AppearanceプロパティをButtonにする private async void checkBox1_CheckedChangedAsync(object sender, EventArgs e) { CheckBox chkBox = (CheckBox)sender; if (chkBox.Checked) { // 起動時はチェックが入っておらず、表示が開始になっている // チェックが入ると表示を停止に変更 chkBox.Text = "停止"; // テキストボックスに入力してあるメールアドレスを取得 string email = textBox1.Text; Console.Write("メールアドレス : " + email); // テキストボックスに入力してあるパスワードを取得 string password = textBox2.Text; Console.Write("\nパスワード : " + password); // メールアドレスとパスワードでトークンを取得する処理 // 入力ミスでトークンを取得できなかった時などの例外処理が必要かも? await CheckTokenAsync(email, password); // ログイン処理 // 「TokenType.User は旧形式です」という警告がでてるけど、どうしたらいいかわからない Console.WriteLine("ログイン処理中…"); await client.LoginAsync(TokenType.User, Properties.Settings.Default.Token); await client.StartAsync(); Console.WriteLine("ログイン完了"); // ログインしたことがわかるように、読み上げ開始のお知らせ var task = Task.Run(() => { using (var start = new BouyomiChanClient()) { Console.WriteLine("ディスコードの読み上げを開始しました。"); start.AddTalkTask("ディスコードの読み上げを開始しました。"); } }); } else { // チェックを外した状態は停止中、表示を開始するためのボタンに変更する chkBox.Text = "開始"; // ログアウト処理 Console.WriteLine("ログアウト処理中…"); await client.StopAsync(); await client.LogoutAsync(); Console.WriteLine("ログアウト完了"); // ログアウトしたことがわかるように、読み上げ終了のお知らせ var task = Task.Run(() => { using (var end = new BouyomiChanClient()) { Console.WriteLine("ディスコードの読み上げを終了しました。"); end.AddTalkTask("ディスコードの読み上げを終了しました。"); } }); } }
public BouyomiClientWrapper() : base() { this.client = new BouyomiChanClient(); }
private async void RecognizeButton_Click(object sender, RoutedEventArgs e) { await changeStateRecognizeButton(false); if (isListening == false) { if (audioConfig == null) { audioConfig = AudioConfig.FromDefaultMicrophoneInput(); } await changeControls(false); try { string subscriptionKey = AzureSubscriptionKeyTextBox.Text.Trim(); Uri endpointUri = new Uri(AzureServiceEndpointUriTextBox.Text.Trim()); if (subscriptionKey.Length == 0 || endpointUri.IsWellFormedOriginalString() != true) { await changeStateRecognizeButton(true); await changeControls(true); return; } textQueue = new ConcurrentQueue <string>(); speechConfig = SpeechConfig.FromEndpoint(endpointUri, subscriptionKey); speechConfig.SpeechRecognitionLanguage = "ja-JP"; recognizer = new SpeechRecognizer(speechConfig, audioConfig); if (bouyomiChan != null) { bouyomiChan.Dispose(); bouyomiChan = null; } if (BouyomiChanCheckBox.IsChecked == true) { bouyomiChan = new BouyomiChanClient(); } isListening = true; recognizer.Recognized += UpdateRecognizedText; recognizer.Canceled += RecognizeCanceled; await recognizer.StartContinuousRecognitionAsync(); double refreshSecond = RefreshSecondSlider.Value; _ = Task.Run(() => writeToTextfile(refreshSecond)); } catch (Exception ex) { Debug.WriteLine(ex.Message); if (bouyomiChan != null) { bouyomiChan.Dispose(); bouyomiChan = null; } await changeControls(true); await changeStateRecognizeButton(true); return; } } else { recognizer.Recognized -= UpdateRecognizedText; recognizer.Canceled -= RecognizeCanceled; await recognizer.StopContinuousRecognitionAsync(); if (bouyomiChan != null) { bouyomiChan.Dispose(); bouyomiChan = null; } isListening = false; await changeControls(true); } await changeStateRecognizeButton(true); }