Note
Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.
SpeechSynthesizer.Speak Method (Prompt)
Synchronously speaks the contents of a Prompt object.
Namespace: Microsoft.Speech.Synthesis
Assembly: Microsoft.Speech (in Microsoft.Speech.dll)
Syntax
'Declaration
Public Sub Speak ( _
prompt As Prompt _
)
'Usage
Dim instance As SpeechSynthesizer
Dim prompt As Prompt
instance.Speak(prompt)
public void Speak(
Prompt prompt
)
Parameters
- prompt
Type: Microsoft.Speech.Synthesis.Prompt
The content to speak.
Remarks
To asynchronously speak the contents of a Prompt object, use SpeakAsync(Prompt).
Examples
The following example creates a Prompt object from a string and passes the object as an argument to the Speak(Prompt) method.
using System;
using Microsoft.Speech.Synthesis;
namespace SampleSynthesis
{
class Program
{
static void Main(string[] args)
{
// Initialize a new instance of the SpeechSynthesizer.
using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
// Configure the audio output.
synth.SetOutputToWaveFile(@"C:\Test\Color.wav");
// Create a SoundPlayer instance to play the output audio file.
System.Media.SoundPlayer m_SoundPlayer =
new System.Media.SoundPlayer(@"C:\Test\Color.wav");
// Create a prompt from a string.
Prompt color = new Prompt("What is your favorite color?");
// Speak the contents of the prompt synchronously and play the output file.
synth.Speak(color);
m_SoundPlayer.Play();
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}