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

Windows11 2023更新后如何在PowerShell中访问新增自然语音

在PowerShell中访问Windows 11讲述人新增的自然TTS语音

我们可以用以下PowerShell脚本列出并使用Windows传统的文本转语音(TTS)功能:

Add-Type -AssemblyName System.speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speak.GetInstalledVoices()|ForEach-Object { $_.VoiceInfo }

运行后会返回类似这样的传统语音信息:

Gender                : Male
Age                   : Adult
Name                  : Microsoft David Desktop
Culture               : en-US
Id                    : TTS_MS_EN-US_DAVID_11.0
Description           : Microsoft David Desktop - English (United States)
SupportedAudioFormats : {}
AdditionalInfo        : {[Age, Adult], [Gender, Male], [Language, 409], [Name, Microsoft David Desktop]...}

Gender                : Female
Age                   : Adult
Name                  : Microsoft Zira Desktop
Culture               : en-US
Id                    : TTS_MS_EN-US_ZIRA_11.0
Description           : Microsoft Zira Desktop - English (United States)
SupportedAudioFormats : {}
AdditionalInfo        : {[Age, Adult], [Gender, Female], [Language, 409], [Name, Microsoft Zira Desktop]...}

但2023年Windows 11的最新更新后,上述脚本无法列出讲述人(Narrator)新增的自然语音(可通过「设置 > 辅助功能 > 讲述人」路径查看这类语音)。这类语音不属于.NET Framework的System.Speech.Synthesis命名空间范畴,需要改用UWP的Windows.Media.SpeechSynthesis命名空间来访问。

列出所有自然语音的脚本

# 加载必要的运行时程序集
Add-Type -AssemblyName System.Runtime.WindowsRuntime

# 获取异步操作转Task的通用方法
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | Where-Object { 
    $_.Name -eq 'AsTask' -and 
    $_.GetParameters().Count -eq 1 -and 
    $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' 
})[0]

# 获取所有已安装的TTS语音(包括自然语音)
$speechSynthesisType = [Windows.Media.SpeechSynthesis.SpeechSynthesizer, Windows.Foundation, ContentType=WindowsRuntime]
$voicesAsyncOp = $speechSynthesisType::AllVoicesAsync()
$asTaskMethod = $asTaskGeneric.MakeGenericMethod([Windows.Media.SpeechSynthesis.VoiceInformation[]])
$allVoices = $asTaskMethod.Invoke($null, @($voicesAsyncOp)).Result

# 格式化输出语音信息
$allVoices | ForEach-Object {
    [PSCustomObject]@{
        语音名称 = $_.DisplayName
        语音ID = $_.Id
        语言区域 = $_.Language
        性别 = $_.Gender
        描述 = $_.Description
    }
}

运行该脚本后,就能看到包括Microsoft Jenny (Natural)在内的所有自然语音条目。

使用指定自然语音朗读文本

如果要调用Microsoft Jenny (Natural)进行文本朗读,可以用以下脚本:

# 加载必要的运行时程序集
Add-Type -AssemblyName System.Runtime.WindowsRuntime

# 获取异步操作转Task的通用方法
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | Where-Object { 
    $_.Name -eq 'AsTask' -and 
    $_.GetParameters().Count -eq 1 -and 
    $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' 
})[0]

# 获取所有语音并筛选目标语音
$speechSynthesisType = [Windows.Media.SpeechSynthesis.SpeechSynthesizer, Windows.Foundation, ContentType=WindowsRuntime]
$voicesAsyncOp = $speechSynthesisType::AllVoicesAsync()
$asTaskMethod = $asTaskGeneric.MakeGenericMethod([Windows.Media.SpeechSynthesis.VoiceInformation[]])
$allVoices = $asTaskMethod.Invoke($null, @($voicesAsyncOp)).Result
$targetVoice = $allVoices | Where-Object { $_.DisplayName -eq 'Microsoft Jenny (Natural)' }

# 创建语音合成器并设置目标语音
$synth = New-Object Windows.Media.SpeechSynthesis.SpeechSynthesizer
$synth.Voice = $targetVoice

# 生成语音流并播放
$text = "Hello, this is a test using Microsoft Jenny's natural voice."
$speechStreamAsyncOp = $synth.SynthesizeTextToStreamAsync($text)
$speechStream = $asTaskGeneric.MakeGenericMethod([Windows.Media.SpeechSynthesis.SpeechSynthesisStream]).Invoke($null, @($speechStreamAsyncOp)).Result

$player = New-Object Windows.Media.Playback.MediaPlayer
$player.SetSource($speechStream, $speechStream.ContentType)
$player.Play()

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 14:53:14