SpeechSynthesizer.SetOutputToDefaultAudioDevice 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
設定SpeechSynthesizer物件,以便將輸出傳送至預設音訊裝置。
public:
void SetOutputToDefaultAudioDevice();
C#
public void SetOutputToDefaultAudioDevice();
member this.SetOutputToDefaultAudioDevice : unit -> unit
Public Sub SetOutputToDefaultAudioDevice ()
下列範例會使用合成器將片語讀出預設音訊輸出。
C#
using System;
using System.Speech.Synthesis;
namespace SampleSynthesis
{
class Program
{
static void Main(string[] args)
{
// Initialize a new instance of the speech synthesizer.
using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
// Configure the synthesizer to send output to the default audio device.
synth.SetOutputToDefaultAudioDevice();
// Speak a phrase.
synth.Speak("This is sample text-to-speech output.");
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
您可以使用 Windows主控台中的[音效] 視窗來設定電腦的預設音訊裝置。
如需其他輸出組態選項,請參閱 SetOutputToAudioStream 、 SetOutputToNullSetOutputToWaveFile 和 SetOutputToWaveStream 方法。
產品 | 版本 |
---|---|
.NET | 8 (package-provided), 9 (package-provided), 10 (package-provided) |
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |