Ejemplo n.º 1
0
 public ClipboardReader(SettingsData settings)
 {
     reader       = new SpeechSynthesizer();
     textGetter   = new TextGetter();
     settingsData = settings;
     settingsData.PropertyChanged += onSettingsChanged;
     canStop = canPause = false;
     canPlay = true;
     _state  = readerState.stopped;
 }
Ejemplo n.º 2
0
 public void stop()
 {
     if (canStop)
     {
         waveOut.Stop();
         waveOut.Dispose();
         State    = readerState.stopped;
         canPause = canStop = false;
         canPlay  = true;
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// either pause the reader if playing or unpause if paused.
 /// </summary>
 public void pause()
 {
     if (canPause)
     {
         if (State == readerState.paused)
         {
             waveOut.Play();
             canPause = canStop = canPlay = true;
             State    = readerState.playing;
         }
         else
         {
             waveOut.Pause();
             State    = readerState.paused;
             canPause = canStop = canPlay = true;
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Play starts to read everythin the text set in the textGetter (from clipboard)
        /// if it's paused it will cancel and restart.
        /// </summary>
        public void play()
        {
            if (canPlay)
            {
                Thread t = new Thread(new ThreadStart(textGetter.getText));
                t.SetApartmentState(ApartmentState.STA);
                t.Start();
                t.Join();
                if (State == readerState.playing || State == readerState.paused)
                {
                    waveOut.Stop();
                    waveOut.Dispose();
                }
                State      = readerState.playing;
                canStop    = canPause = canPlay = true;
                lastSpoken = textGetter.text;
                string say = textGetter.text;
                foreach (RegExpression reg in settingsData.RegExs)
                {
                    say = Regex.Replace(say, reg.Pattern, reg.Replacement);
                }

                waveStream = new MemoryStream();
                reader.SetOutputToWaveStream(waveStream);
                reader.Rate = settingsData.speed;
                reader.Speak(say);
                //removing the initial click.
                if (waveStream.Length > 64)
                {
                    waveStream.Position = 64;
                }
                else
                {
                    waveStream.Position = 0;
                }
                WaveFormat          format       = new WaveFormat(11025, 2);
                RawSourceWaveStream sourceStream = new RawSourceWaveStream(waveStream, format);
                waveOut = new WaveOut();
                waveOut.PlaybackStopped += autoEndPlay;
                waveOut.Init(sourceStream);
                readingThread = new Thread(waveOut.Play);
                readingThread.Start();
            }
        }
Ejemplo n.º 5
0
        public StyleReader(Assembly assembly, string resId)
            : base(assembly.GetManifestResourceStream (resId))
        {
            resourceId = resId;
            string styleKey = resId.Substring (0, resId.Length - 6);
            string token = "";
            List<string> targetsClasses = new List<string> ();
            string currentProperty = "";

            int curlyBracketCount = 0;

            while (!EndOfStream) {
                char c = (Char)Read ();

                switch (state) {
                case readerState.classNames:
                    if (c.IsWhiteSpaceOrNewLine () || c == ',' || c == '{') {
                        if (!string.IsNullOrEmpty (token))
                            targetsClasses.Add (token);
                        if (c == '{')
                            state = readerState.propertyName;
                        token = "";
                    }else if (c=='='){
                        //this file contains only properties,
                        //resource Id (minus .style extention) will determine the single target class
                        if (targetsClasses.Count > 1)
                            throwParserException ("Unexpected token '='");
                        else if (targetsClasses.Count == 1) {
                            if (!string.IsNullOrEmpty (token))
                                throwParserException ("Unexpected token '='");
                            currentProperty = targetsClasses [0];
                            targetsClasses [0] = styleKey;
                        }else{
                            if (string.IsNullOrEmpty (token))
                                throwParserException ("Unexpected token '='");
                            targetsClasses.Add (styleKey);
                            currentProperty = token;
                            token = "";
                        }
                        state = readerState.expression;
                    }else
                        token += c;
                    break;
                case readerState.propertyName:
                    if (c.IsWhiteSpaceOrNewLine () || c == '=') {
                        if (!string.IsNullOrEmpty (token))
                            currentProperty = token;
                        if (c == '=')
                            state = readerState.expression;

                        token = "";
                    }else if (c == '}'){
                        if (!string.IsNullOrEmpty (token))
                            throwParserException ("Unexpected token '" + c + "'");
                        targetsClasses = new List<string> ();
                        currentProperty = "";
                        state = readerState.classNames;
                    } else
                        token += c;
                    break;
                case readerState.expression:
                    bool expressionIsFinished = false;
                    if (curlyBracketCount == 0) {
                        if (c == '{'){
                            if (!string.IsNullOrEmpty(token.Trim()))
                                throwParserException ("Unexpected token '{'");
                            curlyBracketCount++;
                            token = "{";
                        }else if (c == '}')
                            throwParserException ("Unexpected token '{'");
                        else if (c == ';') {
                            expressionIsFinished = true;
                        } else
                            token += c;
                    } else {
                        if (c == '{')
                            curlyBracketCount++;
                        else if (c == '}') {
                            curlyBracketCount--;
                            if (curlyBracketCount == 0)
                                expressionIsFinished = true;
                        }
                        token += c;
                    }
                    if (expressionIsFinished) {
                        if (!string.IsNullOrEmpty (token)) {
                            string expression = token.Trim ();

                            foreach (string tc in targetsClasses) {
                                if (!Interface.Styling.ContainsKey (tc))
                                    Interface.Styling [tc] = new Style ();
                                else if (Interface.Styling [tc].ContainsKey (currentProperty))
                                    continue;
                                Interface.Styling [tc] [currentProperty] = expression;
                            }
                            token = "";
                        }
                        //allow omiting ';' if curly bracket close expression
                        while (!EndOfStream) {
                            if (Char.IsWhiteSpace((char)Peek()))
                                Read();
                            else
                                break;
                        }
                        if (this.Peek () == ';')
                            this.Read ();
                        state = readerState.propertyName;
                    }
                    break;
                }
            }

            if (curlyBracketCount > 0)
                throwParserException ("Unexpected end of file");
        }
Ejemplo n.º 6
0
        public StyleReader(Assembly assembly, string resId)
            : base(assembly.GetManifestResourceStream(resId))
        {
            resourceId = resId;
            string        styleKey        = resId.Substring(0, resId.Length - 6);
            string        token           = "";
            List <string> targetsClasses  = new List <string> ();
            string        currentProperty = "";

            int curlyBracketCount = 0;

            while (!EndOfStream)
            {
                char c = (Char)Read();
                if (c == '/' && !EndOfStream)
                {
                    if ((char)Peek() == '/')                       //process comment, skip until newline
                    {
                        ReadLine();
                        continue;
                    }
                }
                switch (state)
                {
                case readerState.classNames:
                    if (c.IsWhiteSpaceOrNewLine() || c == ',' || c == '{')
                    {
                        if (!string.IsNullOrEmpty(token))
                        {
                            targetsClasses.Add(token);
                        }
                        if (c == '{')
                        {
                            state = readerState.propertyName;
                        }
                        token = "";
                    }
                    else if (c == '=')
                    {
                        //this file contains only properties,
                        //resource Id (minus .style extention) will determine the single target class
                        if (targetsClasses.Count > 1)
                        {
                            throwParserException("Unexpected token '='");
                        }
                        else if (targetsClasses.Count == 1)
                        {
                            if (!string.IsNullOrEmpty(token))
                            {
                                throwParserException("Unexpected token '='");
                            }
                            currentProperty    = targetsClasses [0];
                            targetsClasses [0] = styleKey;
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(token))
                            {
                                throwParserException("Unexpected token '='");
                            }
                            targetsClasses.Add(styleKey);
                            currentProperty = token;
                            token           = "";
                        }
                        state = readerState.expression;
                    }
                    else
                    {
                        token += c;
                    }
                    break;

                case readerState.propertyName:
                    if (c.IsWhiteSpaceOrNewLine() || c == '=')
                    {
                        if (!string.IsNullOrEmpty(token))
                        {
                            currentProperty = token;
                        }
                        if (c == '=')
                        {
                            state = readerState.expression;
                        }

                        token = "";
                    }
                    else if (c == '}')
                    {
                        if (!string.IsNullOrEmpty(token))
                        {
                            throwParserException("Unexpected token '" + c + "'");
                        }
                        targetsClasses  = new List <string> ();
                        currentProperty = "";
                        state           = readerState.classNames;
                    }
                    else
                    {
                        token += c;
                    }
                    break;

                case readerState.expression:
                    bool expressionIsFinished = false;
                    if (curlyBracketCount == 0)
                    {
                        if (c == '{')
                        {
                            if (!string.IsNullOrEmpty(token.Trim()))
                            {
                                throwParserException("Unexpected token '{'");
                            }
                            curlyBracketCount++;
                            token = "{";
                        }
                        else if (c == '}')
                        {
                            throwParserException("Unexpected token '{'");
                        }
                        else if (c == ';')
                        {
                            expressionIsFinished = true;
                        }
                        else
                        {
                            token += c;
                        }
                    }
                    else
                    {
                        if (c == '{')
                        {
                            curlyBracketCount++;
                        }
                        else if (c == '}')
                        {
                            curlyBracketCount--;
                            if (curlyBracketCount == 0)
                            {
                                expressionIsFinished = true;
                            }
                        }
                        token += c;
                    }
                    if (expressionIsFinished)
                    {
                        if (!string.IsNullOrEmpty(token))
                        {
                            string expression = token.Trim();

                            foreach (string tc in targetsClasses)
                            {
                                if (!Interface.Styling.ContainsKey(tc))
                                {
                                    Interface.Styling [tc] = new Style();
                                }
                                else if (Interface.Styling [tc].ContainsKey(currentProperty))
                                {
                                    continue;
                                }
                                Interface.Styling [tc] [currentProperty] = expression;
                            }
                            token = "";
                        }
                        //allow omiting ';' if curly bracket close expression
                        while (!EndOfStream)
                        {
                            if (Char.IsWhiteSpace((char)Peek()))
                            {
                                Read();
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (this.Peek() == ';')
                        {
                            this.Read();
                        }
                        state = readerState.propertyName;
                    }
                    break;
                }
            }

            if (curlyBracketCount > 0)
            {
                throwParserException("Unexpected end of file");
            }
        }