Update convert-txt2wav.ps1

This commit is contained in:
Markus Fleschutz 2021-04-15 08:52:28 +02:00 committed by GitHub
parent e0a8a3b53b
commit df7cbfab55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,21 +1,19 @@
#!/usr/bin/pwsh #!/usr/bin/pwsh
<# <#
.SYNTAX convert-txt2wav.ps1 .SYNTAX convert-txt2wav.ps1 [<text>] [<wav-file>]
.DESCRIPTION converts the given text into an audio .WAV file .DESCRIPTION converts the given text to a .WAV audio file
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
$Text = "Hello, my name ist Bond, James Bond" param($Text = "", $WavFile = "")
$Speed = -1 # -10 is slowest, 10 is fastest if ($Text -eq "") { $Text = read-host "Enter text to speak" }
$TargetWavFile = "spoken.wav" if ($WavFile -eq "") { $WavFile = read-host "Enter .WAV file to save to" }
try { try {
Add-Type -AssemblyName System.Speech Add-Type -AssemblyName System.Speech
$SpeechSynthesizer = New-Object System.Speech.Synthesis.SpeechSynthesizer $SpeechSynthesizer = New-Object System.Speech.Synthesis.SpeechSynthesizer
# $SpeechSynthesizer.SelectVoice("Microsoft Eva Mobile") $SpeechSynthesizer.SetOutputToWaveFile($tWavFile)
$SpeechSynthesizer.Rate = $Speed
$SpeechSynthesizer.SetOutputToWaveFile($TargetWavFile)
$SpeechSynthesizer.Speak($Text) $SpeechSynthesizer.Speak($Text)
$SpeechSynthesizer.Dispose() $SpeechSynthesizer.Dispose()
exit 0 exit 0