Ai Dreams Forum

Member's Experiments & Projects => AI Programming => Topic started by: brty21 on March 18, 2017, 04:20:32 am

Title: Rivescript not working as expected- solved
Post by: brty21 on March 18, 2017, 04:20:32 am
Does anyone use rivescript ? I have it on a local server and it all loads in a browser and working (well nearly)
The problem I have is adding new stuff
I added the following how questions...
---------------------------------------------------------------------------------
+  how do you * the *
-  Well, I like to <star1> the <star2>. How? I cant really say

+  how does the * work
-  I think the <star> works with the help of magic squirrels

+  how does *
-  interesting question. Are you teasing me?
+  no
-  Ok then. I can be a bit dipsy sometimes.

+  how does it *
-  Maybe that is beyond the scope of this conversation

+  how * will that be
-  That depends on how <star> it is to begin with

+  how will I *
-  trust in your instincts
-  there will be no way of knowing for sure

+  how do you like *
-  I like <star> a lot actually
-----------------------------------------------------------------------------
Regardless of things making sense, most of it works. BUT, the " how will I * " results in rivescript not finding the answer
Does anyone know where I am going wrong in the above?
Title: Re: Rivescript not working as expected
Post by: brty21 on March 18, 2017, 04:20:57 am
=
Title: Re: Rivescript not working as expected
Post by: Freddy on March 18, 2017, 05:03:40 am
We have a moderator that knows Rivescript, so hopefully they will be able to help. I've only seen it in passing so can't really help.

The thing I notice about the problem line is that it's the only one that uses two consecutive hyphens - maybe there is a syntax problem there. I'm guessing you want it to pick a random line out of those two, so maybe there is some required structure. I seem to remember being told that it uses the pipe... |

Just an uneducated guess.
Title: Re: Rivescript not working as expected
Post by: brty21 on March 18, 2017, 12:18:13 pm
Thanks for looking Freddy. I solved it by changing

how will I *
to
how will i *

I'm very interested in your unity/elfscript project. I'm just using animated gif's of daz animations but would love to use a 3d figure and will be trying it when i have time.
Title: Re: Rivescript not working as expected
Post by: Art on March 18, 2017, 01:56:32 pm
Right on! The Capital I catches me especially if I'm typing in a hurry.

Capitals are not allowed in the Trigger input from the user. They are handled by the program.

One can have two, three or a bunch of the - 's (hyphens) as they are the various responses RiveScript can use when selecting an answer.

The Pipes are useful in the Trigger statements from the user such as + Do you have a (vehicle | car | automobile)

No ?'s / punctuation is allowed at the end of Trigger / possible User input sentences (denoted with a +)

Glad you found the culprit!

Title: Re: Rivescript not working as expected
Post by: brty21 on March 18, 2017, 05:36:06 pm
Hi Art,

Yes, i didn't notice about the capital letter thing until just after posting the question..

I'm using rivescript-js-1.17.2 on localhost

I'm happy now that calling TTS and avatars is possible with rivescript and javascript. I don't know how to program, but there are a lot of examples that help
I am building separate .rive files in an effort to make editing things faster. I don't know if they should all be merged later or not? The standard Eliza based rive is still in there.

main things I want to do next are...

Build more brain .rive files
Use Mary tts instead of windows (no idea how to call this with javascript yet)
Do a lot more gif animations -as at the moment its set to talking or not talking (linked to the text to speech)

hmm this may take some time ;-)

Title: Re: Rivescript not working as expected
Post by: Freddy on March 18, 2017, 06:45:41 pm
Glad you got it sorted.

I'm very interested in your unity/elfscript project. I'm just using animated gif's of daz animations but would love to use a 3d figure and will be trying it when i have time.

Elfscript is on hold at the moment as I have so much on. But it's usable now, I'll look into opening up the private board where Art and myself had been discussing it. That's going to be a few weeks away though when I have more time to support it hopefully.

There is a technical difficulty in using my avatars in a browser that I have not got around yet and that involves multi threading. The short version is that it will not work just yet. I need to explore other ways of doing things, if indeed there are any - or for Unity to come up with something.

Quote
The Pipes are useful in the Trigger statements from the user such as + Do you have a (vehicle | car | automobile)

Interesting, that's the same method I came up with for variations of input. I use double pipes for random sentences (and also different input) and singles for variable phrases...

For sentences :

Code
i: hello||howdy||Greetings||good day;
o: Hello there !||Good to meet you !;

For phrases :

Code
i: I have a (bike|car|lorry);
o: Oh, that's a means of transport.||How long have you had one ?;

My interpreter is not fussy about capitals because all input is normalised.
Title: Re: Rivescript not working as expected
Post by: Art on March 19, 2017, 04:41:36 pm
Yes I recall that, Freddy.

It would be nice if a 3D animated avatar could be realized via Unity, Daz3d, Poser, Blender or some other "fairly realistic" method. Most users and fans of chatbots agree that an avatar provides a visual connection to an otherwise talking computer program.

Most also know of those 3D avatars from Haptek that UltraHal (Zabaware) and other programs used in the past. It's a shame that the People Putty developers didn't keep up with Windows. I'm sure there are other opportunities available...we just have to find them.
Title: Re: Rivescript not working as expected
Post by: Freddy on March 19, 2017, 07:14:52 pm
Well there's no difficulty with the avatars running on the desktop as you've seen from my videos - even in virtual reality it's a goer. I'd like to crack browser support though some time.
Title: Re: Rivescript not working as expected
Post by: brty21 on March 20, 2017, 01:01:40 am
A blender addon or Daz studio plugin would be amazing! It's a shame haptek faded too, i did try to get it working on windows 10 but no
So far, yours seems the best solution for using 3d figures Freddy -but I'd have to get my head around Unity. It kind of bewilders me like blender did in earlier versions
Title: Re: Rivescript not working as expected
Post by: Freddy on March 20, 2017, 01:59:57 am
Unity is not so bad, there are a lot of tutorials and in their forums are some of the most helpful people you can find.

I wrote one for getting the figures into Unity here :

http://widdershinsstudio.uk/exporting-daz3d-models-or-characters-into-unity-for-animation/ (http://widdershinsstudio.uk/exporting-daz3d-models-or-characters-into-unity-for-animation/)

Learning the interface in Unity is one of the first things to crack. You could opt to use javascript as your language of choice - personally I prefer c# in Unity despite doing a lot of js programming in web work.

You mentioned this :

Quote
Use Mary tts instead of windows (no idea how to call this with javascript yet)

You'll need a server to set Mary up on, I'm not sure if you can do it on a regular hosting site - I've only set it up on a VPS. But if you go that route I can probably help - calling the Mary server through javascript and using HTML5 audio should be relatively straight forward. Lipsync is where it gets complicated.

Apologies if I am telling things you already know :)
Title: Re: Rivescript not working as expected
Post by: brty21 on March 21, 2017, 09:42:05 pm
I have read through your article with interest while on my quest last week. I will get back to trying it soon.

Using marytts would be perfect as if i later upload a rivescript bot  that's using microsoft speechsynth it may sound very strange on some computers using the older voices. (i use windows 10)
I am using localhost and have put mary on it but no idea how to get rivescript to use it. There is an example web page in the mary folder that i can browse to but it just outputs a wav file to save.
Well there's no rush as its going take quite a while to get my rivebot talking without falling back to the * trigger to much

Lip sync is way beyond me atm as I can only get javascript to load a talking gif and an idle gif right now. still at least an avatar of sorts.

...This is all pushing me to actually try to learn javascript- well, you never know!

I am enjoying rive-script though - even if it doesn't really allow for much learning through conversations like some bots



Title: Re: Rivescript not working as expected
Post by: Freddy on March 23, 2017, 01:27:05 am
Here's a short couple of scripts that I came up with which use PHP and javascript to interface with MaryTTS.

Browsers/JS don't like cross site scripting. There's ways to get around it, but I find them complicated and it's easily solved with a relay for testing purposes. You can get into all that other gubbins later if you want.

Take these two scripts and put them in some directory that is useful to you. The HTML/JS script calls the PHP. The PHP calls Mary. The PHP then sends what it got from Mary back to the client or browser. The client then plays it.

The main reason why you get the cross site problem is that Mary uses a different port compared to normal, ie port 80 in most cases.



Here's the HTML/JS :

Code
<html>

<title>Demo Play TTS</title>

<head>

</head>

<script>

// It's a pain using JS for cross site so just use a simple PHP relay to start with.
var relay = "gettts.php";

// The words to render.
var tts = "Just a simple Demo. Refresh page if you change the words in the script.";

// The URL for the relay with the words added on.
var url = relay + "?words=" + tts;

// Set up an audio player and get the audio from the relay URL.
var audio = new Audio(url);

// Play the audio which would have been made by Mary.
audio.play();

</script>

<body>

Just a simple Demo. Refresh page if you change the words in the script.

</body>

</html>

And the PHP...

Code
<?php

// Your server or host.
$host = "http://localhost";

// A voice you have installed with Mary.
$voice = "cmu-slt-hsmm";

// Get the words sent from the JS - best to do some sanitising here later.
$words = $_GET['words'];

// URL to the Mary port and various settings.
$url = $host  . ":59125/process?INPUT_TEXT=" . $words . ".&INPUT_TYPE=TEXT&OUTPUT_TYPE=AUDIO&LOCALE=en_US&AUDIO=WAVE_FILE&VOICE=" . $voice;

// Mary doesn't like spaces.
$url = str_replace(" ", "+", $url);

// Get the WAV file from Mary.
$wav = file_get_contents($url);

// Set a header for the client.
header('Content-Type: audio/wav');

// Echo the audio data.
echo $wav;

// End.
die();

Have a play with that. Save the PHP as 'gettts.php' and the HTML whatever you see fit. Change the JS variable 'tts' to whatever you like. Just hit the HTML page in your browser to see what it does.

Hopefully it will work, it did for me. You may have to change the voice setting if you don't have that one, but I think that is the default voice when installing.

Note that PHP is server side - so you need to browse to the HTML via your local host. Just double clicking on the HTML file will not work.
Title: Re: Rivescript not working as expected
Post by: 8pla.net on March 23, 2017, 03:23:37 am
Reporting success installing MaryTTS on Ubuntu using these directions...

Reference: http://askubuntu.com/questions/709241/how-to-install-marytts-on-ubuntu (http://askubuntu.com/questions/709241/how-to-install-marytts-on-ubuntu)

Please see attachment (for discussion purposes only). 

The default demo site address runs on localhost port 59125 . 

NOTE:  This seems to be version 5.1.2 (not the latest version apparently).
As this was just an experiment, no recommendations are intended here.

Title: Re: Rivescript not working as expected
Post by: 8pla.net on March 23, 2017, 05:51:17 am
Wow!  Mary generates Parts of Speech in XML ...

Code
<?xml version="1.0" encoding="UTF-8"?>
<maryxml xmlns="http://mary.dfki.de/2002/MaryXML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="0.5" xml:lang="en-US">
<p>
<voice name="cmu-slt-hsmm">
<s>
<t pos="VB">Welcome</t>
<t pos="TO">to</t>
<t pos="DT">the</t>
<t pos="NN">world</t>
<t pos="IN">of</t>
<t pos="NN">speech</t>
<t pos="NN">synthesis</t>
<t pos=".">!</t>
</s>
</voice>
</p>
</maryxml>

And phonemes as well in XML ...

Code
<?xml version="1.0" encoding="UTF-8"?>
<maryxml xmlns="http://mary.dfki.de/2002/MaryXML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="0.5" xml:lang="en-US">
<p>
<voice name="cmu-slt-hsmm">
<s>
<t g2p_method="lexicon" ph="' w E l - k @ m" pos="VB">Welcome</t>
<t g2p_method="lexicon" ph="' t u" pos="TO">to</t>
<t g2p_method="lexicon" ph="D @" pos="DT">the</t>
<t g2p_method="lexicon" ph="' w r= l d" pos="NN">world</t>
<t g2p_method="lexicon" ph="' V v" pos="IN">of</t>
<t g2p_method="lexicon" ph="s - ' p i tS" pos="NN">speech</t>
<t g2p_method="lexicon" ph="' s I n - T @ - s @ s" pos="NN">synthesis</t>
<t pos=".">!</t>
</s>
</voice>
</p>
</maryxml>
Title: Re: Rivescript not working as expected
Post by: Freddy on March 23, 2017, 11:56:49 am
Yup - Mary is really very good. You can also change pronunciation too.

Mary will also provide phoneme timings, which is what you need for lip sync.
Title: Re: Rivescript not working as expected
Post by: brty21 on March 23, 2017, 11:32:27 pm
 :) Thanks I will definitely try to get mary going with that info -after the weekend (i got five children!)

Then, on the front end side of things, all I want to do is figure out how to get an extra avatar pic to show temporarily before it goes back to idle.   ie idle-talking-action-idle or idle-action-talking-idle
....If you see what i mean
- I will post my code tampering attempts another time though
Title: Re: Rivescript not working as expected
Post by: brty21 on March 27, 2017, 11:34:23 am
Here's a short couple of scripts that I came up with which use PHP and javascript to interface with MaryTTS.

Browsers/JS don't like cross site scripting. There's ways to get around it, but I find them complicated and it's easily solved with a relay for testing purposes. You can get into all that other gubbins later if you want.

Take these two scripts and put them in some directory that is useful to you. The HTML/JS script calls the PHP. The PHP calls Mary. The PHP then sends what it got from Mary back to the client or browser. The client then plays it.

The main reason why you get the cross site problem is that Mary uses a different port compared to normal, ie port 80 in most cases.



Here's the HTML/JS :

Code
<html>

<title>Demo Play TTS</title>

<head>

</head>

<script>

// It's a pain using JS for cross site so just use a simple PHP relay to start with.
var relay = "gettts.php";

// The words to render.
var tts = "Just a simple Demo. Refresh page if you change the words in the script.";

// The URL for the relay with the words added on.
var url = relay + "?words=" + tts;

// Set up an audio player and get the audio from the relay URL.
var audio = new Audio(url);

// Play the audio which would have been made by Mary.
audio.play();

</script>

<body>

Just a simple Demo. Refresh page if you change the words in the script.

</body>

</html>

And the PHP...

Code
<?php

// Your server or host.
$host = "http://localhost";

// A voice you have installed with Mary.
$voice = "cmu-slt-hsmm";

// Get the words sent from the JS - best to do some sanitising here later.
$words = $_GET['words'];

// URL to the Mary port and various settings.
$url = $host  . ":59125/process?INPUT_TEXT=" . $words . ".&INPUT_TYPE=TEXT&OUTPUT_TYPE=AUDIO&LOCALE=en_US&AUDIO=WAVE_FILE&VOICE=" . $voice;

// Mary doesn't like spaces.
$url = str_replace(" ", "+", $url);

// Get the WAV file from Mary.
$wav = file_get_contents($url);

// Set a header for the client.
header('Content-Type: audio/wav');

// Echo the audio data.
echo $wav;

// End.
die();

Have a play with that. Save the PHP as 'gettts.php' and the HTML whatever you see fit. Change the JS variable 'tts' to whatever you like. Just hit the HTML page in your browser to see what it does.

Hopefully it will work, it did for me. You may have to change the voice setting if you don't have that one, but I think that is the default voice when installing.

Note that PHP is server side - so you need to browse to the HTML via your local host. Just double clicking on the HTML file will not work.
:)

Working well, Thanks a lot! At least I have some idea now

Since RiveScript is working as expected now. I will post new topics to new threads
Title: Re: Rivescript not working as expected- solved
Post by: 8pla.net on March 28, 2017, 10:32:21 pm
Does MaryTTS require Dedicated Server Hosting?

It seems to me it may, but I'm not really sure, since
I've only just tested it on my localhost.
Title: Re: Rivescript not working as expected- solved
Post by: Freddy on March 28, 2017, 11:04:18 pm
I don't think a regular shared server is possible unless they bundle it. You'd need shell access to install it. I use a VPS.