1

I used java to make a pretty neat chatbot a while ago. Recently, I discovered I could use VBS to read text out loud. I used what I discovered to have the chatbot actually speak instead of just printing the response.

That all works fine, but the user can type responses faster than the text-to-speech can finish talking. This causes a backup, as the user enters messages, the bot's responses just get added to the tts queue and won't be spoken until the first response(s) are finished being read.

When the script to read the response is called, I want all speech to be stopped before the response is read. I don't have a clue as how to do this, help would be appreciated. Thanks!

textSpeech.vbs

//I want all speech to be stopped here

Dim sapi
Set sapi=CreateObject("sapi.spvoice")

//speaks the string passed to script
sapi.Speak Wscript.Arguments(0)

Chatbot.java (only relevant code is shown)

try {
    //textSpeech.vbs is executed with sayString as an argument
    Runtime.getRuntime().exec( "wscript \"" + path + "\" \"" + sayString + "\"");
} catch( IOException e ) {
    System.out.println(e);
    System.exit(0);
}

1 Answer 1

3

VBS has just one thread, it means that once you start a process, the processor stops at that line and does not go forward in your code til the process is finished.

Inside vbs you cant do anything. But, for our luck, you can do this at java.

When users start typing again, you kill the runtime process from java:

Process rp = Runtime.getRuntime()
             .exec( "wscript \"" + path + "\" \"" + sayString + "\"");

// whenever user starts typing{
if(user.isTyping()){
  rp.destroy();
}

I hope it works for you!

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.