Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added natural language interactions with api.ai #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[Samaritan 2.0!](https://rodrigograca31.github.io/Samaritan/)
[Samaritan 2.1!](https://rodrigograca31.github.io/Samaritan/)
=========

Features:
* Speech recognition
* Voice image search
* Added natural language interactions with api.ai (Endless possibilities, refer docs at https://docs.api.ai/)
Demo at https://iocare.dlinkddns.com/Samaritan/ (Ask question related to relations, feelings, vacations, travel, education, hobbies etc)

Technologies:
* HTML
Expand Down
42 changes: 34 additions & 8 deletions js/speech.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,40 @@ var speechModule = (function () {
samaritanModule.showImages(photosURL);
});
}

//Added Real Power of AI - with AI API from api.ai
var accessToken = "Client access token from api.ai";//Please use your own accessToken.
var baseUrl = "https://api.api.ai/v1/";
var _send = function (phrase) {
console.log('Welcome to Samaritan ASI!');
console.log('processing send');
var text = phrase;
$.ajax({
type: "POST",
url: baseUrl + "query?v=20160910",
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Authorization": "Bearer " + accessToken
},
data: JSON.stringify({ q: text, lang: "en" }),
success: function(data) {
var txt = data.result.fulfillment.speech;
samaritanModule.write(txt);
console.log(txt);
},
error: function() {
samaritanModule.write('Internal Server Error');
}
});
samaritanModule.write('...');
};
//Added Real Power of AI - Ends Here

var _commands = {
'locate the machine': _writeWrapper('Target can not be reached !'),
'where are you': _writeWrapper("I am everywhere , i am god"),
'who am I': _writeWrapper("Asset"),
'who are you': _writeWrapper('i am samaritan !'),
//'where are you': _writeWrapper("I am everywhere , i am god"),//implemented in AI
'who am I': _writeWrapper("Admin"),
//'who are you': _writeWrapper('i am samaritan !'),//implemented in AI
'find Finch': _writeWrapper('Locating Harold Finch ?'),
'yes': _writeWrapper('yes what ?'),
'no': _writeWrapper('ok then what is your suggestion ?'),
Expand All @@ -49,10 +77,8 @@ var speechModule = (function () {
'find (me) *name': _flickrSearch,
'search (for) *name': _flickrSearch,
'show (me) *name': _flickrSearch,
//repeats everything if it's not one of the above
'*phrase': function (phrase) {
samaritanModule.write(phrase);
}
//This is now handled by AI
'*phrase': _send
};

//PUBLIC **********************************
Expand Down