Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. The design of HTML and WebserverComponent

    1. How to create a button and catch a click event on it?

    2. How to render Dialogflow intermediate transcripts dynamically in a text box?

  2. The demo program connects all the components (NaoqiMicrophoneSensor(or local DesktopMicrophone), WebserverComponent, DialogflowService DialogflowComponent, etc)

The design of html and Webserver

1. How to create a button and catch a click event on it?

In the demo_pepper_guess_number.html, we need to add a button and make it listen to the click event. Once the button is clicked, the isClicked flag will be set to true, and it sends will send the flag to the Flask server via WebSocket.

Code Block
// Flag to track if the game should start
var isClicked = false; 

// Get a reference to the startButton element
var startButton = document.getElementById('startButton');

// Event listener for the start button click
startButton.addEventListener('click', function() {
  isClicked = true; // Set the flag
  sendFlagToServer(isClicked);
});

// Function to send flag to Flask server
function sendFlagToServer(flag) {
  socket.emit('clicked_flag', flag);
}

On the Flask serverFlaser server (webserver_pepper_tablet.py), we need to register a handler to react to the "clicked_flag" event.

...

If the flag is set to true, a SICMessage “ButtonClicked” will be sent to the SIC channel as an output of this component. This output will be received on a callback in on the demo side (demo_pepper_guess_number.py) to determine if whether the button has been clicked or not.

...

When a web client receives an “update_textbox” event emitted from the flask Flask server, the event handler is triggered. Then it calls the updateTextbox(text) function passing the received text as an argument.

Code Block
    // Event handler for receiving updated text
    socket.on('update_textbox', function(text) {
      updateTextbox(text);
    });

On the Flask serverFlaser server (webserver_pepper_tablet.py), we emit the “update_textbox” event along with the transcript transcribed from Dialogflow.

...

The demo program connects all the components

The demo program is located in tests/demo_webserver/demo_pepper_guess_number.py.

There are many SIC components we need to connect to in this demo.

...

Components running on a local machine:

  1. WebserverComponent

  2. DialogflowComponent

Here is the schematic overview of how this program works: The demo_pepper_guess_number progam serves as the user application control, sending an HtmlMessage as input for the WebserverComponent to render. Upon receiving the ButtonClicked message with a value of “True”, it sends a GetIntentRequest to the DialogflowComponent. The resulting RecognitionResult is received in the on_dialog callback, and upon obtaining the transcript result, a TranscriptMessage is sent to the WebserverComponent

...

for dynamic transcript rendering in the above-mentioned textbox.

During each GetIntentRequest request, the resulting query_text generated by Dialogflow is passed to the extract_and_compare_number function. This function extracts a number from the query_text and compares it with the randomly generated number x. When the detected number is higher/lower than or equal to x, we will request the NaoqiTextToSpeechActuator to make Pepper say the corresponding response.

...