php example

Discussion in 'Amazon Echo Development' started by Chad Doebelin, Jun 23, 2015.

  1. Chad Doebelin

    Chad Doebelin New Member

    Messages:
    17
    Likes Received:
    3
    Trophy Points:
    3
    Gender:
    Male
    Code:
    <?php
    function speechOut($words) {
            header('Content-type: application/json');
    
            $open = '{"version": "1.0","sessionAttributes":"","response":{"outputSpeech":{"type": "PlainText","text": "';
            $close = '"},"shouldEndSession": false}}';
    
            echo $open;
             echo ($words);
            echo $close;
    }
    $data = json_decode(file_get_contents('php://input'), TRUE);
    $text = print_r($data,true);
    
    $ver = $data['session'][sessionId];
    
    file_put_contents('what_amazon_is_saying.txt', $text);
    file_put_contents('speech_command.txt',$ver);
    //speechOut("Say what you want now! now!");
    //speechOut($ver);
    speechOut('are you still listening?');
    ?>

    This is useful and has a speechOut() function.

    I can tail the two output files to see the conversation between echo and my script.
     
    Last edited: Jun 23, 2015
    Avinash likes this.

Share This Page