Prompt 构造函数

定义

创建类的新实例 Prompt

重载

名称 说明
Prompt(PromptBuilder)

Prompt对象创建类的新实例PromptBuilder

Prompt(String)

创建类的新实例 Prompt ,并指定要说出的文本。

Prompt(String, SynthesisTextFormat)

创建类的新实例 Prompt ,并指定要说出的文本以及其格式是纯文本还是标记语言。

Prompt(PromptBuilder)

Prompt对象创建类的新实例PromptBuilder

public:
 Prompt(System::Speech::Synthesis::PromptBuilder ^ promptBuilder);
public Prompt(System.Speech.Synthesis.PromptBuilder promptBuilder);
new System.Speech.Synthesis.Prompt : System.Speech.Synthesis.PromptBuilder -> System.Speech.Synthesis.Prompt
Public Sub New (promptBuilder As PromptBuilder)

参数

promptBuilder
PromptBuilder

要说的内容。

适用于

Prompt(String)

创建类的新实例 Prompt ,并指定要说出的文本。

public:
 Prompt(System::String ^ textToSpeak);
public Prompt(string textToSpeak);
new System.Speech.Synthesis.Prompt : string -> System.Speech.Synthesis.Prompt
Public Sub New (textToSpeak As String)

参数

textToSpeak
String

要朗读的文本。

示例

以下示例从字符串创建一个 Prompt 对象,并将该对象作为参数传递给 Speak 该方法。

using System;
using System.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.SetOutputToDefaultAudioDevice();

        // Create a prompt from a string.
        Prompt color = new Prompt("What is your favorite color?");

        // Speak the contents of the prompt synchronously.
        synth.Speak(color);
      }

      Console.WriteLine();
      Console.WriteLine("Press any key to exit...");
      Console.ReadKey();
    }
  }
}

适用于

Prompt(String, SynthesisTextFormat)

创建类的新实例 Prompt ,并指定要说出的文本以及其格式是纯文本还是标记语言。

public:
 Prompt(System::String ^ textToSpeak, System::Speech::Synthesis::SynthesisTextFormat media);
public Prompt(string textToSpeak, System.Speech.Synthesis.SynthesisTextFormat media);
new System.Speech.Synthesis.Prompt : string * System.Speech.Synthesis.SynthesisTextFormat -> System.Speech.Synthesis.Prompt
Public Sub New (textToSpeak As String, media As SynthesisTextFormat)

参数

textToSpeak
String

要朗读的文本。

media
SynthesisTextFormat

一个指定文本格式的值。

示例

以下示例生成一个包含 SSML 标记的字符串,从字符串创建对象 Prompt ,并朗讲提示。

using System;
using System.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.SetOutputToDefaultAudioDevice();

        // Build an SSML prompt in a string.
        string fileName = "<speak version=\"1.0\" ";
        fileName += "xmlns=\"http://www.w3.org/2001/10/synthesis\" ";
        fileName += "xml:lang=\"en-US\">";
        fileName += "Say a name for the new file <mark name=\"fileName\" />.";
        fileName += "</speak>";

        // Create a Prompt object from the string.
        Prompt ssmlFile = new Prompt(fileName, SynthesisTextFormat.Ssml);

        // Speak the contents of the SSML prompt.
        synth.Speak(ssmlFile);
      }

      Console.WriteLine();
      Console.WriteLine("Press any key to exit...");
      Console.ReadKey();
    }
  }
}

注解

参数的内容 textToSpeak 必须包含一个 speak 元素,并且必须符合 语音合成标记语言 (SSML) 版本 1.0。 有关详细信息,请参阅 语音合成标记语言参考

适用于