SpeechSynthesisStream 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
支持读取和写入语音合成引擎生成的音频数据, (语音) 随机访问流。
public ref class SpeechSynthesisStream sealed : IClosable
public ref class SpeechSynthesisStream sealed : IClosable, ITimedMetadataTrackProvider
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class SpeechSynthesisStream final : IClosable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class SpeechSynthesisStream final : IClosable, ITimedMetadataTrackProvider
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class SpeechSynthesisStream : System.IDisposable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class SpeechSynthesisStream : System.IDisposable, ITimedMetadataTrackProvider
Public NotInheritable Class SpeechSynthesisStream
Implements IDisposable
Public NotInheritable Class SpeechSynthesisStream
Implements IDisposable, ITimedMetadataTrackProvider
- 继承
- 属性
- 实现
Windows 要求
设备系列 |
Windows 10 (在 10.0.10240.0 中引入)
|
API contract |
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)
|
示例
UWP 应用可以使用 SpeechSynthesizer 对象来创建音频流,并根据纯文本字符串输出语音。
// The media object for controlling and playing audio.
MediaElement mediaElement = this.media;
// The object for controlling the speech synthesis engine (voice).
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
// Generate the audio stream from plain text.
SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync("Hello World");
// Send the stream to the media object.
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();
// The object for controlling the speech synthesis engine (voice).
synth = ref new SpeechSynthesizer();
// The media object for controlling and playing audio.
media = ref new MediaElement();
// The string to speak.
String^ text = "Hello World";
// Generate the audio stream from plain text.
task<SpeechSynthesisStream ^> speakTask = create_task(synth->SynthesizeTextToStreamAsync(text));
speakTask.then([this, text](SpeechSynthesisStream ^speechStream)
{
// Send the stream to the media object.
// media === MediaElement XAML object.
media->SetSource(speechStream, speechStream->ContentType);
media->AutoPlay = true;
media->Play();
});
// The string to speak with SSML customizations.
string Ssml =
@"<speak version='1.0' " +
"xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'>" +
"Hello <prosody contour='(0%,+80Hz) (10%,+80%) (40%,+80Hz)'>World</prosody> " +
"<break time='500ms'/>" +
"Goodbye <prosody rate='slow' contour='(0%,+20Hz) (10%,+30%) (40%,+10Hz)'>World</prosody>" +
"</speak>";
// The media object for controlling and playing audio.
MediaElement mediaElement = this.media;
// The object for controlling the speech synthesis engine (voice).
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
// Generate the audio stream from plain text.
SpeechSynthesisStream stream = await synth.synthesizeSsmlToStreamAsync(Ssml);
// Send the stream to the media object.
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();
// The object for controlling the speech synthesis engine (voice).
synth = ref new SpeechSynthesizer();
// The media object for controlling and playing audio.
media = ref new MediaElement();
// The string to speak.
String^ ssml =
"<speak version='1.0' "
"xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'>"
"Hello <prosody contour='(0%,+80Hz) (10%,+80%) (40%,+80Hz)'>World</prosody>"
"<break time='500ms' /> "
"Goodbye <prosody rate='slow' contour='(0%,+20Hz) (10%,+30%) (40%,+10Hz)'>World</prosody>"
"</speak>";
// Generate the audio stream from SSML.
task<SpeechSynthesisStream ^> speakTask = create_task(synth->SynthesizeSsmlToStreamAsync(ssml));
speakTask.then([this, ssml](SpeechSynthesisStream ^speechStream)
{
// Send the stream to the media object.
// media === MediaElement XAML object.
media->SetSource(speechStream, speechStream->ContentType);
media->AutoPlay = true;
media->Play();
});
注解
版本历史记录
Windows 版本 | SDK 版本 | 已添加值 |
---|---|---|
1703 | 15063 | TimedMetadataTracks |
属性
CanRead |
获取是否可以从 中读取 SpeechSynthesisStream 。 |
CanWrite |
获取一个值,该值指示 SpeechSynthesisStream 是否可以写入。 |
ContentType |
获取 SpeechSynthesisStream 内容的 MIME 类型。 |
Markers |
获取与 SpeechSynthesisStream 关联的时间线标记的集合。 注意 SpeechSynthesisStream.Markers 已弃用。 建议将 MediaPlayerElement 和 MediaPlaybackItem 对象与 SpeechSynthesizerOptions 对象的 IncludeSentenceParametadata 和 IncludeWordMetadata 属性 () 。 |
Position |
获取 SpeechSynthesisStream 中的当前位置。 |
Size |
获取或设置 SpeechSynthesisStream 的大小。 |
TimedMetadataTracks |
获取语音合成流中由 SpeechSynthesizer.Options 属性指定的可选单词和句子边界的集合。 |
方法
CloneStream() |
创建 SpeechSynthesisStream 的副本,该副本引用与原始流相同的字节。 |
Close() |
释放 SpeechSynthesisStream 公开的系统资源。 |
Dispose() |
执行与释放或重置非托管资源关联的应用程序定义的任务。 |
FlushAsync() |
在顺序流中异步刷新数据。 |
GetInputStreamAt(UInt64) |
检索 SpeechSynthesisStream 中指定位置的输入流。 |
GetOutputStreamAt(UInt64) |
检索 SpeechSynthesisStream 中指定位置的输出流。 |
ReadAsync(IBuffer, UInt32, InputStreamOptions) |
在顺序流中异步读取数据。 |
Seek(UInt64) |
转到 SpeechSynthesisStream 中的指定位置。 |
WriteAsync(IBuffer) |
在顺序流中异步写入数据。 |