Esempio n. 1
0
 void startSpeakProcess()
 {
     if (listToSpeak.Count > 0 && _synth.State != SynthesizerState.Speaking)
     {
         command c = listToSpeak[listToSpeak.Count - 1];
         listToSpeak = listToSpeak.GetRange(0, listToSpeak.Count - 1);
         //listToSpeak.RemoveAt(listToSpeak.Count - 1);
         _synth.SpeakAsync(c.para);
     }
 }
Esempio n. 2
0
        void setupWebsocket(string url)
        {
            closeWebsocket();
            try
            {
                ws         = new WebSocket(url);
                ws.OnOpen += (sender, e) =>
                {
                    command regCmd = new command("led", "");
                    regCmd.msgType = "reg";
                    string strcmd = Newtonsoft.Json.JsonConvert.SerializeObject(regCmd);
                    ws.Send(strcmd);
                    regCmd         = new command("tts", "");
                    regCmd.msgType = "reg";
                    strcmd         = Newtonsoft.Json.JsonConvert.SerializeObject(regCmd);
                    ws.Send(strcmd);
                };

                ws.OnMessage += (sender, e) =>
                {
                    Debug.WriteLine(e.Data);
                    object    o      = Newtonsoft.Json.JsonConvert.DeserializeObject <statusMsg>(e.Data);
                    statusMsg status = (statusMsg)o;
                    if (status.status == "success" && status.cmds != null)
                    {
                        List <command> list = (List <command>)Newtonsoft.Json.JsonConvert.DeserializeObject <List <command> >(status.cmds);
                        foreach (command _cmd in list)
                        {
                            Debug.WriteLine(string.Format("name: {0}    para: {1}", _cmd.name, _cmd.para));

                            switch (_cmd.name)
                            {
                            case "led":
                                //设置LED字幕
                                if (this.ckbled.Checked)
                                {
                                    try
                                    {
                                        appendLog("获取到LED屏内容:" + _cmd.para + "  " + _cmd.timeStamp);
                                        this.sendMsgToLED(this.LED_IP, _cmd.para);
                                    }
                                    catch (System.Exception ex)
                                    {
                                        appendLog("发送到LED屏时发生异常:" + ex.Message);
                                    }
                                }
                                break;

                            case "tts":
                                appendLog("获取到tts内容:" + _cmd.para + "  " + _cmd.timeStamp);
                                listToSpeak.Insert(0, _cmd);
                                //启动语音播放
                                startSpeakProcess();
                                break;
                            }
                        }
                    }
                };

                ws.OnError += (sender, e) =>
                {
                    Debug.WriteLine(e.Message);
                    setupWebsocket(wssUrl);
                };

                ws.OnClose += (sender, e) =>
                {
                    Debug.WriteLine(e.Data);
                };

                ws.Connect();
            }
            catch (Exception e)
            {
            }
        }