PromptBuilder.AppendBookmark(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在物件上附加書籤 PromptBuilder 。
public:
void AppendBookmark(System::String ^ bookmarkName);
public void AppendBookmark(string bookmarkName);
member this.AppendBookmark : string -> unit
Public Sub AppendBookmark (bookmarkName As String)
參數
- bookmarkName
- String
一串包含附加書籤名稱的串。
範例
以下範例建立一個包含兩個書籤的提示,並將輸出傳送到 WAV 檔案進行播放。 事件處理 BookmarkReached 程序會寫入書籤名稱及其在事件被上傳至主控台時的音訊串流中的位置。
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.SetOutputToWaveFile(@"C:\test\weather.wav");
// Create a SoundPlayer instance to play the output audio file.
System.Media.SoundPlayer m_SoundPlayer =
new System.Media.SoundPlayer(@"C:\test\weather.wav");
// Build a prompt and append bookmarks.
PromptBuilder builder = new PromptBuilder(
new System.Globalization.CultureInfo("en-US"));
builder.AppendText(
"The weather forecast for today is partly cloudy with some sun breaks.");
builder.AppendBookmark("Daytime forecast");
builder.AppendText(
"Tonight's weather will be cloudy with a 30% chance of showers.");
builder.AppendBookmark("Nighttime forecast");
// Add a handler for the BookmarkReached event.
synth.BookmarkReached +=
new EventHandler<BookmarkReachedEventArgs>(synth_BookmarkReached);
// Speak the prompt and play back the output file.
synth.Speak(builder);
m_SoundPlayer.Play();
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
// Write the name and position of the bookmark to the console.
static void synth_BookmarkReached(object sender, BookmarkReachedEventArgs e)
{
Console.WriteLine("Bookmark ({0}) reached at: {1} ",
e.Bookmark, e.AudioPosition);
}
}
}
備註
語音合成引擎若在使用任一BookmarkReached、SpeakSpeakAsyncSpeakSsml或方法的提示時遇到書籤,會產生SpeakSsmlAsync事件。