我正在开发一个 TTS(文本到语音)应用程序,我需要展示每个语音的持续时间。问题是它总是返回零。任何帮助都是最受欢迎的。谢谢。
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
MediaPlayerElement mediaPlayerElement = new MediaPlayerElement();
SpeechSynthesisStream stream = await synthesizer.SynthesizeTextToStreamAsync("Some text...");
mediaPlayerElement.Source = MediaSource.CreateFromStream(stream, stream.ContentType);
mediaPlayerElement.MediaPlayer.Play();
string strDuration = mediaPlayerElement.MediaPlayer.PlaybackSession.NaturalDuration.Milliseconds.ToString();
MessageDialog msgDlg = new MessageDialog(strDuration);
await msgDlg.ShowAsync();