GithubHelp home page GithubHelp logo

voice4game-js's Introduction

Voice4Game.js Voice Command Library

This JavaScript library is meant to facilitate the control of web-based HTML5/JavaScript games through voice commands.

(More background information and in-depth documentation coming soon!)

Usage Instructions

  1. Include the voice4game.js library in your HTML5 project directory.

  2. Add the following script tags before those of your JS game logic code in your main HTML file (often index.html):

       <script src=”PATH_TO_V4G”></script>
    
  • Replace PATH_TO_V4G with the relative path to the voice4game.js file from the directory of your main HTML file.
  • The voice4game.js file needs to be included before the game logic so that it may be initialized and configured within the game logic’s scope.
  1. Call the Voice4Game.init function at the end of your initialization game logic so that it executes once and has access to game commands that you intend to map to voice commands.
  • Voice4Game.init’s first argument is an object whose key-value pairs are mappings of voice command text to game command functions (String -> Function), e.g.

      {“move left”: function() { player.moveLeft(); }, // ex. of mapping to an anonymous function
       “move right”: player.moveRight} // ex. of mapping to an existing function
    
    • (Note that proper creation of game command functions may require some experience in using closures in JavaScript to retain scope.)
  • Voice4Game.init’s second argument is a boolean value that enables “debug mode” if true, and leaves it off if false.

    • “Debug mode” dynamically adds a transcription and logging text area to the top of your main HTML file so that spoken input and speech recognition statuses/errors may be displayed.
  1. After your Voice4Game.init call, call the Voice4Game.start function wherever you want the speech recognition to begin listening (which is often right after the Voice4Game.init call).
  • OPTIONAL: If you would like to dynamically modify the mapping of voice commands to game command functions during your game’s runtime, you may use the Voice4Game.registerVoiceCmd and Voice4Game.unregisterVoiceCmd functions to add or remove mappings anytime after initialization. You may also call Voice4Game.stop at a point where you would like to stop speech recognition.
  1. To test the usage of the newly integrated Voice4Game.js in your modified game, you must run it with a working internet connection in a browser that supports the Web Speech API, such as Google Chrome.
  • You can either deploy your modified game online (such as on a GitHub gh-pages page) or run it on a local HTTP web server serving to a port on your localhost.
  • If you host it online, make sure you visit your game’s page at its HTTPS URL. Otherwise, the browser will ask you for microphone permissions after every recognized portion of speech.
  • You must accept the requested microphone permissions in order for Voice4Game.js to work. You will see a red dot on your browser tab to indicate whether speech recognition is currently active.
  • Make sure to speak commands you included in the Voice4Game.js initialization clearly, and when contextually relevant within your game!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.