jcunews

speak.hta

Feb 11th, 2022
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.52 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset=utf-8 />
  5. <meta http-equiv="x-ua-compatible" content="IE=9" />
  6. <!--
  7.  This is an HTML Application.
  8.  While it's in HTML format, it's not meant to be opened under a web browser.
  9.  But it does require Internet Explorer 7+, and Windows XP or later.
  10.  Windows already handles HTA files out of the box.
  11.  Simply double-click the file to run it.
  12. -->
  13. <style>
  14.   body {margin:0;box-sizing:border-box;padding:.5em;height:100%;font-size:16pt}
  15.   #tts {display:none}
  16.   input {margin:0 2em;width:5em}
  17.   #out {
  18.     position:absolute;left:.5em;top:2.5em;right:.5em;bottom:.5em;
  19.     box-sizing:border-box;border:.1em solid #bbb;padding:.1em .3em;
  20.     overflow:auto;
  21.   }
  22. </style>
  23. </head>
  24. <body>
  25. <hta:application id=hta></hta:application>
  26. <object id=tts classid="clsid:96749377-3391-11d2-9ee3-00c04f797396"></object>
  27. <center>
  28.   <input id=ifile type=file style="display:none" />
  29.   <input id=bload value=Load... type=button />
  30.   <input id=bspeak value=Speak type=button disabled />
  31.   <input id=bpause value=Pause type=button disabled />
  32. </center>
  33. <div id=out></div>
  34. <script language=vbscript>
  35.  
  36. sub load(fname)
  37.   on error resume next
  38.   set fs = createobject("scripting.filesystemobject")
  39.   set f = fs.opentextfile(fname)
  40.   if err.number <> 0 then
  41.     msgbox "Error opening file: " & fname & vblf & err.description & ".", _
  42.      16, document.title
  43.    if withcmdline then close
  44.  end if
  45.  on error goto 0
  46.  lines = f.readall
  47.  if instr(lines, vbcrlf) > 0 then
  48.    lines = split(lines, vbcrlf)
  49.  else
  50.    lines = split(lines, vblf)
  51.  end if
  52.  f.close
  53.  set f = fs.getfile(fname)
  54.  filepath = fname
  55.  document.title = apptitle & " - " & f.name
  56.  bspeak.disabled = false
  57. end sub
  58.  
  59. sub ifile_onchange
  60.  load ifile.value
  61. end sub
  62.  
  63. sub bload_onclick
  64.  ifile.click
  65. end sub
  66.  
  67. sub nextline
  68.  lineindex = lineindex + 1
  69.  if lineindex <= ubound(lines) then
  70.    speakline
  71.  else
  72.    donespeak
  73.  end if
  74. end sub
  75.  
  76. sub donespeak
  77.  speaking = false
  78.  bspeak.value = "Speak"
  79.  bpause.value = "Pause"
  80.  bpause.disabled = true
  81. end sub
  82.  
  83. sub chk
  84.  if speaking then
  85.    if tts.status.runningstate = 1 then
  86.      clearinterval tchk
  87.      nextline
  88.    end if
  89.  end if
  90. end sub
  91.  
  92. sub speakline
  93.  if out.innerhtml <> "" then
  94.    out.innertext = out.innertext & vblf & lines(lineindex)
  95.  else
  96.    out.innertext = lines(lineindex)
  97.  end if
  98.  out.scrolltop = out.scrollheight
  99.  tts.speak lines(lineindex), 1
  100. end sub
  101.  
  102. sub bspeak_onclick
  103.  if speaking then
  104.    clearinterval tchk
  105.    tts.pause
  106.    donespeak
  107.    set a = tts.clonenode(false)
  108.    document.body.removechild document.getelementbyid("tts")
  109.    document.body.appendchild a
  110.  else
  111.    speaking = true
  112.    bspeak.value = "Stop"
  113.    bpause.value = "Pause"
  114.    bpause.disabled = false
  115.    lineindex = 0
  116.    out.innerhtml = ""
  117.    speakline
  118.    tchk = setinterval(getref("chk"), 50)
  119.  end if
  120. end sub
  121.  
  122. sub bpause_onclick
  123.  if paused then
  124.    paused = false
  125.    bpause.value = "Pause"
  126.    tts.resume
  127.  else
  128.    paused = true
  129.    bpause.value = "Resume"
  130.    tts.pause
  131.  end if
  132. end sub
  133.  
  134. sub init
  135.  bload.focus
  136.  if filepath <> "" then load filepath
  137. end sub
  138.  
  139. apptitle = "Speak"
  140. document.title = apptitle
  141. filepath = ""
  142. set x = new regexp
  143. x.pattern = "(?:""[^""]+""|\S+)\s+(""[^""]+""|\S+)"
  144. set m = x.execute(hta.commandline)
  145. if m.count > 0 then filepath = m(0).submatches(0)
  146. lines = ""
  147. lineindex = 0
  148. speaking = false
  149. paused = false
  150. tts.alertboundary = 64
  151. settimeout getref("init"), 0
  152.  
  153. </script>
  154. </body>
  155. </html>
  156.  
Add Comment
Please, Sign In to add comment