• Das Erstellen neuer Accounts wurde ausgesetzt. Bei berechtigtem Interesse bitte Kontaktaufnahme über die üblichen Wege. Beste Grüße der Admin

[FRAGE] Funktion aufrufen

Freed20

New member
Hallo,

ich kenne mich ehrlicherweise null aus mit JavaScript. Ich komme aus dem Java-Welt. Ich brauche aber eine Anwendung, der mir den text über ein Mikrofon lesen tut und anhand des textes dann, die richtige sache ausgeben soll(Über eine Liste, die im Code angelegt ist). Zum Beispiel bei Hello, soll er "XXZ ausgeben". Dafür habe ich ein Beispiel von Artyom team gefunden. Ich habe es auch zum laufen gebracht. Nur stört es mich, wenn ich das richtige Wort gefunden habe(aus der Liste), dann wird nicht mehr weiter gesucht, ich muss statt dessen wieder auf das Button "start voice commands" drücken damit er eine neue Suche macht. Wie bekomme ich es hin,dass die Suche auch nach einem richtige Treffer, automatisch weiter geht. Sprich neue Spracheingabe, schauen ob treffer da ist Hier ist das HTML Code:

HTML:
<!DOCTYPE html>
<html lang="en">
  <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <meta name="description" content="">
      <meta name="author" content="Our Code World">

      <title>Hello artyom.js</title>

      <!-- Don't forget to add artyom to your document in the head tag-->

      <script src="artyom.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

  </head>

  <body>
    <div>
      <h4>Use <b>ctrl+u</b> or <b>right click > inspect element</b> to see the source code of this page.</h4>
      <input type="button" onclick="startArtyom()" value="Start voice commands"/><br><br>
      <input type="button" onclick="stopArtyom()" value="Stop listening"/><br>
      <span id="output" style="font-size:20px;color:red;"></span><br>
      <span id="time" style="font-size:35px;color:green;"></span><br>

      <span style="color:blue;">The loaded commands are : </span><br>
      <div id="commands-list">

      </div>
      <textarea id="text-content"></textarea>
      <input id="talk-lang" type="button" value="Synthesize "/>
      <select id="select-voice">

      </select>
      <input id="load-voices" type="button" value="Load voices"/>
      <div id="voices-item"></div>
    </div>
    <script>
    $("#talk-lang").click(function(){
        artyom.say($("#text-content").val());
    });

    $("#select-voice").change(function(){
        var lang = $(this).val();

        artyom.initialize({lang:lang});
    });

    document.getElementById("load-voices").addEventListener("click", function(){
        var voices = artyom.getVoices();
        var html = "";

        voices.forEach(function(voice){
            html += "Voz name : " + voice.name + " con lang : " + voice.lang + "<br>";
        });

        document.getElementById("voices-item").innerHTML = html;
    }, false);
      // Now we add the most important point of the plugin, the commands
      // This library is very flexible and now we will see why :
      // Every command is a literal object
      artyom.addCommands([
        {
          description:"Artyom can talk too, lets say something if we say hello",
          indexes:["hallo","hey"],
          action:function(i){
              // i = the index of the array of indexes option

              if(i == 0){
                //You say : "hello"
                document.getElementById('time').innerHTML = "Hello ! How are you? I don't want to talk today";
					//Here u would like to call function_two.
			      }
			  if(i == 1){
                //You say : "hello"
                document.getElementById('time').innerHTML = "Hey";
						//Here u would like to call function_two.
			         }
          }
        },
        {
          description:"Say goodbye",
          indexes:["goodbye"],
          action:function(){
            alert("Now all is over.");
          }
        },
        {
          description:"Say what time is it",
          indexes:['what time is it'],
          action:function(){
           var currentdate = new Date();
           var datetime = "About the date : " + currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/"
                + currentdate.getFullYear() + " @ "
                + currentdate.getHours() + ":"
                + currentdate.getMinutes() + ":"
                + currentdate.getSeconds();
            document.getElementById('time').innerHTML = datetime;
          }
        },
        {
          description: "Smart command, say how much x in what we say",
          indexes:["what's the number of *"],
          smart:true,
          action:function(i,wildcard){
            document.getElementById('time').innerHTML = "The number of " + wildcard + ' is '+ Math.floor(Math.random() * 4000) + 1;
          }
        }
      ]);


      // Redirect the recognized text
      artyom.redirectRecognizedTextOutput(function(text,isFinal){
        var span = document.getElementById('output');

        if(isFinal){
          span.innerHTML = '';
        }else {
          span.innerHTML = text;
        }
      });

      function startArtyom(){
        artyom.initialize({
          lang:"de-DE",// More languages are documented in the library
          continuous:false,//if you have https connection, you can activate continuous mode
          debug:true,//Show everything in the console
          listen:true // Start listening when this function is triggered
        });
      }

      function stopArtyom(){
        artyom.fatality();
      }

      window.onload = function(){
          var tab = document.getElementById("commands-list");
          var commands =  artyom.getAvailableCommands();
          var html = '';

          for(var i = 0;i < commands.length;i++){
              var command = commands[i];
              html += command.description + " : <span style='color:blue;'>"+command.indexes.toString()+"</span><br>";
          }

          tab.innerHTML = html;

          artyom.initialize({lang:"es-ES"});

        var vocesitas = [
            {lang:"es-ES",description: "Espanol"},
            {lang:"de-DE",description: "Deutsch"},
            {lang:"pt-PT",description: "Portugues"},
            {lang:"it-IT",description: "Italiano"}
        ];

        vocesitas.forEach(function(voice){
            $('#select-voice').append($('<option>', {value:voice.lang, text:voice.description}));
        });
      };
    </script>
  </body>

</html>



ich bedanke mich schon mal im voraus.

EDIT: Sorry ich habe beim erstellen der Frage natürlich einen fehler gemacht :( Kann es nicht mehr ändern.
 
Zuletzt bearbeitet von einem Moderator:
Arbeitest du auch wirklich mit https, wie oben im Code angedeutet?

Alternativ könntest du auch die startArtyom() immer in den Actions am Ende aufrufen...
 
Zurück
Oben