1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PowerShellに喋ってもらう

Last updated at Posted at 2023-12-20

初期化

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でずんだもんでも喋ってもらえるようにしておきたい

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?