在 PowerShell 中用 System.Speech 实现文字转语音

无需第三方工具:.NET 的 SpeechSynthesizer 能把任意文本朗读出来——适合让脚本发出语音提醒。

Windows语音合成媒体PowerShell低风险
运行 `Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('要朗读的文本')` 即可听到朗读。

01命令

命令
$ Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('Backup finished successfully.')

02作用说明

System.Speech 随 .NET Framework 一起发布,所以每台 Windows 的 PowerShell 都自带它,Add-Type 只是把程序集加载进会话。除了 Speak(),合成器还支持 SpeakAsync 异步朗读、SetOutputToWaveFile 把语音渲染成 WAV 文件、SelectVoice 选择已安装的语音。注意新的 PowerShell 7(.NET Core)要用别的程序集,System.Speech 仅限 Windows,所以最稳妥的还是在自带的 Windows PowerShell 5.1 里运行。

03风险

风险低风险
使用条件Works in Windows PowerShell 5.1; voices installed with Windows (e.g. Microsoft Zira/David) are used automatically.

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • SpeechSynthesizer Class | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    依据: Microsoft documents System.Speech.Synthesis.SpeechSynthesizer and its Speak method for text-to-speech synthesis in .NET.

最后验证: 2026-09-17 · 分类: 媒体

06相关方案