初期化
Add-Type -AssemblyName System.Speech
$synth = New-Object System.Speech.Synthesis.SpeechSynthesizer
喋る
$synth.Speak('エル・プサイ・コングルゥ')
設定
# 速さ (-10 ~ 10) デフォルトは0
$synth.Rate = 3
# 音量 (0 ~ 100)
$synth.Volume = 100
声を選ぶ
声一覧を表示 といってもデフォルトじゃ2つしかない
$synth.GetInstalledVoices().VoiceInfo | Select-Object -Property Name, Culture, Gender, Age
Name Culture Gender Age ---- ------- ------ --- Microsoft Haruka Desktop ja-JP Female Adult Microsoft Zira Desktop en-US Female Adult
# 声を選択
$synth.SelectVoice("Microsoft Haruka Desktop")
関数作っておく
code $profile
に書き込んでおく
function say {
param(
[Parameter(ValueFromPipeline=$true)]
[string]$InputString
)
process {
if (!$synth) {
Add-Type -AssemblyName System.Speech
$synth = New-Object System.Speech.Synthesis.SpeechSynthesizer
$synth.Rate = 2
}
if ($InputString) {
$synth.Speak($InputString)
} else {
Write-Host "文字列を渡してください"
}
}
}
引数でもパイプでも渡せる
# 引数で渡す
say hello
# パイプで渡す
"はろー" | say
TODO: VOICEVOXでずんだもんでも喋ってもらえるようにしておきたい