-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtts.vbs
More file actions
77 lines (61 loc) · 1.66 KB
/
tts.vbs
File metadata and controls
77 lines (61 loc) · 1.66 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
' Text-to-Speech VBScript with File and Command-Line Input
Option Explicit
Dim speech, voices
Dim i, voiceIndex
Dim inputText, inputFile
Dim args
Set speech = CreateObject("SAPI.SpVoice")
Set voices = speech.GetVoices
Set args = WScript.Arguments
' -------------------------
' Voice selection
' -------------------------
voiceIndex = 0 ' default voice
If args.Count >= 2 Then
If IsNumeric(args(args.Count - 1)) Then
voiceIndex = CInt(args(args.Count - 1))
End If
End If
If voiceIndex >= 0 And voiceIndex < voices.Count Then
Set speech.Voice = voices.Item(voiceIndex)
End If
' -------------------------
' Input handling
' -------------------------
inputText = ""
If args.Count > 0 Then
' File input mode
If args(0) = "-f" And args.Count >= 2 Then
inputFile = args(1)
inputText = ReadFile(inputFile)
' Direct text input
Else
inputText = args(0)
End If
Else
' Interactive fallback
inputText = InputBox("Enter text to speak:", "Text to Speech")
End If
' -------------------------
' Speak
' -------------------------
If Len(inputText) > 0 Then
speech.Speak inputText
Else
WScript.Echo "No text provided."
End If
' =========================
' File reading function
' =========================
Function ReadFile(path)
Dim fso, file, text
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(path) Then
WScript.Echo "File not found: " & path
WScript.Quit 1
End If
Set file = fso.OpenTextFile(path, 1)
text = file.ReadAll
file.Close
ReadFile = text
End Function