AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Need help passing variable values, not names
 
 

Hi again, everyone.

I’m developing a simple TTS (using SAPI) interface for ChatScript that will allow it to speak it’s answers when speech is enabled. I’m doing this with a small .exe written in c++ that accepts command line parameters, in this case, words. The reason I’m doing it this way, instead of recompiling it into CS, is that I don’t want to be forced to recompile with every new release.

So far, the proof of concept is working with one slight problem: I’m using the ^system command to call my program and pass along output as command line arguments. The problem with this is that ^system outputs the literal text. For instance:

u: ( what is your name ) My name is $bot
^system(c:\cs\sapirepeat my name is $bot)
  ^keep()

will literally say “My name is dollarsign bot”.

I do understand that this is how the ^system command was intended to function.

My question is: is there any way to pass the value of the variables, or even to just echo the last output that CS puts on the screen (ie: My Name is Anna). Using %lastoutput for instance, same issue, she says “blah blah blah percent lastoutput”.

Ideas anyone?

 

 
  [ # 1 ]

After thought: I’m running this in local mode. I suppose if I have to, I could run it in server mode and just pass the output over to my program. I wanted to avoid getting into an entirely new interface.

In order to keep it as simple as possible, I’m hoping to just echo the output stream on the screen to my program as well.

 

 
  [ # 2 ]

Just a very wild guess, what happens when you do ^system(c:\cs\sapirepeat my name is [$bot]) ?

 

 
  [ # 3 ]

Nice thought…thanks.

It ignores whatever is in brackets completely. So it says “My name is”.

I think this is the normal function of the ^system command, based on what I’ve read. It literally passes the text in () to the operating system, without parsing or acting on it. I was just hoping that it might pass along the variable value as well.

 

 
  [ # 4 ]

John,

I would just write the whole response text to a file.
And then have your executable file open that text file
and generate text to speech when you call it from
chatscript.  So, no command line arguments are needed.

This way, “My name is $bot.” will simply say “My name is Elizabot.”

VBS:

Set objFSO CreateObject("Scripting.FileSystemObject")
Set objText objFSO.OpenTextFile(strText ".txt"ForReading)
strText 
objText.ReadAll
objText
.Close
Set Sapi 
Wscript.CreateObject("SAPI.SpVoice")
Sapi
.speak strText 

Reference:
http://www.instructables.com/id/Make-your-windows-read-files-writen-in-notepad/

 

 
  [ # 5 ]

Thanks, 8pla. 

I may have to end up going that way. That’s just a huge amount of “file work” if you consider export/import/speak/delete for every single response.

I have time to figure this out. I’m waiting for my 18gig ontology to finish indexing in postgreSQL <grins>. It’s going to be a good week!

 

 
  [ # 6 ]

What you propose, John, is more neat and simple.
I hope your proposal is able to work as well.
It could be a useful, easier technique than doing C++.

But since Don checked in… grin  Let’s chat about C++ ...

char sapi[512];

sprintf(sapi"system %s %s %s"arg1arg2arg3);

system((char *)sapi)

(This code is untested.)

 

 
  [ # 7 ]

how about popen?

u: (play)  $test = ^“hello my love”
    $tmp = join(talk ^” \”  $test \” ” )
    popen($tmp ‘^myfunc)

 

 
  [ # 8 ]
∞Pla•Net - Mar 24, 2014:
char sapi[512];
sprintf(sapi"system %s %s %s"arg1arg2arg3);
system((char *)sapi)

If one of the arguments contains text with whitespaces, you’d have to put it in additional quotes. I use ShellExecute() myself, less chance of freezing the program.

char sapi[512];
sprintf(sapi"talk.exe \"%s\""outputtextstring);
system(sapi)

To stay on topic: I’ve never experienced any issues with constantly checking/reading/deleting files as an intermediate. That’s how I relay voice commands to my program. I use Speakonia’s automatic clipboard-reading function for TTS, but unfortunately that one does give me issues.

 

 
  [ # 9 ]

@ 8pla and Don:  Thanks guys! I’ve already got the argument portion of the SAPI code working. She can read any input passed to her on the command line, regardless of whitespace, and any documents passed to her until she gets a carriage return (ie: up until the end of the first paragraph). This is functioning beautifully for my purposes. I’m not concerned with writing the code for file I/O per say…I’m concerned on what effect this will have on my robot’s other functioning. She is already doing image processing, sonar pings on six different sensors every 15ms, etc, and since she has to interact in the real world, safety and response time is a very real issue for me. If she’s doing a lot of file I/O for every sentence, it becomes a performance concern (and therefore a safety concern) for me.

If you’re curious, I’m basically using getline. Converting it to a wide string, then passing it to the SAPI instance. 

@Bruce: Thank you. I’ll try that solution and get back to you this morning.

 

 
  [ # 10 ]

As I meant, I’ve never had performance issues. It takes the Loebner Prize Protocol before I experience slowdown, which requires creating one intermediate file for each letter of output (rediculous, I know).
But for voice interface I only have the program check for the presence of the intermediate file twice a second, ignoring it if it’s not there. If you are concerned about performance speed, it may be actually advisable to try alternatives to system() calls. They can cause noticable delays in Windows.

 

 
  [ # 11 ]
Bruce Wilcox - Mar 24, 2014:

how about popen?

u: (play)  $test = ^“hello my love”
    $tmp = join(talk ^” \”  $test \” ” )
    popen($tmp ‘^myfunc)

Fantastic, Bruce. With some tweaking I was able to get this to speak the variable values instead of the literal name. I really appreciate your help!

Just so I understand what’s happening here…The join statement is obviously building the string for output. This is also where the value of the variable is placed into the string, right? So for passing values, it’s the join statement that is important here. Well, I guess popen is too, since system wouldn’t pass the value of $tmp.

Regardless…thank you very much. This has given me the direction I needed to work on this part of my project.

 

 
  [ # 12 ]

Don & 8pla,

Problem solved with Bruce’s answer. I just needed to know how to pass variable values (not names) out of ChatScript.

I just wanted to thank both of you for always jumping in and taking the time to try to help me, even with code examples. I really do appreciate you guys taking the time to try to help me.

Thank you!

 

 
  [ # 13 ]

OF course the variables used should really be $$ ones. I used permanent ones only so I could ask :user variables to confirm the variables got what I wanted.

 

 
  [ # 14 ]

System was the ORIGINAL interface command and very inflexible. Popen is the more capable command and now I could probably simply remove system. But I probably will just not mess with it.

 

 
  [ # 15 ]

I’ve tested popen a while back, but not with voice. I guess I had a braincramp and didn’t think to try it this time. Whew. It’s been a crazy few months in my life, and I’m relearning most of what I already learned about ChatScript. I appreciate the pointers to the right path. System works great for me when I need to send static values. It’s useful in it’s place.

In this case, I was trying to find an “easy” way to add speech output without having to recompile every time a new release comes out, or design an entirely new interface. Eventually, I’ll set up a variable to test if speech is “on”, then a macro or something similar in the control scripts to echo everything out to my speech module if speech=on.  Haven’t got nearly that far yet, lol, but that’s the plan.

 

 1 2 3 > 
1 of 3
 
  login or register to react