Bagikan melalui


SpeechSynthesisStream Kelas

Definisi

Mendukung pembacaan dan penulisan data audio yang dihasilkan oleh mesin sintesis ucapan (suara) ke/dari aliran akses acak.

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
Warisan
Object Platform::Object IInspectable SpeechSynthesisStream
Atribut
Penerapan

Persyaratan Windows

Rangkaian perangkat
Windows 10 (diperkenalkan dalam 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (diperkenalkan dalam v1.0)

Contoh

Aplikasi UWP Anda dapat menggunakan objek SpeechSynthesizer untuk membuat aliran audio dan ucapan output berdasarkan string teks biasa.

// 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();
});

Keterangan

Riwayat versi

Versi Windows Versi SDK Nilai ditambahkan
1703 15063 TimedMetadataTracks

Properti

CanRead

Mendapatkan apakah SpeechSynthesisStream dapat dibaca.

CanWrite

Mendapatkan nilai yang menunjukkan apakah SpeechSynthesisStream dapat ditulis.

ContentType

Mendapatkan jenis MIME konten SpeechSynthesisStream.

Markers

Mendapatkan kumpulan penanda garis waktu yang terkait dengan SpeechSynthesisStream.

Catatan

SpeechSynthesisStream.Markers tidak digunakan lagi. Sebaiknya gunakan objek MediaPlayerElement dan MediaPlaybackItem sebagai gantinya (bersama dengan properti IncludeSentenceBoundaryMetadata dan IncludeWordBoundaryMetadata dari objek SpeechSynthesizerOptions ).

Position

Mendapatkan posisi saat ini dalam SpeechSynthesisStream.

Size

Mendapatkan atau mengatur ukuran SpeechSynthesisStream.

TimedMetadataTracks

Mendapatkan kumpulan batas kata dan kalimat opsional dalam aliran sintesis ucapan seperti yang ditentukan oleh properti SpeechSynthesizer.Options .

Metode

CloneStream()

Membuat salinan SpeechSynthesisStream yang mereferensikan byte yang sama dengan aliran asli.

Close()

Merilis sumber daya sistem yang diekspos oleh SpeechSynthesisStream.

Dispose()

Melakukan tugas yang ditentukan aplikasi yang terkait dengan membebaskan, melepaskan, atau mereset sumber daya yang tidak terkelola.

FlushAsync()

Menghapus data secara asinkron dalam aliran berurutan.

GetInputStreamAt(UInt64)

Mengambil aliran input di lokasi tertentu di SpeechSynthesisStream.

GetOutputStreamAt(UInt64)

Mengambil aliran output di lokasi tertentu di SpeechSynthesisStream.

ReadAsync(IBuffer, UInt32, InputStreamOptions)

Membaca data secara asinkron dalam aliran berurutan.

Seek(UInt64)

Masuk ke posisi yang ditentukan dalam SpeechSynthesisStream.

WriteAsync(IBuffer)

Menulis data secara asinkron dalam aliran berurutan.

Berlaku untuk

Lihat juga