SpeechSynthesisStream Класс

Определение

Поддерживает чтение и запись звуковых данных, созданных подсистемой синтеза речи (голосом), в поток произвольного доступа и из нее.

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
Наследование
Object Platform::Object IInspectable SpeechSynthesisStream
Атрибуты
Реализации

Требования к 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

Возвращает тип MIME содержимого SpeechSynthesisStream.

Markers

Возвращает коллекцию маркеров временная шкала, связанных с SpeechSynthesisStream.

Примечание

SpeechSynthesisStream.Markers является нерекомендуемой. Вместо этого рекомендуется использовать объекты MediaPlayerElement и MediaPlaybackItem (в сочетании со свойствами IncludeSentenceBoundaryMetadata и IncludeWordBoundaryMetadata объекта SpeechSynthesizerOptions ).

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)

Асинхронно записывает данные в последовательный поток.

Применяется к

См. также раздел