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 app 可以使用 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物件的IncludeSentenceBoundaryMetadata和IncludeWordBoundaryMetadata屬性) 。 |
Position |
取得 SpeechSynthesisStream中的目前位置。 |
Size |
取得或設定 SpeechSynthesisStream的大小。 |
TimedMetadataTracks |
取得 SpeechSynthesizer.Options 屬性所指定之語音合成資料流程中的選擇性字組和句子界限集合。 |
方法
CloneStream() |
建立 SpeechSynthesisStream 的複本,參考與原始資料流程相同的位元組。 |
Close() |
釋放 SpeechSynthesisStream公開的系統資源。 |
Dispose() |
執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。 |
FlushAsync() |
在循序資料流程中以非同步方式排清資料。 |
GetInputStreamAt(UInt64) |
在 SpeechSynthesisStream中指定的位置擷取輸入資料流程。 |
GetOutputStreamAt(UInt64) |
擷取 SpeechSynthesisStream中指定位置的輸出資料流程。 |
ReadAsync(IBuffer, UInt32, InputStreamOptions) |
以非同步方式在循序資料流程中讀取資料。 |
Seek(UInt64) |
移至 SpeechSynthesisStream中指定的位置。 |
WriteAsync(IBuffer) |
以非同步方式在循序資料流程中寫入資料。 |