Skip to content

Instantly share code, notes, and snippets.

@CannoHarito
Last active November 15, 2023 05:43
Show Gist options
  • Save CannoHarito/a3e0d755b4b130e0bf33474cc3546372 to your computer and use it in GitHub Desktop.
Save CannoHarito/a3e0d755b4b130e0bf33474cc3546372 to your computer and use it in GitHub Desktop.
powershellがしゃべるやつ。Ctrl+Cで終わればよいだろう。
param([Int]$volume, [string]$voice)
# & .\Enter-TTS-Console.ps1 -voice 'Microsoft Zira Desktop'
# in cmd.exe: powershell .\Enter-TTS-Console.ps1 -voice 'Microsoft` Zira` Desktop'
Add-Type -AssemblyName System.speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
if ($volume) {
$speak.Volume = $volume
}
if ($voice) {
$speak.SelectVoice($voice)
}
function Out-Speak {
param (
[Parameter( ValueFromPipeline = $true)]
[string]$words
)
process {
if ($words) {
$speak.Speak($words)
}
}
}
if ($MyInvocation.InvocationName -ne ".") {
"Voice:$($speak.Voice.Name),Volume:$($speak.Volume)" | ForEach-Object { $_ | Out-Host; $_ } | Out-Speak
try {
while (1) {
Read-Host | Out-Speak
}
}
finally { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment