LoginSignup
1
1

More than 3 years have passed since last update.

PowerShellでSpeechSynthesizerを使う

Last updated at Posted at 2020-07-10

やりたいこと

Windowsのコンピューターを簡単に喋らせたいです。

喋らせる手順

  1. PowerShellを起動します。
    • 例えば、ファイル名を指定して実行の画面でPowerShell.exeを実行するなど
    • PowerShell Version 6以上では動かないようなので要注意です
  2. 次のコードを実行します。
Add-Type -AssemblyName System.Speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speak.SelectVoice("Microsoft Haruka Desktop")
$speak.Speak("こんばんは。")

音声の切り替え

インストールされている音声の一覧はこれにより取得できます。

$speak.GetInstalledVoices() | Select-Object {$_.VoiceInfo.Name}
$speak.SelectVoice("何かの音声")

Waveファイルとしての録音する

$speak.SetOutputToWaveFile("Speaking.wav")
$speak.Speak("こんばんは。")
$speak.SetOutputToDefaultAudioDevice()

SetOutputToDefaultAudioDeviceを呼ばないとWaveファイルがロックされたままになります。(より良い方法がありそう)

1
1
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
1