Zaport-speech

Once Upon a Time is a Twitter bot that can tell “once upon a time” stories. Using the Twit API, this program can search Twitter for posts that begin with or include the words “once upon a time.” When a user asks the computer to tell a story, it responds by reading that post. The context of this bot is the desktop, though it could be used anywhere (with the exception that there must be internet and computer access).

The current iteration does not function the way I would like. At the moment, the Twitter API code and the speech in/out code work properly, though I have experienced difficultly integrating the two. After many attempts over many hours, I resorted to using the output from the Twitter and copying and pasting it as a string into the speech code. While the video shows how I would like the bot to function, keep in mind that it is not running in real-time. Learning how to integrate the two programs will be my next step.

Here is a rough sketch of the program:

Here’s the code that’s used with the Twitter API:

module.exports = {
    consumer_key:         'your code'
    ,consumer_secret:      'your code'
    ,access_token:         'your code'
    ,access_token_secret:  'your code'
};
//Adapted from Daniel Shiffman
var numberOfTweets = 100;
 
var Twit = require('twit');
 
var config = require('./config');
var T = new Twit(config);
 
var params = {
    q: 'once upon a time', //give it a querry term
    count: numberOfTweets //number of tweets you want
};
 
T.get('search/tweets', params, gotData); //search twitter
 
function gotData (err, data, response) {
    var tweets = data.statuses;
    for (var i = 0; i < tweets.length; i++){
        console.log(tweets[i].text);
    }
};

Here’s the Speech Code:

 
 
    <!-- P5 stuff -->
    <script src="../p5.js"></script><script src="../addons/p5.dom.js"></script>
 
  <!-- speech stuff -->
    <script src="../addons/p5.speech.js"></script>
 
  <!-- Twitter stuff 
    <script src="twitter_code/node2/bot.js"></script>
    <script src="twitter_code/node2/config.js"></script>-->
 
  <!-- My stuff -->
    <script src="once_upon_a_time.js"></script>
// ONCE-UPON-A-TIME
// Adapted code from GOLAN LEVIN
 
// speech recognizer variables
var mySpeechRecognizer;
var mostRecentSpokenWord;
var mostRecentConfidence;
 
var img1;
var img2;
var img3;
var img4;
var img5;
 
// game variables
var x, y;
var dx, dy;
 
var index = 0;
 
var words = [
 
"Once upon a time, I became yours and you became mine, and we'll stay together, through both the tears and the laughter, because that's what they call happily ever after."
,"Once upon a Time, I got so crazy I almost forgot my homework. That time, is the present time." 
,"Once upon a time, the World wanted to be like us. Now they demand we become like them."
,"Once upon a time, its foibles were amusing, but now it's just pathetic and nonsensical, and it's amazing that anyone pays it any attention."
];
 
var names = [
"@TeamPatatas"
,"@5hAriLmINFINITY"
,"@ananavarro"
,"@britektire"
,"@NMamatas"
];
 
var iptr = 0; // a counter for the words
 
var myVoice = new p5.Speech(); // new P5.Speech object
 
//=========================================
function setup() {
    createCanvas(640, 480);
 
    mostRecentConfidence = 0;
    mostRecentSpokenWord = "";
    initializeMySpeechRecognizer(); 
 
    x = width/2;
    y = height/2;
    dx = 0;
    dy = 0;
 
    img1 = loadImage("001.jpg");
    img2 = loadImage("002.jpg");
    img3 = loadImage("003.jpg");
    img4 = loadImage("004.jpg");
    img5 = loadImage("005.jpg");
}
 
//=========================================
function initializeMySpeechRecognizer(){
    mySpeechRecognizer = new p5.SpeechRec('en-US'); 
 
    // These are important settings to experiment with
    mySpeechRecognizer.continuous = true;      // Do continuous recognition
    mySpeechRecognizer.interimResults = false; // Allow partial recognition (faster, less accurate)
    mySpeechRecognizer.onResult = parseResult; // The speech recognition callback function
    mySpeechRecognizer.start(); // Start the recognition engine. Requires an internet connection!
 
    console.log(mySpeechRecognizer);
}
 
//=========================================
 
function doList()
    {
        myVoice.listVoices(); // debug printer for voice options
    }
 
function mousePressed()
    {
        // if in bounds:
        if(mouseX