Asked by:
Speech Synthesizer Marks Dont Fire in Windows 8.1

Question
-
I noticed some replies on the thread:
http://social.msdn.microsoft.com/Forums/windowsapps/en-US/12632c23-526b-41b3-969d-3b62bf387063/how-to-use-marks-in-ssml
But I'm still having problems firing a bookmark. Is this supposed to work in Windows 8.1? Or am I doing something wrong?
Thanks for your help.using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.Media.SpeechSynthesis; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 namespace SpeechMark { /// <summary> /// An empty page that can be used on its own or navigated to within a Frame. /// </summary> public sealed partial class BlankPage1 : Page { public BlankPage1() { this.InitializeComponent(); m_button.Click += m_button_Click; } async void m_button_Click(object sender, RoutedEventArgs e) { string ssml = "<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en\"><voice gender=\"female\" xml:lang=\"en\"><prosody rate=\"1\">how are you doing</prosody><mark name=\"utteranceComplete\"/></voice></speak>"; var m_audioPlayer = new MediaElement(); var m_textToSpeech = new SpeechSynthesizer(); m_audioPlayer.MarkerReached += new TimelineMarkerRoutedEventHandler(onUtteranceCompleted); SpeechSynthesisStream stream = await m_textToSpeech.SynthesizeSsmlToStreamAsync(ssml); // Add markers manually { m_audioPlayer.Markers.Clear(); foreach (var marker in stream.Markers) { m_audioPlayer.Markers.Add(new TimelineMarker() { Text = marker.Text, Time = marker.Time, Type = marker.MediaMarkerType }); } } m_audioPlayer.SetSource(stream, stream.ContentType); m_audioPlayer.Play(); } public void onUtteranceCompleted(object sender, TimelineMarkerRoutedEventArgs e) { // Breakpoint here never gets hit } } }
Saturday, December 7, 2013 8:26 AM
All replies
-
Hi,
because i´m on a surface pro i´m not able to test it, but i think the mediaelement needs to be in the visual tree to get the events.
lh
Saturday, December 7, 2013 2:51 PM -
Is this not firing the bookmark or is this not playing at all?
I'd expect the latter. As Lars says, the MediaElement should be in the visual tree (but can be hidden). You'll also need to wait for the source to be ready before calling Play. Either set the MediaElement to AutoPlay or listen for CurrentStateChanged and call Play after that reports it ready. This may not be an issue with the preloaded stream from the SpeechSynthesizer, but it's necessary for the general case.
--Rob
Saturday, December 7, 2013 10:12 PMModerator -
why not on a surface pro? been thinking about getting one for development.
you are right! adding it to the tree makes everything work.
Sunday, December 8, 2013 7:45 AM -
thanks for the quick reply!
it is playing without issue. as Lars mentioned, it needs to be in the tree to work. same thing with playing overlapping sounds.
this is really weird behavior and you guys should at the minimum document it! i don't see why it shouldn't work without being in the visual tree, especially if it plays. there's got to be a way you can rig it up in the back end to remove this requirement.
Sunday, December 8, 2013 7:46 AM -
i also made the AutoPlay change as you suggested.
seems I have a bigger problem though... after playing a few streams, I get the following error:
"A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Unknown Module.
Additional information: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
If there is a handler for this exception, the program may be safely continued."
and then
"
An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module.
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
If there is a handler for this exception, the program may be safely continued.
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
After that message, the app crashes.
This is a C# app that doesn't use any custom native libraries.
How can I debug this problem further?
Thanks
Sunday, December 8, 2013 8:26 AM -
continuing the crash on this thread... got an easy repro for it too:
Monday, December 9, 2013 8:27 AM