Skip to content

Commit fe1a4f7

Browse files
committed
Add speak-arabic.ps1
1 parent 4fbc4dc commit fe1a4f7

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Scripts/speak-arabic.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<#
2+
.SYNOPSIS
3+
Speaks text with an Arabic text-to-speech voice
4+
.DESCRIPTION
5+
This PowerShell script speaks the given text with an Arabic text-to-speech (TTS) voice.
6+
.PARAMETER text
7+
Specifies the text to speak
8+
.EXAMPLE
9+
PS> ./speak-arabic "أهلاً"
10+
.LINK
11+
https://github.com/fleschutz/PowerShell
12+
.NOTES
13+
Author: Markus Fleschutz | License: CC0
14+
#>
15+
16+
param([string]$text = "")
17+
18+
try {
19+
if ($text -eq "") { $text = read-host "Enter the Arabic text to speak" }
20+
21+
$TTSVoice = New-Object -ComObject SAPI.SPVoice
22+
foreach ($Voice in $TTSVoice.GetVoices()) {
23+
if ($Voice.GetDescription() -like "*- Arabic*") {
24+
$TTSVoice.Voice = $Voice
25+
[void]$TTSVoice.Speak($text)
26+
exit 0 # success
27+
}
28+
}
29+
throw "No Arabic voice for text-to-speech (TTS) found - please install one"
30+
} catch {
31+
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
32+
exit 1
33+
}

0 commit comments

Comments
 (0)