1

私は現在、 AnnyangJS Libraryを使用してSiri のような仮想アシスタントを構築しています。現在、以下に示すコード例のすべてのコマンドを入力する必要があります。このプロジェクトはかなりの量の入力/出力コマンドで構成されているため、データベース (または同様のもの) を使用してこのプロセスを自動化する方法があるため、手動ですべてのコマンドを入力することなく、コマンドのシステムを簡単に構築できます。単一のもの。

Google、SO、および他のいくつかの情報源を検索しましたが、この可能性に関する情報は見つかりませんでした. これをどのように達成できるかに関する情報は、非常に高く評価されます。

プロジェクトの現在の段階は、こちらの JS Fiddle で見ることができます。

ここでアプリを直接実行することもできます。

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>

4

1 に答える 1