user3090763
user3090763

Reputation: 1099

How to control speed of audio in Media Element in Window Store App

I am playing audio with media element by converting text to speech in my app. here is my code

var synth = new SpeechSynthesizer();
            var voice=SpeechSynthesizer.AllVoices;
            synth.Voice = voice[2];
 var text = "My name is John";

            var stream = await synth.SynthesizeTextToStreamAsync(text);

            var me = new MediaElement();
             me.SetSource(stream, stream.ContentType);
            me.Play();

Audio here being played is fast .I want that audio should play slowly. I tried Playback property of media element but its does not work.How to control speed of play back in media element?

Upvotes: 1

Views: 1482

Answers (1)

letiagoalves
letiagoalves

Reputation: 11302

Use DefaultPlaybackRate property:

var me = new MediaElement();
me.DefaultPlaybackRate = 0.5;
me.SetSource(stream, stream.ContentType);
me.Play();

You can also use PlaybackRate property if you don't want it to persist throughout the lifetime of the MediaElement. This happens because PlaybackRate will have DefaultPlaybackRate value when Play method is called till playback ends.

Reference

Upvotes: 2

Related Questions