You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否在System.Speech.Synthesis中使用Windows 11本地新增自然语音?

问题解答

核心结论

可以本地使用Windows 11新增的自然语音,但System.Speech.Synthesis无法直接识别它们——这套API基于旧版SAPI框架,而Windows 11的新自然语音属于WinRT体系的Windows Speech API,两者底层不兼容。

替代方案:使用WinRT SpeechSynthesizer

要在WPF中本地调用这些新语音,需改用WinRT的Windows.Media.SpeechSynthesis.SpeechSynthesizer,步骤如下:

  1. 启用WinRT支持
    右键WPF项目→编辑项目文件,添加以下配置:

    <PropertyGroup>
      <TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
      <UseWPF>true</UseWPF>
      <EnableWindowsRuntimeSupport>true</EnableWindowsRuntimeSupport>
    </PropertyGroup>
    

    注意:目标框架需指定为支持WinRT的Windows版本(如net6.0-windows10.0.19041.0及以上)。

  2. 编写调用代码
    示例代码如下:

    using Windows.Media.SpeechSynthesis;
    using Windows.Storage.Streams;
    using System.Windows.Media;
    using System.Linq;
    
    // 获取所有已安装的新自然语音
    var allVoices = SpeechSynthesizer.AllVoices;
    foreach (var voice in allVoices)
    {
        Console.WriteLine($"{voice.DisplayName} - {voice.Language}");
    }
    
    // 选择目标语音并合成播放
    var synthesizer = new SpeechSynthesizer();
    synthesizer.Voice = allVoices.First(v => v.DisplayName.Contains("Microsoft Jenny Online (Natural)"));
    var speechStream = await synthesizer.SynthesizeTextToStreamAsync("这是Windows 11自然语音的测试内容");
    
    // 转换流格式适配WPF播放
    var mediaStreamSource = new MediaStreamSource(new WinRtStreamAdapter(speechStream));
    var mediaPlayer = new MediaPlayer();
    mediaPlayer.Open(mediaStreamSource);
    mediaPlayer.Play();
    

    注:WinRtStreamAdapter用于桥接WinRT流和WPF的MediaStreamSource,可自行实现或借助WinRT.Storage.Streams NuGet包简化转换。

  3. 权限配置(可选)
    若项目包含Package.appxmanifest,添加语音相关能力声明:

    <Capabilities>
      <DeviceCapability Name="speechRecognition" />
    </Capabilities>
    

    本地合成无需联网权限,可按需调整。

关键原因说明

  • System.Speech依赖的SAPI是Windows旧版语音框架,仅支持传统SAPI格式的语音包;
  • Windows 11新增的自然语音属于Windows Speech Platform v11或Edge TTS体系,仅通过WinRT API开放访问,不兼容旧版SAPI接口。

内容的提问来源于stack exchange,提问作者Lee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 11:02:20