<commit_before>var server = require("./server");
var tjbot = require('tjbot');
var config = require('./config');
var AudioContext = require('web-audio-api').AudioContext
context = new AudioContext
var request = require("request");
var fs = require('fs');
var fileDir = process.cwd() + "/public/img"
var curImage = "";

// obtain our credentials from config.js
var credentials = config.credentials;

// obtain user-specific config
var VOICE = config.voice;
var WORKSPACEID = config.conversationWorkspaceId;

// these are the hardware capabilities that TJ needs for this recipe
var hardware = ['microphone', 'speaker', 'led', 'servo'];

// Set up configuration paramters
var tjConfig = {
    verboseLogging: true, //enable console debugging
    servoPin: 7, // set servo pin
    cameraParams: {
        height: 720,
        width: 960,
        vflip: false,
        hflip: false
    } // setup my camera capture parameters
};

var listening = true;

// instantiate our TJBot!
var tj = new tjbot(hardware, tjConfig, credentials);

server.wss.on('connection', function connection(ws) {
    ws.on('message', function incoming(message) {
        message = JSON.parse(message)
        console.log("beee", (message));
        switch (message.event) {
            case 'wave':
                wave("Waving my arm. Just for you")
                break;
            case 'dance':
                predance("Sure. I'll play some music and dance.")
                break;
            case 'see':
                see("Taking a picture!")
                break;
            case 'text':
                seeText("Scanning for text in the image")
                break;
            case 'led':
                console.log("shinning led ", message.color)
                tj.shine(message.color)
                break;
            case 'speak':
                console.log("speaking ", message.value)
                logSpeak("TJBot", message.value);
                tj.speak(message.value).then(function() {
                    tj.shine("white");
                });
                break;
            case 'listening':
                console.log("toggle listening", message.value)
                listening = message.value;
                break;

        }
    });

});

startListening();



function startListening() {

    tj.listen(function(msg) {
        if (listening) {
            logSpeak("you", msg);
            // send to the conversation service
            tj.converse(WORKSPACEID, msg, function(response, responseText) {
                // speak the result
                response = response.object;
                if (response.output.text.length > 0) {
                    //console.log(response)
                    conversation_response = response.output.text[0];
                    if (conversation_response != undefined) {
                        var matchedIntent = response.intents[0].intent; // intent with the highest confidence
                        var intentconfidence = response.intents[0].confidence;
                        console.log("> intents : ", response.intents);

                        if (intentconfidence > 0.5) {
                            tj.shine("green");
                            if (matchedIntent == "dance") {
                                predance("Sure, will play some music");
                                //dance();
                            } else if (matchedIntent == "wave") {
                                wave(conversation_response);
                            } else if (matchedIntent == "see") {
                                see(conversation_response);
                            } else if (matchedIntent == "off_topic") {
                                // do nothing
                            } else {

                                tj.speak(conversation_response).then(function() {
                                    tj.shine("white");
                                });
                            }

                            if (matchedIntent != "off_topic") {
                                logSpeak("TJBot", conversation_response, matchedIntent + "( " + intentconfidence + ")");
                            }

                        } else {
                            tj.shine("red");
                            setTimeout(function() {
                                tj.shine("white");
                            }, 800);
                        }

                    } else {
                        tj.shine("red");
                        console.log("The response (output) text from your conversation is empty. Please check your conversation flow \n" + JSON.stringify(response))
                    }
                } else {
                    console.error("The conversation service did not return any response text.");
                }
                //console.log("conversation response", response)
            });
        }

    });
    //  }

}

function setLED(color) {
    tj.shine(color)
}

function predance(conversation_response, intent) {
    //logSpeak("TJBot", conversation_response, intent);
    tj.speak(conversation_response).then(function() {
        dance("club.wav")
    });
}

function wave(conversation_response) {
    //logSpeak("TJBot", conversation_response);
    tj.speak(conversation_response).then(function() {
        // wave
        tj.wave();<commit_msg>udpate UI .. add intent<commit_after>var server = require("./server");
var tjbot = require('tjbot');
var config = require('./config');
var AudioContext = require('web-audio-api').AudioContext
context = new AudioContext
var request = require("request");
var fs = require('fs');
var fileDir = process.cwd() + "/public/img"
var curImage = "";

// obtain our credentials from config.js
var credentials = config.credentials;

// obtain user-specific config
var VOICE = config.voice;
var WORKSPACEID = config.conversationWorkspaceId;

// these are the hardware capabilities that TJ needs for this recipe
var hardware = ['microphone', 'speaker', 'led', 'servo'];

// Set up configuration paramters
var tjConfig = {
    verboseLogging: true, //enable console debugging
    servoPin: 7, // set servo pin
    cameraParams: {
        height: 720,
        width: 960,
        vflip: false,
        hflip: false
    } // setup my camera capture parameters
};

var listening = true;

// instantiate our TJBot!
var tj = new tjbot(hardware, tjConfig, credentials);

server.wss.on('connection', function connection(ws) {
    ws.on('message', function incoming(message) {
        message = JSON.parse(message)
        console.log("beee", (message));
        switch (message.event) {
            case 'wave':
                wave("Waving my arm. Just for you")
                break;
            case 'dance':
                predance("Sure. I'll play some music and dance.")
                break;
            case 'see':
                see("Taking a picture!")
                break;
            case 'text':
                seeText("Scanning for text in the image")
                break;
            case 'led':
                console.log("shinning led ", message.color)
                tj.shine(message.color)
                break;
            case 'speak':
                console.log("speaking ", message.value)
                logSpeak("you", message.value);
                converse(message.value);
                // tj.speak(message.value).then(function() {
                //     tj.shine("white");
                // });
                break;
            case 'listening':
                console.log("toggle listening", message.value)
                listening = message.value;
                break;

        }
    });

});

startListening();



function startListening() {

    tj.listen(function(msg) {
        if (listening) {
            logSpeak("you", msg);
            // send to the conversation service
            converse(msg);
        }
    });

}

function converse(msg) {
    tj.converse(WORKSPACEID, msg, function(response, responseText) {
        // speak the result
        response = response.object;
        if (response.output.text.length > 0) {
            //console.log(response)
            conversation_response = response.output.text[0];
            if (conversation_response != undefined) {
                var matchedIntent = response.intents[0].intent; // intent with the highest confidence
                var intentconfidence = response.intents[0].confidence;
                console.log("> intents : ", response.intents);

                if (intentconfidence > 0.5) {
                    tj.shine("green");
                    if (matchedIntent == "dance") {
                        predance("Sure, will play some music");
                        //dance();
                    } else if (matchedIntent == "wave") {
                        wave(conversation_response);
                    } else if (matchedIntent == "see") {
                        see(conversation_response);
                    } else if (matchedIntent == "off_topic") {
                        // do nothing
                    } else {

                        tj.speak(conversation_response).then(function() {
                            tj.shine("white");
                        });
                    }

                    if (matchedIntent != "off_topic") {
                        logSpeak("TJBot", conversation_response, matchedIntent + "(" + intentconfidence.toFixed(2) * 100 + "%)");
                    }

                } else {
                    tj.shine("red");
                    setTimeout(function() {
                        tj.shine("white");
                    }, 800);
                }

            } else {
                tj.shine("red");
                console.log("The response (output) text from your conversation is empty. Please check your conversation flow \n" + JSON.stringify(response))
            }
        } else {
            console.error("The conversation service did not return any response text.");
        }
        //console.log("conversation response", response)
    });
}

function setLED(color) {
    tj.shine(color)
}

function predance(conversation_response, intent) {
    //logSpeak("TJBot", conversation_response, intent);
    tj.speak(conversation_response).then(function() {
        dance("club.wav")
    });
}

function wave(conversation_response) {
    //logSpeak("TJBot", conversation_response);
    tj.speak(conversation_response).then(function() {
        // wave
        tj.wave();
{'fraction_non_alphanumeric': 0.11480391225904472, 'fraction_numerical': 0.0034184787769442598, 'mean_word_length': 1.5136038186157519, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '856644', 'n_tokens_mistral': 2752, 'n_tokens_neox': 2587, 'n_words': 629}