Improved the scripts

This commit is contained in:
Markus Fleschutz 2021-01-09 16:40:46 +01:00
parent 3dc9fd05ba
commit 138a0d2b20
4 changed files with 20 additions and 1 deletions

View File

@ -9,11 +9,20 @@
function Speak([string]$Text) { function Speak([string]$Text) {
write-progress "$Text" write-progress "$Text"
$Voice = new-object -ComObject SAPI.SPVoice $Voice = new-object -ComObject SAPI.SPVoice
$Voices = $Voice.GetVoices()
foreach ($OtherVoice in $Voices) {
$Description = $OtherVoice.GetDescription()
if ($Description -like "*- English (United States)") {
$Voice.Voice = $OtherVoice
break
}
}
[void]$Voice.Speak($Text) [void]$Voice.Speak($Text)
write-progress -complete "$Text" write-progress -complete "$Text"
} }
try { try {
[system.threading.thread]::currentthread.currentculture=[system.globalization.cultureinfo]"en-US"
Speak("Today is $((Get-Date).ToShortDateString())") Speak("Today is $((Get-Date).ToShortDateString())")
exit 0 exit 0
} catch { } catch {

View File

@ -8,7 +8,7 @@
function Speak { param([string]$Text) function Speak { param([string]$Text)
write-output "'$Text'" write-output "'$Text'"
$Result = $Voice.speak("$Text") [void]$Voice.speak("$Text")
} }
try { try {

View File

@ -9,11 +9,20 @@
function Speak([string]$Text) { function Speak([string]$Text) {
write-progress "$Text" write-progress "$Text"
$Voice = new-object -ComObject SAPI.SPVoice $Voice = new-object -ComObject SAPI.SPVoice
$Voices = $Voice.GetVoices()
foreach ($OtherVoice in $Voices) {
$Description = $OtherVoice.GetDescription()
if ($Description -like "*- English (United States)") {
$Voice.Voice = $OtherVoice
break
}
}
[void]$Voice.Speak($Text) [void]$Voice.Speak($Text)
write-progress -complete "$Text" write-progress -complete "$Text"
} }
try { try {
[system.threading.thread]::currentthread.currentculture=[system.globalization.cultureinfo]"en-US"
Speak("It's now $((Get-Date).ToShortTimeString())") Speak("It's now $((Get-Date).ToShortTimeString())")
exit 0 exit 0
} catch { } catch {

View File

@ -11,6 +11,7 @@ $PathToRepo = "$PSScriptRoot/.."
try { try {
write-output "Init speech recognition engine..." write-output "Init speech recognition engine..."
[system.threading.thread]::currentthread.currentculture=[system.globalization.cultureinfo]"en-US"
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Speech") [void][System.Reflection.Assembly]::LoadWithPartialName("System.Speech")
$speechRecogEng = [System.Speech.Recognition.SpeechRecognitionEngine]::new() $speechRecogEng = [System.Speech.Recognition.SpeechRecognitionEngine]::new()
#$speechRecogEng.InitialSilenceTimeout = 15 #$speechRecogEng.InitialSilenceTimeout = 15