Giter VIP home page Giter VIP logo

cybertyper's Introduction

CyberTyper

A ReactJS component for automatically typing text like a typewriter synchronized with Speech Synthesis (using jaxcore-say) and Speech Recognition (coming soon).

Examples:

Usage:

yarn install cybertyper

Include:

import CyberTyper from 'cybertyper';
import Say from 'jaxcore-say';
Say.setWorkers({
	'espeak': 'webworkers/espeak-en-worker.js'
});
const voice = new Say({
	language: 'en-us'
});

Jaxcore Say WebWorkers

The say library is used for speech synthesis. The webworker file set in setWorkers() must be copied to the public html directory (eg public/webworkers):

espeak-en-worker.js can be downloaded from here

Create a "script"

A CyberTyper script is an array of lines which will be speech synthesized and typed:

const cyberTyperScript = [
	{
		text: 'A quick brown fox',
		linebreak: true
	},
	{
		text: 'jumped over', 
		linebreak: true
	},
	{
		text: 'the lazy dog.', 
		linebreak: true
	}
];

linebreak: true adds an additional line break after the line is typed.

Different jaxcore-say voice profiles can be defined for each line:

const cyberTyperScript = [
	{
		text: 'I am Cylon',
		speaker: {
			voice: 'Cylon'
		}
	},
	{
		text: 'I am Leon',
		speaker: {
			voice: 'Leon'
		}
	}
];

A display name and custom CSS class can be specified for each line:

const cyberTyperScript = [
	{
		text: 'I am Cylon',
		speaker: {
			voice: 'Cylon',
			name: 'Cylon',
			className: 'cyloncss'
		}
	},
	{
		text: 'I am Leon',
		speaker: {
			voice: 'Leon',
			name: 'Leon',
			className: 'roycss'
		}
	}
];

Component Usage

<CyberTyper
    autostart={true}
    script={cyberTyperScript}
    maxLines={15}
    lineBreakDuration={200}
    hideCursorWhenDone={true}
    onComplete={() => {
        console.log('CyberTyper complete');
}}/>

Beware: web browsers disable JavaScript AudioContext usage until after a user action. So <CyberTyper/> should be rendered after a mouse click or keyboard action.

Custom CSS

The <CyberTyper/> component does not include any CSS of it's own. But the DIV and SPAN elements have .CyberTyper classes defined which can be used to customize how the generated lines look, including the styling of a cursor and names.

See CyberTyper.css

cybertyper's People

Contributors

dsteinman avatar

Watchers

James Cloos avatar

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.