I'm trying to do a TTS app for Windows Phone, but i have a little problem. I'v make a function to call Google TTS service and play it on a MediaElement, that works perfect.
That's the function i'v wrote
public void Say(string phrase)
{
mediaElement1.Source = new Uri("http://translate.google.com/translate_tts?tl=en&q=" + phrase, UriKind.Absolute));
mediaElement1.Play();
}
But if i call the function a lot of times, for example, in a for loop, it just say the last item of loop. For example
for (int i = 0; i < 10; i++)
{
Say(Convert.ToString(i));
}
Then it just say 'Nine', nope '1,2,3,4,...'
I'v tried to do a 'Playlist' of words, that the function will play. This is my code.
bool first = true;
List<Uri> uriTask = new List<Uri>();
public void Say(string phrase)
{
uriTask.Add(new Uri("http://translate.google.com/translate_tts?tl=es&q=" + phrase, UriKind.Absolute));
if (mediaElement1.CurrentState != MediaElementState.Playing)
{
if (first)
{
CHECK();
first = false;
}
else
{
mediaElement1.MediaEnded += delegate
{
mediaElement1.Position = TimeSpan.Zero;
CHECK();
};
}
}
}
private void CHECK()
{
if (uriTask.Count > 0)
{
mediaElement1.Source = uriTask[0];
mediaElement1.Play();
uriTask.RemoveAt(0);
}
}
Thanks. Greetings