Jump to content

Help fix my code


Recommended Posts

I am writing a program that will allow you to right-click on a text file and choose to have it read to you. I will add the right-click part later, for now I am having trouble stopping the reading mid-sentence.

Main.exe

Opt("OnExitFunc", "endscript")
HotKeySet("{ESC}", "endscript")

If $CmdLine[0] == 0 Then
    Exit
EndIf

$file = FileOpen($CmdLine[1], 0)
Dim $handle

If $file = -1 Then
    $speech = ObjCreate("SAPI.SPVOICE")
    $speech.Rate = 7
    $speech.Speak("Error, unable to open file.", 7)
    Exit
EndIf

While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $handle = RunWait("TextToSpeech.exe " & $line) 
Wend

Func endscript()
    If ProcessExists($handle) Then ProcessClose($handle)
    FileClose($file)
    Exit
EndFunc

TextToSpeech.exe

If $CmdLine[0] == 0 Then
    Exit
EndIf

$speech = ObjCreate("SAPI.SPVOICE")
$speech.Speak($CmdLineRaw)

Main.exe calls TextToSpeech.exe with each line of text in the given file, so that I could kill it mid-sentence. Unfortunately it waits until the sentence is completed before exiting.

Also, while I'm on the subject: if anyone has a good tutorial on parsing *.rtf and/or *.doc files, I would really appreciate them.

Thanks

Edited by Apocalypse
Link to comment
Share on other sites

I think you would attract more response if you used a proper heading. Something along the line:

How do I terminate SAPI.SPVOICE in the middle of a sentence? Any suggestions appreciated!

Oh well hope that fixed your code..:whistle:

Link to comment
Share on other sites

see what happens when you read it one word at a time, considering that as a story, a " " (space) will be the universal splitter for each word, you could read in a line, split it at the spaces into an array, and read each word individually.

look at regular expressions, i can imagine there would be a way to read everything upto a "." with that being a line, and you can add a hotkey / button on a small toolbar to "stop" the script, seeing as it is going 1 word at a time, it should stop after its current word is read.. unlike the sentence where it needs to read the sentence first.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...