Added speak-date.ps1

This commit is contained in:
Markus Fleschutz
2021-01-09 16:14:22 +01:00
parent 891548f6b4
commit 3dc9fd05ba
4 changed files with 32 additions and 3 deletions

22
Scripts/speak-date.ps1 Normal file
View File

@ -0,0 +1,22 @@
#!/snap/bin/powershell
<#
.SYNTAX ./speak-date.ps1
.DESCRIPTION speaks the current date by text-to-speech (TTS)
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
function Speak([string]$Text) {
write-progress "$Text"
$Voice = new-object -ComObject SAPI.SPVoice
[void]$Voice.Speak($Text)
write-progress -complete "$Text"
}
try {
Speak("Today is $((Get-Date).ToShortDateString())")
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -6,10 +6,15 @@
.NOTES Author: Markus Fleschutz / License: CC0
#>
try {
function Speak([string]$Text) {
write-progress "$Text"
$Voice = new-object -ComObject SAPI.SPVoice
$Text = "The current time is $((Get-Date).ToShortTimeString())"
$Result = $Voice.Speak($Text)
[void]$Voice.Speak($Text)
write-progress -complete "$Text"
}
try {
Speak("It's now $((Get-Date).ToShortTimeString())")
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"