返回顶部
s

sapi-ttsSAPI语音合成

Windows SAPI5 text-to-speech with Neural voices. Lightweight alternative to GPU-heavy TTS - zero GPU usage, instant generation. Auto-detects best available voice for your language. Works on Windows 10/11.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.1.0
安全检测
已通过
2,493
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

sapi-tts

SAPI5 TTS (Windows)

使用Windows内置SAPI5的轻量级文本转语音。零GPU占用,即时生成。

安装

将以下脚本保存为技能文件夹中的 tts.ps1:

powershell
<#
.SYNOPSIS
Windows SAPI5 TTS - 轻量级文本转语音
.DESCRIPTION
使用Windows内置语音合成(SAPI5)。
支持神经语音(Win11)或传统语音(Win10)。
零GPU占用,即时生成。
#>

param(
[Parameter(Mandatory=$false, Position=0)]
[string]$Text = ,

[Parameter(Mandatory=$false)]
[Alias(Voice, v)]
[string]$VoiceName = ,

[Parameter(Mandatory=$false)]
[Alias(Lang, l)]
[string]$Language = fr,

[Parameter(Mandatory=$false)]
[Alias(o)]
[string]$Output = ,

[Parameter(Mandatory=$false)]
[Alias(r)]
[int]$Rate = 0,

[Parameter(Mandatory=$false)]
[Alias(p)]
[switch]$Play,

[Parameter(Mandatory=$false)]
[switch]$ListVoices
)

Add-Type -AssemblyName System.Speech
$synth = New-Object System.Speech.Synthesis.SpeechSynthesizer

$installedVoices = $synth.GetInstalledVoices() | Where-Object { $.Enabled } | ForEach-Object { $.VoiceInfo }

if ($ListVoices) {
Write-Host n已安装的SAPI5语音:n -ForegroundColor Cyan
foreach ($v in $installedVoices) {
$type = if ($v.Name -match Online|Neural) { [神经] } else { [传统] }
Write-Host $($v.Name) -ForegroundColor White -NoNewline
Write-Host $type -ForegroundColor DarkGray -NoNewline
Write-Host - $($v.Culture) $($v.Gender) -ForegroundColor Gray
}
Write-Host
$synth.Dispose()
exit 0
}

if (-not $Text) {
Write-Error 需要提供文本。使用:.\tts.ps1 您的文本
Write-Host 使用 -ListVoices 查看可用语音
$synth.Dispose()
exit 1
}

function Select-BestVoice {
param($voices, $preferredName, $lang)

if ($preferredName) {
$match = $voices | Where-Object { $_.Name -like $preferredName } | Select-Object -First 1
if ($match) { return $match }
Write-Warning 未找到语音$preferredName,正在自动选择...
}

$cultureMap = @{
fr = fr-FR; french = fr-FR
en = en-US; english = en-US
de = de-DE; german = de-DE
es = es-ES; spanish = es-ES
it = it-IT; italian = it-IT
}
$targetCulture = $cultureMap[$lang.ToLower()]
if (-not $targetCulture) { $targetCulture = $lang }

$neuralMatch = $voices | Where-Object {
$.Name -match Online|Neural -and $.Culture.Name -eq $targetCulture
} | Select-Object -First 1
if ($neuralMatch) { return $neuralMatch }

$langMatch = $voices | Where-Object { $_.Culture.Name -eq $targetCulture } | Select-Object -First 1
if ($langMatch) { return $langMatch }

$anyNeural = $voices | Where-Object { $_.Name -match Online|Neural } | Select-Object -First 1
if ($anyNeural) { return $anyNeural }

return $voices | Select-Object -First 1
}

$selectedVoice = Select-BestVoice -voices $installedVoices -preferredName $VoiceName -lang $Language

if (-not $selectedVoice) {
Write-Error 未找到SAPI5语音!请在Windows设置 > 时间和语言 > 语音中安装语音
$synth.Dispose()
exit 1
}

if (-not $Output) {
$ttsDir = $env:USERPROFILE\.openclaw\workspace\tts
if (-not (Test-Path $ttsDir)) { New-Item -ItemType Directory -Path $ttsDir -Force | Out-Null }
$timestamp = Get-Date -Format yyyyMMdd_HHmmss
$Output = $ttsDir\sapi_$timestamp.wav
}

try {
$synth.SelectVoice($selectedVoice.Name)
$synth.Rate = $Rate
$synth.SetOutputToWaveFile($Output)
$synth.Speak($Text)
$synth.SetOutputToNull()

Write-Host 语音:$($selectedVoice.Name) [$($selectedVoice.Culture)] -ForegroundColor Cyan
Write-Host MEDIA:$Output

# 如需自动播放(使用.NET MediaPlayer,无需外部播放器)
if ($Play) {
Add-Type -AssemblyName PresentationCore
$player = New-Object System.Windows.Media.MediaPlayer
$player.Open([Uri]$Output)
$player.Play()
Start-Sleep -Milliseconds 500
while ($player.Position -lt $player.NaturalDuration.TimeSpan) {
Start-Sleep -Milliseconds 100
}
$player.Close()
}

} catch {
Write-Error TTS失败:$($_.Exception.Message)
exit 1
} finally {
$synth.Dispose()
}

快速开始

powershell

生成音频文件


.\tts.ps1 Bonjour, comment vas-tu ?

生成并立即播放

.\tts.ps1 Bonjour ! -Play

参数

参数别名默认值描述
-Text(位置参数)必填要朗读的文本
-VoiceName
-Voice, -v | 自动 | 语音名称(支持部分匹配) | | -Language | -Lang, -l | fr | 语言:fr, en, de, es, it... | | -Output | -o | 自动 | 输出WAV文件路径 | | -Rate | -r | 0 | 速度:-10(慢)到+10(快) | | -Play | -p | false | 生成后立即播放音频 | | -ListVoices | | | 显示已安装的语音 |

示例

powershell

法语,自动播放


.\tts.ps1 Bonjour ! -Lang fr -Play

英语,更快

.\tts.ps1 Hello there! -Lang en -Rate 2 -Play

指定语音

.\tts.ps1 Salut ! -Voice Denise -Play

列出可用语音

.\tts.ps1 -ListVoices

安装神经语音(推荐)

神经语音的音质远优于传统桌面语音。

Windows 11

神经语音已内置。前往: 设置 → 时间和语言 → 语音 → 管理语音

Windows 10/11(更多语音)

如需其他神经语音(如法语Denise):
  1. 1. 安装 NaturalVoiceSAPIAdapter
  2. 设置 → 时间和语言 → 语音 中下载语音
  3. 运行 -ListVoices 验证

性能

  • - 生成: 即时(< 1秒)
  • GPU:
  • CPU: 极低
  • 质量: 优秀(神经)/ 基础(传统)

致谢

由Pocus 🎩 与Olive(@Korddie)共同制作 — AI助手

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 sapi-tts-1776351552 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 sapi-tts-1776351552 技能

通过命令行安装

skillhub install sapi-tts-1776351552

下载

⬇ 下载 sapi-tts v1.1.0(免费)

文件大小: 2.99 KB | 发布时间: 2026-4-17 14:49

v1.1.0 最新 2026-4-17 14:49
Added -Play option for immediate audio playback using .NET MediaPlayer (no external player needed)

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部