1

I am currently building a Siri-Like Virtual Assistant using the AnnyangJS Library. Currently I have to enter every single command in the code example demonstrated below. Since this project consists of a decent amount of Input/Output commands would there be a way to automate this process using a database(or something similar), so I would simply be able to build a system of commands, without having to manually enter every single one.

I have searched Google, SO, and several other sources, but have not found any information regarding a possibility of this. Any information regarding as to how this could be accomplished would be immensely appreciated.

The current stage of the project can be viewed at a JS Fiddle here.

You can also directly run the app here:

annyang.setLanguage('en-US');

function speakEnglish() {
  syeVoice = "US English Male";
  if (annyang) {
    // Let's define our first command. First the text we expect, and then the function it should call
    var hello = {
      'Hello': function() {

        document.getElementById("reply").innerHTML = "Hello!";
        responsiveVoice.speak('Hello!', syeVoice);

      }
    };
    var hi = {
      'hi': function() {

        document.getElementById("reply").innerHTML = "Hey There!";
        responsiveVoice.speak('Hey There!', syeVoice);
      }
    };
    var hey = {
      'hey': function() {

        document.getElementById("reply").innerHTML = "Hey There!";
        responsiveVoice.speak('Hey There!', syeVoice);
      }
    };
    var who_are_you = {

      'Who are you': function() {

        document.getElementById("reply").innerHTML = "I am Sye, an artificial intelligence.";
        responsiveVoice.speak('I am Sai. An artificial intelligence.', syeVoice);

      }
    };

    var how_are_you = {

      'how are you': function() {

        document.getElementById("reply").innerHTML = "I feel great! What about you? ";
        responsiveVoice.speak("I feel great! What about you? ", syeVoice);
      }
    };
    var i_feel_good = {

      'I feel (great) (good) (happy)': function() {

        document.getElementById("reply").innerHTML = "That's Wonderful!";
        responsiveVoice.speak("That's Wonderful!", syeVoice);
      }
    };

    var i_feel_bad = {

      'I feel (sad) (bad) (horrible)': function() {

        document.getElementById("reply").innerHTML = "I would empathize, but I dont have feelings.";
        responsiveVoice.speak("I would empathize ... but I dont have feelings. ", syeVoice);
      }
    };
    var switch_to_chinese = {

      'Switch to Chinese Mode': function() {

        document.getElementById("reply").innerHTML = "你好。";
        responsiveVoice.speak('你好', 'Chinese Female');
        speakChinese();


      }
    };
    var i_feel_good = {

      'I feel (great) (good) (happy)': function() {

        document.getElementById("reply").innerHTML = "That's Wonderful!";
        responsiveVoice.speak("That's Wonderful!", syeVoice);
      }
    };
    var bye = {

      '(good)bye': function() {

        document.getElementById("reply").innerHTML = "Goodbye!";
        responsiveVoice.speak("Goodbye", syeVoice);
      }
    };
    var play_classical_music = {

      'play classical music': function() {

        document.getElementById("reply").innerHTML = "Playing Classical Music..";
        document.getElementById('classical-music').play();
      }
    };
    var stop_classical_music = {

      'stop playing classical music': function() {

        document.getElementById("reply").innerHTML = " Music Stopped";
        document.getElementById('classical-music').pause();
      }
    };
    var play_jazz_music = {

      'play jazz music': function() {

        document.getElementById("reply").innerHTML = "Playing Jazz Music..";
        document.getElementById('jazz-music').play();
      }
    };
    var stop_jazz_music = {

      'stop playing jazz music': function() {

        document.getElementById("reply").innerHTML = " Music Stopped";
        document.getElementById('jazz-music').pause();
      }
    };
    var good_job = {

      'good job': function() {

        document.getElementById("reply").innerHTML = "Thanks!";
        responsiveVoice.speak("Thanks", syeVoice);
      }
    };
    annyang.addCallback('resultNoMatch', function() {
      document.getElementById("reply").innerHTML = "I did'nt seem to catch that. Could you please repeat.";
      responsiveVoice.speak("I did not seem to catch that. Could you please repeat.", syeVoice);
    });
    var thankyou = {

      'Thank you (sai)': function() {

        document.getElementById("reply").innerHTML = "You're Welcome!";
        responsiveVoice.speak("Your Welcome!", syeVoice); // It must be spelled incorrectly in order to Sye to be able to say it correctly. 
      }
    };
    var thanks = {

      'Thanks (sai)': function() {

        document.getElementById("reply").innerHTML = "You're Welcome!";
        responsiveVoice.speak("Your Welcome!", syeVoice); // It must be spelled incorrectly in order to Sye to be able to say it correctly. 
      }
    };

    // Add our commands to annyang
    annyang.addCommands(good_job);
    annyang.addCommands(stop_jazz_music);
    annyang.addCommands(play_jazz_music);
    annyang.addCommands(stop_classical_music);
    annyang.addCommands(play_classical_music);
    annyang.addCommands(hello);
    annyang.addCommands(hi);
    annyang.addCommands(hey);
    annyang.addCommands(who_are_you);
    annyang.addCommands(how_are_you);
    annyang.addCommands(switch_to_chinese);
    annyang.addCommands(i_feel_good);
    annyang.addCommands(i_feel_bad);
    annyang.addCommands(bye);
    annyang.addCommands(thankyou);
    annyang.addCommands(thanks);




    // Start listening. You can call this here, or attach this call to an event, button, etc.
    annyang.start();
  }
};

speakEnglish();
/* Resources */

@import url(https://fonts.googleapis.com/css?family=Raleway:300,200);
@import url(https://fonts.googleapis.com/css?family=Lato:300);

/* Styling */

body {
  text-align: center;
  background-color: #ecf0f1;
  color: #34495e;
  background-size: cover;
  background-repeat: no-repeat;
  font-weight: lighter;
}
#reply {
  font-family: 'Raleway', sans-serif;
  padding: 20px;
}
<script src="//cdnjs.cloudflare.com/ajax/libs/annyang/2.0.0/annyang.min.js"></script>
<script src='https://code.responsivevoice.org/responsivevoice.js'></script>

<audio id="jazz-music">
  <source src="http://www.justjazznyc.com/sound/dreamer.mp3">
</audio>
<audio id="classical-music">
  <source src="http://www.forelise.com/media/fur_elise_valentina_lisitsa.mp3">
</audio>

<h1 id="reply"> Welcome </h1>
Christopher Moore
  • 15,626
  • 10
  • 42
  • 52

1 Answers1

0

You can't do it that way, it would take ages to place for every word in the if statement.But if you insist to do it in that way, do it with a database. In order to do it correctly you will need to create an algorithm, that will solve your problem. Here is an article it's iOs dev but might help you about your problem: http://www.raywenderlich.com/60870/building-ios-app-like-siri