Edit

Share via


TextToSpeech Class

Definition

Enables text to speech using the Windows 10 SpeechSynthesizer class.

public ref class TextToSpeech : UnityEngine::MonoBehaviour
[UnityEngine.AddComponentMenu("Scripts/MRTK/SDK/TextToSpeech")]
[UnityEngine.RequireComponent(typeof(UnityEngine.AudioSource))]
public class TextToSpeech : UnityEngine.MonoBehaviour
[<UnityEngine.AddComponentMenu("Scripts/MRTK/SDK/TextToSpeech")>]
[<UnityEngine.RequireComponent(typeof(UnityEngine.AudioSource))>]
type TextToSpeech = class
    inherit MonoBehaviour
Public Class TextToSpeech
Inherits MonoBehaviour
Inheritance
UnityEngine.MonoBehaviour
TextToSpeech
Attributes
UnityEngine.AddComponentMenuAttribute UnityEngine.RequireComponentAttribute

Remarks

SpeechSynthesizer generates speech as a SpeechSynthesisStream.

This class converts that stream into a Unity AudioClip and plays the clip using the AudioSource you supply in the inspector. This allows you to position the voice as desired in 3D space. One recommended approach is to place the AudioSource on an empty GameObject that is a child of Main Camera and position it approximately 0.6 units above the camera. This orientation will sound similar to Cortana's speech in the OS.

Constructors

TextToSpeech()

Properties

AudioSource

Gets or sets the audio source where speech will be played.

Voice

Gets or sets the voice that will be used to generate speech. To use a non en-US voice, set this to Other.

VoiceName

Gets or sets the voice that will be used to generate speech.

Methods

IsSpeaking()

Returns whether or not the AudioSource is actively playing.

SpeakSsml(String)

Speaks the specified SSML markup using text-to-speech.

SpeechTextInQueue()

Returns info whether a text is submitted and being processed by PlaySpeech method Handy for avoiding situations when a text is submitted, but audio clip is not yet ready because the audio source isn't playing yet. Example: yield return new WaitWhile(() => textToSpeechManager.SpeechTextInQueue() || textToSpeechManager.IsSpeaking())

StartSpeaking(String)

Speaks the specified text using text-to-speech.

StopSpeaking()

Stops text-to-speech playback.

Applies to