Jaydeep Jaydeep - 3 months ago 27
C# Question

Windows Phone 8 SpeechSynthesizer Pause

I'm developing an app where I would like to pause in between when the SpeechSynthesizer.SpeakTextAsync is running and resume back from there.

await synthesizer.SpeakTextAsync(text);


stop reading when
var stop = true;

Answer

Some one posted here a while back, at the same time I refreshed the page, read his answer, saw a notification & refreshed the page again & the answer was gone. But whoever posted, he is a life saver. It stuck my mind and I ended up creating this.

    String text;  // your text to read out loud
    String[] parts = text.Split(' ');
    int max = parts.Length;
    int count = 0;

    private String makeSSML() {
        if (count == max) { 
            count= 0;
        }
        String s = "<speak version=\"1.0\" ";
        s += "xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-US\">";
        for (int i = count; i < max; i++)
        {
            s += parts[i];
            s += "<mark name=\"anything\"/>";
        }
        s += "<mark name=\"END\"/>";
        s += "</speak>";
        return s;
    }

    private void playIT(){
        synth = new SpeechSynthesizer();
        synth.BookmarkReached += synth_BookmarkReached;
        synth.SpeakSsmlAsync(makeSSML());
    }

    private void synth_BookmarkReached(object sender, SpeechBookmarkReachedEventArgs e)
    {
        count++;
        if (e.Bookmark == "END") {
            synth.Dispose();
        }
    }

    private void Pause_Click(object sender, RoutedEventArgs e)
    {
        synth.Dispose();
    }

Thanks man, your answer gave me the idea.