-
-
Notifications
You must be signed in to change notification settings - Fork 546
Expand file tree
/
Copy pathspeak-file.ps1
More file actions
executable file
·31 lines (26 loc) · 705 Bytes
/
speak-file.ps1
File metadata and controls
executable file
·31 lines (26 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<#
.SYNOPSIS
Speaks file content by text-to-speech
.DESCRIPTION
This PowerShell script speaks the content of the given text file by text-to-speech (TTS).
.PARAMETER File
Specifies the path to the text file
.EXAMPLE
PS> ./speak-file.ps1 C:\MyFile.txt
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
param([string]$File = "")
try {
if ($File -eq "") { $File = Read-Host "Enter path to text file" }
$Text = Get-Content $File
$Voice = new-object -ComObject SAPI.SPVoice
$Result = $Voice.Speak($Text)
exit 0 # success
} catch {
"⚠️ ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
exit 1
}