On Error Resume Next
Sub Logit(msg)
  Dim f2, lf
  Set f2 = CreateObject("Scripting.FileSystemObject")
  Set lf = f2.OpenTextFile(f2.GetParentFolderName(WScript.ScriptFullName) & "\munchyroll_vo_log.txt", 8, True)
  lf.WriteLine msg
  lf.Close
End Sub
Logit "start " & Now
Dim fso, dir, v, t, fmt, s, name, voices, who
Set fso = CreateObject("Scripting.FileSystemObject")
  If Err.Number <> 0 Then Logit "line 1: Set fso = CreateObject(Scripting.FileSystemObject) -> " & Err.Number & " " & Err.Description : Err.Clear
dir = fso.GetParentFolderName(WScript.ScriptFullName) & "\munchyroll_vo"
  If Err.Number <> 0 Then Logit "line 2: dir = fso.GetParentFolderName(WScript.ScriptFullName) & \mun -> " & Err.Number & " " & Err.Description : Err.Clear
If Not fso.FolderExists(dir) Then fso.CreateFolder dir
Sub Say(voiceName, fileName, text)
  Set v = CreateObject("SAPI.SpVoice")
  If Err.Number <> 0 Then Logit "line 3: Set v = CreateObject(SAPI.SpVoice) -> " & Err.Number & " " & Err.Description : Err.Clear
  For Each t In v.GetVoices
    If InStr(t.GetDescription, voiceName) > 0 Then Set v.Voice = t
  Next
  Set fmt = CreateObject("SAPI.SpAudioFormat")
  If Err.Number <> 0 Then Logit "line 4: Set fmt = CreateObject(SAPI.SpAudioFormat) -> " & Err.Number & " " & Err.Description : Err.Clear
  fmt.Type = 39
  If Err.Number <> 0 Then Logit "line 5: fmt.Type = 39 -> " & Err.Number & " " & Err.Description : Err.Clear
  Set s = CreateObject("SAPI.SpFileStream")
  If Err.Number <> 0 Then Logit "line 6: Set s = CreateObject(SAPI.SpFileStream) -> " & Err.Number & " " & Err.Description : Err.Clear
  Set s.Format = fmt
  If Err.Number <> 0 Then Logit "line 7: Set s.Format = fmt -> " & Err.Number & " " & Err.Description : Err.Clear
  s.Open dir & "\" & fileName & ".wav", 3
  If Err.Number <> 0 Then Logit "line 8: s.Open dir & \ & fileName & .wav, 3 -> " & Err.Number & " " & Err.Description : Err.Clear
  Set v.AudioOutputStream = s
  If Err.Number <> 0 Then Logit "line 9: Set v.AudioOutputStream = s -> " & Err.Number & " " & Err.Description : Err.Clear
  v.Rate = 1
  If Err.Number <> 0 Then Logit "line 10: v.Rate = 1 -> " & Err.Number & " " & Err.Description : Err.Clear
  v.Speak text
  If Err.Number <> 0 Then Logit "line 11: v.Speak text -> " & Err.Number & " " & Err.Description : Err.Clear
  s.Close
  If Err.Number <> 0 Then Logit "line 12: s.Close -> " & Err.Number & " " & Err.Description : Err.Clear
End Sub
For Each who In Array("David", "Zira")
  Say who, LCase(who) & "_vo1", "Looking for the ultimate anime lineup? Munchy roll has you covered!"
  If Err.Number <> 0 Then Logit "line 13: Say who, LCase(who) & _vo1, Looking for the ultimate anime l -> " & Err.Number & " " & Err.Description : Err.Clear
  Say who, LCase(who) & "_vo2", "Fuel your nostalgia with the legendary journeys of Nah-roo-toe, Shippoo-den, and the timeless grit of Cowboy Bebop, and Darker Than Black."
  If Err.Number <> 0 Then Logit "line 14: Say who, LCase(who) & _vo2, Fuel your nostalgia with the leg -> " & Err.Number & " " & Err.Description : Err.Clear
  Say who, LCase(who) & "_vo3", "Then, crush the new era! Stand tall with Kaiju Number Eight, Solo Leveling, and Gotchee-ah-koota. Dive into the madness of Hell's Paradise, Cleva-tess, and Full-metal Alchemist!"
  If Err.Number <> 0 Then Logit "line 15: Say who, LCase(who) & _vo3, Then, crush the new era! Stand t -> " & Err.Number & " " & Err.Description : Err.Clear
  Say who, LCase(who) & "_vo4", "From Delicious in Dungeon, to Eminence in Shadow, we serve the best. Munchy roll. Feed your obsession!"
  If Err.Number <> 0 Then Logit "line 16: Say who, LCase(who) & _vo4, From Delicious in Dungeon, to Em -> " & Err.Number & " " & Err.Description : Err.Clear
Next
Set s = fso.CreateTextFile(dir & "\done.txt", True)
s.WriteLine "ok"
s.Close
  If Err.Number <> 0 Then Logit "line 17: s.Close -> " & Err.Number & " " & Err.Description : Err.Clear
