Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

📢 A text2speech implementation for HTML documents.

License

Notifications You must be signed in to change notification settings

chialab/speaker

Repository files navigation

Speaker

A text2speech implementation for HTML documents.

NPM


Get the library

Install via NPM or Yarn:

npm i @chialab/speaker
yarn add @chialab/speaker

Usage

Initialize

import { Speaker } from '@chialab/speaker';

const article = document.querySelector('article');
const speaker = new Speaker(article);

Playback

speaker.play(); // Play or resume playback
speaker.pause(); // Pause
speaker.stop(); // Stop

Highlight

Highlight the active sentence and/or word:

speaker.setupHighlighter({
    boundaries: true,
    sentences: true,
});

Warning

The client must support CSS Highlights API to enable highlighting. (caniuse.com)

Highlights colors

You can stylize highlighted words, sentences and blocks via CSS:

::highlight(speaker-blocks-highlight) {
    background-color: #ffc80080;
}

::highlight(speaker-sentences-highlight) {
    background-color: #ffc800;
}

::highlight(speaker-boundaries-highlight) {
    background-color: #ff9300;
}

Development

Build status codecov

Build

Install the dependencies

yarn

and run the build script:

yarn build

This will generate the ESM and CJS bundles in the dist folder and declaration files in the types folder.


License

Speaker is released under the MIT license.

About

📢 A text2speech implementation for HTML documents.

Resources

License

Stars

Watchers

Forks