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
| ' text to speech script
' that outputs audio in a wav file
' usage : script.vbs input.txt [output.wav]
dim scrFName, clArgs
scrFName = Wscript.ScriptFullName
set clArgs = Wscript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
dim intxt, outwav
if clArgs.Count > 1 then
intxt = clArgs(0)
outwav = clArgs(1)
elseif clArgs.Count > 0 then
intxt = clArgs(0)
outwav = ""
else
Wscript.Echo "usage : " _
& fso.GetFileName(scrFName) _
& " input.txt [output.wav]" & vbCrLf
Wscript.quit
end if
if fso.FileExists(intxt) then
if fso.GetParentFolderName(intxt) = "" then
intxt = fso.GetAbsolutePathName(intxt)
end if
if outwav = "" then
outwav = fso.GetParentFolderName(intxt) & "\" _
& fso.GetBaseName(intxt) & ".wav"
end if
else
Wscript.Echo "Input file not found: " & intxt
Wscript.quit
end if
dim intxtcontent
set f = fso.OpenTextFile(intxt, 1)
intxtcontent = f.ReadAll
f.close
set f = nothing
Const SAFT48kHz16BitStereo = 39
Const SSFMCreateForWrite = 3
set sapiFStream = CreateObject("SAPI.SpFileStream")
sapiFStream.Format.Type = SAFT48kHz16BitStereo
call sapiFStream.Open(outwav, SSFMCreateForWrite)
set sapiVoice = CreateObject("SAPI.SpVoice")
Set sapiVoice.AudioOutputStream = sapiFStream
'sapiVoice.Rate = -2 ' from -10 to 10
sapiVoice.Speak(intxtcontent)
sapiFStream.Close
set sapiVoice = nothing
set sapiFStream = nothing
set fso = nothing |
Partager