Sign in to follow this  
Followers 0
Apocalypse

Help fix my code

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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:

Share this post


Link to post
Share on other sites

As far as I know, you can't terminate it once called.. You may want to consider splitting the file in parts that are no larger then 300 characters for instance, if you are having trouble with something reading into infinity..

Share this post


Link to post
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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0