private void IPCAddTalkTask03(string TalkText, int iSpeed, int iTone, int iVolume, int vType) { int cid; List <int> CidList = Config.AvatorNames.Select(c => c.Key).ToList(); int cnt = CidList.Count; int ListenIf = (int)ListenInterface.IPC1; int voice = EditInputText.EditInputString((vType > 8 || vType == -1 ? 0 : vType), TalkText); cid = UserData.SelectedCid[ListenIf][voice]; switch (UserData.RandomVoiceMethod[ListenIf]) { case 1: voice = r.Next(0, 9); cid = UserData.SelectedCid[ListenIf][voice]; break; case 2: cid = CidList[r.Next(0, cnt)]; if (Config.AvatorNames.ContainsKey(cid)) { UserData.VoiceParams[ListenIf][voice][cid] = Config.AvatorParams(cid); } break; } Dictionary <string, decimal> Effects = UserData.VoiceParams[ListenIf][voice][cid]["effect"].ToDictionary(k => k.Key, v => v.Value["value"]); Dictionary <string, decimal> Emotions = UserData.VoiceParams[ListenIf][voice][cid]["emotion"].ToDictionary(k => k.Key, v => v.Value["value"]); MessageData talk = new MessageData() { Cid = cid, Message = EditInputText.ChangedTalkText, BouyomiVoice = voice, ListenInterface = ListenIf, TaskId = MessQue.count + 1, Effects = Effects, Emotions = Emotions }; switch (PlayMethod) { case Methods.sync: MessQue.AddQueue(talk); break; case Methods.async: OnCallAsyncTalk?.Invoke(talk); break; } }
private Action SetupBGHttpListenerTask() { Action BGHttpListen = (() => { StringBuilder sb = new StringBuilder(); string listFmt = @"""id"":{0}, ""kind"":""AquesTalk"", ""name"":""{1}"", ""alias"":"""""; List <int> CidList = Config.AvatorNames.Select(c => c.Key).ToList(); int cnt = CidList.Count; int cid; int ListenIf; while (KeepListen) // とりあえずの待ち受け構造 { try { HttpListenerContext context = HTTPListener.GetContext(); HttpListenerRequest request = context.Request; HttpListenerResponse response = context.Response; int voice = 0; string TalkText = "本日は晴天ですか?"; string UrlPath = request.Url.AbsolutePath.ToUpper(); foreach (var item in Regex.Split(request.Url.Query, @"[&?]")) { if (item == "") { continue; } string[] s = Regex.Split(item, "="); if (s.Length < 2) { s = new string[] { HttpUtility.UrlDecode(s[0]), "" } } ; if (s.Length >= 2) { s = new string[] { HttpUtility.UrlDecode(s[0]), HttpUtility.UrlDecode(s[1]) } } ; switch (s[0]) { case "text": TalkText = s[1]; break; case "voice": int.TryParse(s[1], out voice); break; case "volume": case "speed": case "tone": default: break; } } response.ContentType = "application/json; charset=utf-8"; if (ListenPort == Config.HttpPortNum2) { ListenIf = (int)ListenInterface.Http2; } else { ListenIf = (int)ListenInterface.Http1; } voice = EditInputText.EditInputString((voice > 8 || voice == -1 ? 0 : voice), TalkText); cid = UserData.SelectedCid[ListenIf][voice]; switch (UserData.RandomVoiceMethod[ListenIf]) { case 1: voice = r.Next(0, 9); cid = UserData.SelectedCid[ListenIf][voice]; break; case 2: cid = CidList[r.Next(0, cnt)]; if (Config.AvatorNames.ContainsKey(cid)) { UserData.VoiceParams[ListenIf][voice][cid] = Config.AvatorParams(cid); } break; } // dispath url switch (UrlPath) { case "/TALK": Dictionary <string, decimal> Effects = UserData.VoiceParams[ListenIf][voice][cid]["effect"].ToDictionary(k => k.Key, v => v.Value["value"]); Dictionary <string, decimal> Emotions = UserData.VoiceParams[ListenIf][voice][cid]["emotion"].ToDictionary(k => k.Key, v => v.Value["value"]); MessageData talk = new MessageData() { Cid = cid, Message = EditInputText.ChangedTalkText, BouyomiVoice = voice, ListenInterface = ListenIf, TaskId = MessQue.count + 1, Effects = Effects, Emotions = Emotions }; switch (PlayMethod) { case Methods.sync: MessQue.AddQueue(talk); break; case Methods.async: OnCallAsyncTalk?.Invoke(talk); break; } byte[] responseTalkContent = Encoding.UTF8.GetBytes("{" + string.Format(@"""taskId"":{0}", talk.TaskId) + "}"); response.OutputStream.Write(responseTalkContent, 0, responseTalkContent.Length); response.Close(); break; case "/GETVOICELIST": sb.Clear(); sb.AppendLine(@"{ ""voiceList"":["); sb.Append( string.Join(",", Config.AvatorNames.Select(v => string.Format(listFmt, v.Key, v.Value)) .Select(v => "{" + v + "}") .ToArray()) ); sb.AppendLine(@"] }"); byte[] responseListContent = Encoding.UTF8.GetBytes(sb.ToString()); response.OutputStream.Write(responseListContent, 0, responseListContent.Length); response.Close(); break; case "/GETTALKTASKCOUNT": byte[] responseTaskCountContent = Encoding.UTF8.GetBytes("{" + string.Format(@"""talkTaskCount"":{0}", MessQue.count) + "}"); response.OutputStream.Write(responseTaskCountContent, 0, responseTaskCountContent.Length); response.Close(); break; case "/GETNOWTASKID": byte[] responseTaskNowContent = Encoding.UTF8.GetBytes("{" + string.Format(@"""nowTaskId"":{0}", taskId) + "}"); response.OutputStream.Write(responseTaskNowContent, 0, responseTaskNowContent.Length); response.Close(); break; case "/GETNOWPLAYING": byte[] responseTaskPlayingContent = Encoding.UTF8.GetBytes("{" + string.Format(@"""nowPlaying"":{0}", MessQue.count != 0) + "}"); response.OutputStream.Write(responseTaskPlayingContent, 0, responseTaskPlayingContent.Length); response.Close(); break; case "/CLEAR": byte[] responseTaskClearContent = Encoding.UTF8.GetBytes(@"{}"); response.OutputStream.Write(responseTaskClearContent, 0, responseTaskClearContent.Length); response.Close(); break; default: byte[] responseMessageContent = Encoding.UTF8.GetBytes(@"{ ""Message"":""content not found.""}"); response.StatusCode = 404; response.OutputStream.Write(responseMessageContent, 0, responseMessageContent.Length); response.Close(); break; } } catch (Exception) { //Dispatcher.Invoke(() => //{ // MessageBox.Show(e.Message, "sorry3"); //}); } } }); return(BGHttpListen); }
private Action SetupBGTcpListenerTask() { // パケット(プログラムではiSpeed~iVolumeをスキップ) // Int16 iCommand = 0x0001; // Int16 iSpeed = -1; // Int16 iTone = -1; // Int16 iVolume = -1; // Int16 iVoice = 1; // byte bCode = 0; // Int32 iLength = bMessage.Length; // byte[] bMessage; Action BGTcpListen = (() => { while (KeepListen) // とりあえずの待ち受け構造 { try { TcpClient client = TcpIpListener.AcceptTcpClient(); Int16 iCommand; Int16 iVoice; int voice; int ListenIf; byte bCode; Int32 iLength; string TalkText = ""; byte[] iCommandBuff; byte[] iVoiceBuff; byte[] iLengthBuff; List <int> CidList = Config.AvatorNames.Select(c => c.Key).ToList(); int cnt = CidList.Count; int cid; using (NetworkStream ns = client.GetStream()) { using (BinaryReader br = new BinaryReader(ns)) { iCommandBuff = br.ReadBytes(2); iCommand = BitConverter.ToInt16(iCommandBuff, 0); // コマンド switch (iCommand) { case 0x0001: // 読み上げ指示 br.ReadBytes(2 * 3); // スキップ iVoiceBuff = br.ReadBytes(2); iVoice = BitConverter.ToInt16(iVoiceBuff, 0); // 音声 bCode = br.ReadByte(); // 文字列エンコーディング iLengthBuff = br.ReadBytes(4); iLength = BitConverter.ToInt32(iLengthBuff, 0); // 文字列サイズ byte[] TalkTextBuff = new byte[iLength]; TalkTextBuff = br.ReadBytes(iLength); // 文字列データ switch (bCode) { case 0: // UTF8 TalkText = System.Text.Encoding.UTF8.GetString(TalkTextBuff, 0, iLength); break; case 2: // CP932 TalkText = System.Text.Encoding.GetEncoding(932).GetString(TalkTextBuff, 0, iLength); break; case 1: // 暫定で書いた TalkText = System.Text.Encoding.Unicode.GetString(TalkTextBuff, 0, iLength); break; } if (ListenPort == Config.SocketPortNum2) { ListenIf = (int)ListenInterface.Socket2; } else { ListenIf = (int)ListenInterface.Socket1; } voice = EditInputText.EditInputString((iVoice > 8 || iVoice == -1 ? 0 : iVoice), TalkText); cid = UserData.SelectedCid[ListenIf][voice]; switch (UserData.RandomVoiceMethod[ListenIf]) { case 1: voice = r.Next(0, 9); cid = UserData.SelectedCid[ListenIf][voice]; break; case 2: cid = CidList[r.Next(0, cnt)]; if (Config.AvatorNames.ContainsKey(cid)) { UserData.VoiceParams[ListenIf][voice][cid] = Config.AvatorParams(cid); } break; } Dictionary <string, decimal> Effects = UserData.VoiceParams[ListenIf][voice][cid]["effect"].ToDictionary(k => k.Key, v => v.Value["value"]); Dictionary <string, decimal> Emotions = UserData.VoiceParams[ListenIf][voice][cid]["emotion"].ToDictionary(k => k.Key, v => v.Value["value"]); MessageData talk = new MessageData() { Cid = cid, Message = EditInputText.ChangedTalkText, BouyomiVoice = voice, ListenInterface = ListenIf, TaskId = MessQue.count + 1, Effects = Effects, Emotions = Emotions }; switch (PlayMethod) { case Methods.sync: MessQue.AddQueue(talk); break; case Methods.async: OnCallAsyncTalk?.Invoke(talk); break; } break; case 0x0040: // 読み上げキャンセル MessQue.ClearQueue(); break; case 0x0110: // 一時停止状態の取得 byte data1 = 0; using (BinaryWriter bw = new BinaryWriter(ns)) { bw.Write(data1); } break; case 0x0120: // 音声再生状態の取得 byte data2 = MessQue.count == 0 ? (byte)0 : (byte)1; using (BinaryWriter bw = new BinaryWriter(ns)) { bw.Write(data2); } break; case 0x0130: // 残りタスク数の取得 byte[] data3 = BitConverter.GetBytes(MessQue.count); using (BinaryWriter bw = new BinaryWriter(ns)) { bw.Write(data3); } break; case 0x0010: // 一時停止 case 0x0020: // 一時停止の解除 case 0x0030: // 現在の行をスキップし次の行へ default: break; } } } } catch (Exception) { //Dispatcher.Invoke(() => //{ // MessageBox.Show(e.Message, "sorry3"); //}); } } }); return(BGTcpListen); }