Exemple #1
0
 private static void CancelCurrentStream()
 {
     if (TTS.getReader().State == SynthesizerState.Speaking)
     {
         TTS.getReader().SpeakAsyncCancelAll();
         TTS.setReader();
     }
 }
Exemple #2
0
        private static void SetServer()
        {
            try
            {
                TTS.setReader();
                IPAddress localAdd = IPAddress.Parse(SERVER_IP);

                TcpListener listener = new TcpListener(localAdd, PORT_NO);
                Console.WriteLine(ConfigurationManager.AppSettings["ServerInitalState"]);
                listener.Start();

                //---incoming client connected---
                TcpClient client = listener.AcceptTcpClient();

                listener.Stop();
                bool isVrbstyChar    = false;
                bool isPDFMode       = false;
                bool IsLatexDocument = false;

                while (client.Connected)
                {
                    NetworkStream nwStream = client.GetStream();

                    byte[] buffer = new byte[client.ReceiveBufferSize];

                    //---read incoming stream---
                    int    bytesRead    = 0;
                    string dataReceived = string.Empty;

                    try
                    {
                        bytesRead = nwStream.Read(buffer, 0, client.ReceiveBufferSize);
                    }
                    catch (IOException e)
                    {
                        // break;
                    }
                    //---convert the data received into a string---
                    dataReceived = Encoding.ASCII.GetString(buffer, 0, bytesRead);

                    Console.WriteLine("Recevie Data From Client: " + dataReceived);

                    if (dataReceived.Length == 1)
                    {
                        CancelCurrentStream();
                        dataReceived = CurserMode.ParseSource(dataReceived);
                        TTS.Speak(dataReceived);
                    }
                    else if (dataReceived.Equals(ConfigurationManager.AppSettings["DataReceived_Next"]) ||
                             dataReceived.Equals(ConfigurationManager.AppSettings["DataReceived_Stop"]))
                    {
                        if (TTS.getReader().State == SynthesizerState.Paused)
                        {
                            TTS.getReader().Dispose();
                            TTS.setReader();
                        }
                        else
                        {
                            TTS.getReader().SpeakAsyncCancelAll();
                        }
                        if (dataReceived.Equals(ConfigurationManager.AppSettings["DataReceived_Next"]))
                        {
                            isError = true;
                        }
                        dataReceived = string.Empty;
                        isPDFMode    = false;
                        //isVrbstyChar = false;
                        isMisSpelled = false;
                    }
                    else if (dataReceived.Equals(ConfigurationManager.AppSettings["DataReceived_LatexDcmnt"]))
                    {
                        dataReceived    = string.Empty;
                        IsLatexDocument = true;
                    }
                    else if (IsLatexDocument)
                    {
                        if (dataReceived.ToLower().Contains("\\end{document}") || dataReceived.Equals("\\end{document}"))
                        {
                            dataReceived           = strAppendLatexDocument + dataReceived;
                            strAppendLatexDocument = string.Empty;
                            PdfAccessibilityMode obj = new PdfAccessibilityMode(dataReceived);
                            obj.ConvertLatexEquationToText();

                            //---write back the text to the client---
                            byte[] hey = Encoding.ASCII.GetBytes(PdfAccessibilityMode.LatexDocument);
                            Console.WriteLine("Sending back Client : " + PdfAccessibilityMode.LatexDocument);
                            nwStream.Write(hey, 0, hey.Length);
                            PdfAccessibilityMode.LatexDocument = string.Empty;
                            dataReceived    = "";
                            IsLatexDocument = false;
                            nwStream.Flush();
                            //client.Close();
                            //Thread.Sleep(5000);
                            //nwStream.Dispose();
                            //listener.Stop();
                            //nwStream.Dispose();
                            //nwStream.Flush();
                            //listener.Stop();
                            //client.Close();
                            //listener.Start();
                        }
                        else
                        {
                            strAppendLatexDocument = dataReceived + "\n";
                        }
                    }
                    else if (isPDFMode)
                    {
                        PdfMode mathObj = new PdfMode(dataReceived);
                        mathObj.filterLatexSourceCodeUsingOpenDetex();
                        dataReceived = "";
                        isPDFMode    = false;
                    }

                    else if (dataReceived.Equals(ConfigurationManager.AppSettings["DataReceived_PDFMode"]))
                    {
                        CancelCurrentStream();
                        isPDFMode    = true;
                        dataReceived = string.Empty;
                        Console.WriteLine(TTSProperties.MSG_PDF_MODE_ENABLED);
                    }
                    else if (dataReceived.Equals(ConfigurationManager.AppSettings["DataReceived_Pause"]))
                    {
                        TTS.TTS_Pause();
                        dataReceived = string.Empty;
                        Console.WriteLine(TTSProperties.MSG_TTS_PAUSED);
                    }
                    else if (dataReceived.Equals(ConfigurationManager.AppSettings["DataReceived_Resume"]))
                    {
                        TTS.TTS_Resume();
                        dataReceived = string.Empty;
                        Console.WriteLine(TTSProperties.MSG_TTS_RESUMED);
                    }
                    else if (dataReceived.Equals(ConfigurationManager.AppSettings["DataReceived_WordVrbsty"]))
                    {
                        isVrbstyChar = false;
                        dataReceived = string.Empty;
                    }
                    else if (dataReceived.Equals(ConfigurationManager.AppSettings["DataReceived_CharVrbsty"]))
                    {
                        isVrbstyChar = true;
                        dataReceived = string.Empty;
                    }
                    else if (dataReceived.Equals(ConfigurationManager.AppSettings["DataReceived_SpecialCmnd"]))
                    {
                        CancelCurrentStream();
                        isSpeicalCommand = true;
                        dataReceived     = string.Empty;
                    }
                    else if (dataReceived.Equals(ConfigurationManager.AppSettings["DataReceived_IncreaseSpeed"]))
                    {
                        int speed = TTS.getReader().Rate + 1;
                        TTS.TTS_SetSpeed(speed);
                        dataReceived = string.Empty;
                        Console.WriteLine(TTSProperties.MSG_SPEED_INCREASED);
                    }
                    else if (dataReceived.Equals(ConfigurationManager.AppSettings["DataReceived_DecreaseSpeed"]))
                    {
                        int speed = TTS.getReader().Rate - 1;
                        TTS.TTS_SetSpeed(speed);
                        dataReceived = string.Empty;
                        Console.WriteLine(TTSProperties.MSG_SPEED_DECREASED);
                    }
                    else if (CurserMode.IsCurserMode(dataReceived))
                    {
                        string editorCmndValue = ConfigurationManager.AppSettings["DataReceived_EditorCmnd"];
                        if (dataReceived.Contains(editorCmndValue))
                        {
                            dataReceived = dataReceived.Contains(editorCmndValue) ? dataReceived.Replace(editorCmndValue, "") : dataReceived;
                            if (isVrbstyChar)
                            {
                                CancelCurrentStream();
                                //dataReceived = Encoding.Default.GetString(buffer, 0, bytesRead);
                                TTS.VBRCharModeTTSSpeak(dataReceived);
                                //isVrbstyChar = false;
                                continue;
                            }
                        }
                        dataReceived = CurserMode.ParseSource(dataReceived);
                        CancelCurrentStream();
                        TTS.Speak(dataReceived);
                    }
                    else if (dataReceived.Equals(ConfigurationManager.AppSettings["DataReceived_ChangeVoice"]))
                    {
                        isVoiceChange = true;
                        dataReceived  = string.Empty;
                    }
                    else if (isVoiceChange)
                    {
                        isVoiceChange = false;
                        TTS.TTS_ChangeVoice(dataReceived);
                        dataReceived = string.Empty;
                        Console.WriteLine(TTSProperties.MSG_VOICE_CHANGED);
                    }
                    else if (!string.IsNullOrEmpty(dataReceived))
                    {
                        LookupTable();
                        //dataReceived = TextLineParsing(dataReceived);
                        if (isMisSpelled)
                        {
                            dataReceived = "misspelled \r\n" + dataReceived;
                            isMisSpelled = false;
                        }
                        if (isVrbstyChar && !isError && !isSpeicalCommand)
                        {
                            CancelCurrentStream();
                            //dataReceived = Encoding.Default.GetString(buffer, 0, bytesRead);
                            TTS.VBRCharModeTTSSpeak(dataReceived);
                            //isVrbstyChar = false;
                            continue;
                        }
                        dataReceived = TextLineParsing(dataReceived);
                        CancelCurrentStream();
                        TTS.Speak(dataReceived);
                        isError          = false;
                        isSpeicalCommand = false;
                    }
                }
            }catch (Exception ex)
            {
                throw ex;
            }
        }