SpeechSynthesizer 클래스

정의

TTS(텍스트 음성 변환) 서비스에 설치된 음성 합성 엔진(음성)의 기능에 대한 액세스를 제공합니다.

public ref class SpeechSynthesizer sealed : IClosable
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class SpeechSynthesizer final : IClosable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class SpeechSynthesizer final : IClosable
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class SpeechSynthesizer : System.IDisposable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class SpeechSynthesizer : System.IDisposable
function SpeechSynthesizer()
Public NotInheritable Class SpeechSynthesizer
Implements IDisposable
상속
Object Platform::Object IInspectable SpeechSynthesizer
특성
구현

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)

예제

다음 예제에서는 기본 텍스트 문자열에서 음성 오디오 스트림을 생성하는 방법을 보여줍니다.

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

이 예제에서는 음성 출력의 피치, 말하기 속도 및 볼륨을 제어하는 일부 변조 요소를 포함하는 SSML 문자열에서 음성 오디오 스트림을 생성하는 방법을 보여 줍니다.

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

설명

시스템에 설치된 Microsoft 서명된 음성만 음성을 생성하는 데 사용할 수 있습니다.

Windows에는 다양한 언어에 사용할 수 있는 다양한 Microsoft 서명 음성이 포함되어 있습니다. 각 음성은 특정 국가/지역에서 말하는 것처럼 단일 언어로 합성된 음성을 생성합니다.

기본적으로 새 SpeechSynthesizer 개체는 현재 시스템 음성을 사용합니다( DefaultVoice 를 호출하여 기본 음성이 무엇인지 확인).

사용자 시스템에 설치된 다른 음성 합성(텍스트 음성 변환) 음성을 지정하려면 Voice 메서드를 사용합니다(시스템에 설치된 음성 을 찾으려면 AllVoices를 호출).

언어를 지정하지 않으면 언어 제어판에서 선택한 언어에 가장 가까운 음성이 로드됩니다.

SpeechSynthesizer 개체를 사용하여 다음을 수행합니다.

버전 기록

Windows 버전 SDK 버전 추가된 값
1703 15063 옵션
1709 16299 TrySetDefaultVoiceAsync

생성자

SpeechSynthesizer()

SpeechSynthesizer 개체의 새 instance 초기화합니다.

속성

AllVoices

설치된 모든 음성 합성 엔진(음성)의 컬렉션을 가져옵니다.

DefaultVoice

기본 음성 합성 엔진(음성)을 가져옵니다.

Options

SpeechSynthesizer 개체에서 설정할 수 있는 옵션 컬렉션에 대한 참조를 가져옵니다.

Voice

음성 합성 엔진(음성)을 가져오거나 설정합니다.

메서드

Close()

SpeechSynthesizer를 닫고 시스템 리소스를 해제합니다.

Dispose()

관리되지 않는 리소스의 확보, 해제 또는 다시 설정과 관련된 애플리케이션 정의 작업을 수행합니다.

SynthesizeSsmlToStreamAsync(String)

SSML(Speech Synthesis Markup Language) 버전 1.1 문자열에서 음성 출력을 비동기적으로 생성하고 제어합니다.

SynthesizeTextToStreamAsync(String)

문자열에서 음성 출력을 비동기적으로 생성합니다.

TrySetDefaultVoiceAsync(VoiceInformation)

IoT 디바이스에서 음성 합성에 사용되는 음성을 비동기적으로 설정하려고 시도합니다.

참고

이 메서드는 포함 모드에서만 사용할 수 있습니다.

적용 대상

추가 정보