Last active
November 15, 2023 05:43
-
-
Save CannoHarito/a3e0d755b4b130e0bf33474cc3546372 to your computer and use it in GitHub Desktop.
powershellがしゃべるやつ。Ctrl+Cで終わればよいだろう。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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