更改用 C# 编写的 tts 程序的输出设备在 Windows 10 中不起作用

Changing output device for tts program written in C# not working in Windows 10

当我尝试在用 C# 编写的 tts 控制台应用程序的高级音频设置中将输出设备更改为我的虚拟电缆时,音频在我的普通设备上播放。我该如何解决?代码:

using System;
using System.Speech.Synthesis;
namespace hhhh
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("Initialized");

            while (true)
            {
                SpeechSynthesizer synthesizer = new SpeechSynthesizer();

                synthesizer.Speak(Console.ReadLine());

            }
        }

       }
    }

您可能必须配置 synthesizer 对象以侦听特定设备,即默认 synthesizer.SetOutputToDefaultAudioDevice() 或特定目标设备 synthesizer.SetOutputToAudioStream(deviceout, audioformat);

看看this documentation