/// <summary>
 /// Synthesizes passed through text as audio and plays speech through the MediaElement first sent through.
 /// </summary>
 public async Task Read(string text)
 {
     if (this.textToSpeak.Count < 5)
     {
         speechTask task = new speechTask(text, false);
         this.textToSpeak.Enqueue(task);
     } // drop if we have too many text to speak
 }
        public async Task ProcessSpeechTasksAsync(CancellationToken token)
        {
            while (!token.IsCancellationRequested)    //!cancellationTokenSource.Token.IsCancellationRequested
            {
                if (mediaElement != null && synthesizer != null && textToSpeak.Count > 0)
                {
                    try
                    {
                        semaphore.WaitOne();
                        speechTask task = textToSpeak.Dequeue();
                        if (task != null)
                        {
                            var stream = task.isSsml ? await synthesizer.SynthesizeSsmlToStreamAsync(task.text) :
                                         await synthesizer.SynthesizeTextToStreamAsync(task.text);

                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                mediaElement.AutoPlay = true;
                                mediaElement.SetSource(stream, stream.ContentType);
                                mediaElement.Play();
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        semaphore.Release();
                    }
                }
                else
                {
                    await Task.Delay(TimeSpan.FromSeconds(1), token);
                }
            }

            /*  if (mediaElement != null && synthesizer != null)
             * {
             *  var stream = await synthesizer.SynthesizeSsmlToStreamAsync(text);
             *
             *  mediaElement.AutoPlay = true;
             *  mediaElement.SetSource(stream, stream.ContentType);
             *  mediaElement.Play();
             * }
             */
        }
        public async Task ReadSsml(string text)
        {
            speechTask task = new speechTask(text, true);

            this.textToSpeak.Enqueue(task);
        }