Skip to content

Commit a1e4220

Browse files
authored
Add files via upload
1 parent bf56801 commit a1e4220

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

src/win32/tts.vbs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
Option Explicit
2+
3+
Dim SAPIObject : Set SAPIObject = CreateObject("SAPI.SpVoice")
4+
Dim VoiceTokens : Set VoiceTokens = SAPIObject.GetVoices()
5+
Dim VoiceOutputs : Set VoiceOutputs = SAPIObject.GetAudioOutputs()
6+
Dim StdIn : Set StdIn = CreateObject("Scripting.FileSystemObject").GetStandardStream(0)
7+
Dim StdOut : Set StdOut = CreateObject("Scripting.FileSystemObject").GetStandardStream(1)
8+
9+
Dim VoiceVolume : VoiceVolume = 100
10+
Dim VoiceRate : VoiceRate = 0.0
11+
Dim CurrentDevice : CurrentDevice = 0
12+
13+
Sub ListVoices()
14+
Dim Voice
15+
For Each Voice in VoiceTokens
16+
StdOut.WriteLine(Voice.GetDescription)
17+
Next
18+
StdOut.WriteLine("End of voices list")
19+
End Sub
20+
21+
Sub SetDevice(NewDevice)
22+
Dim Index : Index = 0
23+
Dim Device
24+
For Each Device in VoiceOutputs
25+
If (Device.GetDescription = NewDevice) Then
26+
CurrentDevice = Index
27+
28+
Exit For
29+
End If
30+
31+
Index = Index + 1
32+
Next
33+
End Sub
34+
35+
Sub SpeakText(VoiceIndex, Text)
36+
Set SAPIObject.AudioOutput = VoiceOutputs(CurrentDevice)
37+
Set SAPIObject.Voice = VoiceTokens(VoiceIndex)
38+
SAPIObject.Volume = VoiceVolume
39+
SAPIObject.Rate = VoiceRate
40+
SAPIObject.Speak Text, 1
41+
End Sub
42+
43+
Sub SetVolume(NewVolume)
44+
Dim NumVolume : NumVolume = CLng(NewVolume)
45+
If NOT(NumVolume > 100 OR NumVolume < 0) Then
46+
VoiceVolume = NumVolume
47+
Else
48+
VoiceVolume = 100
49+
End If
50+
End Sub
51+
52+
Sub SetRate(NewRate)
53+
Dim NumRate : NumRate = CLng(NewRate)
54+
If NOT(NumRate > 10 OR NumRate < -10) Then
55+
VoiceRate = NumRate
56+
Else
57+
VoiceRate = 0.0
58+
End If
59+
End Sub
60+
61+
Sub MainLoop()
62+
Dim Input
63+
Dim Cmd
64+
Dim Arguments
65+
Dim SplitArguments
66+
67+
Do
68+
Cmd = ""
69+
ReDim Arguments(1)
70+
ReDim SplitArguments(1)
71+
Input = Split(StdIn.ReadLine, " ", 2, 1)
72+
73+
If NOT(uBound(Input) = -1) Then
74+
Cmd = Input(0)
75+
If uBound(Input) = 1 Then
76+
Arguments = Input(1)
77+
SplitArguments = Split(Arguments, " ", 2, 1)
78+
End If
79+
End If
80+
81+
If Cmd = "SpeakText" AND uBound(SplitArguments) = 1 Then
82+
SpeakText SplitArguments(0), SplitArguments(1)
83+
ElseIf Cmd = "ListVoices" Then
84+
ListVoices
85+
ElseIf Cmd = "SetVolume" AND uBound(SplitArguments) = 0 Then
86+
SetVolume SplitArguments(0)
87+
ElseIf Cmd = "SetRate" AND uBound(SplitArguments) = 0 Then
88+
SetRate SplitArguments(0)
89+
ElseIf Cmd = "SetDevice" Then
90+
SetDevice Arguments
91+
End If
92+
Loop While Not StdIn.AtEndOfStream
93+
End Sub
94+
95+
MainLoop

0 commit comments

Comments
 (0)