how to introduce speech recognition into game.

edited April 2016 in Library Questions

Hi,

I am currently working on a university final year project, where I am taking an existing piece of work and adding a useful element to it. I have started building the classic brick breaker game but I am not sure how can i use the speech-to-text library to introduce speech commands into the game, such as 'Run' to start the game and move the paddle by saying 'L' or 'R' (Left and Right).. I would like to configure the commands to the amount of pixels the paddle moves across..such as have default commands set as '30 pixels' and further commands such as 'L1' and 'R2' could be used to move a further distance '40pixels' maybe.

Thank you.

Current Code:

        float ballX;        // x coordinate of the ball
        float ballY;        // y  coordinate of the ball
        float ballW;        // width of the ball
        float ballH;        // height of the ball
        float moveBallX;    // move the ball from left to right randomly
        float moveBallY;    // move the ball from top to bottom randomly
        float paddleX;      // x coordinate of the paddle
        float paddleY;      // y coordinate of the paddle
        float paddleW;      // width of the paddle
        float paddleH;      // height of the paddle
        float movePaddleX;  // move the paddle left or right by 30 pixels



        void setup () {

          size (350, 400);

          // Ball parameters; initial x, y coordinates, and width, height of the ball.
          ballX = 20;
          ballY = 20;
          ballW = 15;
          ballH = 15;

          // Move the ball's coordinate positions randomly in the game.
          moveBallX = random(1, 4); 
          moveBallY = random(1, 4);

          // Paddle parameters; initial x, y coordinates, and width, height of the paddle.
          paddleX = width/2;       
          paddleY = height - 20;
          paddleW = 50;
          paddleH = 10;

          // Move the Paddle's coordinate position
          movePaddleX = 30;
        }

        void draw () {
          background (0);
          ellipse (ballX, ballY, ballW, ballH); // ball
          noStroke();
          rect (paddleX, paddleY, paddleW, paddleH); // paddle

          // Add the moving motion to the ball.
          ballX = ballX + moveBallX;    //the current x position of the ball is moved by the variable moveBallX.
          ballY = ballY + moveBallY;    ///the current y position of the ball is moved by the variable moveBallY.


          //IF statements to control the ball's x coordinate, rebounce the ball when it hits the right or left edge.

          if (ballX > width) {
            moveBallX = -moveBallX; // The values become the opposite, and allow a rebounce.
          }

          if (ballX < 0) {

            moveBallX = -moveBallX;  // The values become opposite, and allow a rebounce.
          }

          //IF statements to control the ball's y, rebounce the ball when it hits the top or bottom edge.

          if (ballY > paddleY)       // 'paddleY' is used instead of 'height'. to show a bounce on the paddle.
          {
            moveBallY = -moveBallY; // The values become the opposite, and allow a rebounce.
          }

          if (ballY < 0) {           

            moveBallY = -moveBallY; // The values become the opposite, and allow a rebounce.
          }

        }

        void keyPressed() {
          if (key == CODED) {
            if (keyCode == LEFT) {         //when the LEFT key is pressed, the paddle is moved to the left by 30 pixels.

              paddleX = paddleX - movePaddleX;
            } else if (keyCode == RIGHT) {  //when the RIGHT key is pressed, the paddle is moved to the right by 30 pixels.

              paddleX = paddleX + movePaddleX;
            }
          }
        }


        //Help acquired from the following sources:
        //https://processing.org/examples/
        //http://www.openprocessing.org/sketch/134612  
        //http://drdoane.com/thinking-through-a-basic-pong-game-in-processing/ 

Answers

Sign In or Register to comment.