npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

spoken-word

v1.0.1

Published

![Banner](https://github.com/westonruter/spoken-word/raw/master/wp-assets/banner-1544x500.png) Add text-to-speech (TTS) to content, with playback controls, read-along highlighting, multi-lingual support, and settings for rate, pitch, and voice.

Downloads

18

Readme

Spoken Word

Banner Add text-to-speech (TTS) to content, with playback controls, read-along highlighting, multi-lingual support, and settings for rate, pitch, and voice.

Contributors: westonruter
Tags: tts, speech-synthesis, text-to-speech, audio, voice, read-along
Requires at least: 4.7
Tested up to: 4.9
Stable tag: 1.0.1
License: MIT
Requires PHP: 5.4

Build Status Built with Grunt

Description

Add text-to-speech (TTS) to content, with playback controls, read-along highlighting, multi-lingual support, and settings for rate, pitch, and voice.

  • Uses local text-to-speech engine in user's browser. Directly interfaces with the speechSynthesis browser API. Zero external requests or dependencies.
  • Words are selected/highlighted as they are being spoken to allow you to read along.
  • Skips speaking elements that should not be read, including footnote superscripts (the sup element).
  • Pauses of different length added are between headings versus paragraphs.
  • Controls remain in view during playback, with each the current text being spoken persistently being scrolled into view. (Requires browser support for position:sticky.)
  • Back/forward controls allow you to skip to the next paragraph; when not speaking, the next paragraph to read will be selected entirely.
  • Select text to read from that point; click on text during speech to immediately change position.
  • Multi-lingual support, allowing embedded text with [lang] attribute to be spoken by the appropriate voice (assuming the user has it installed).
  • Settings for changing the default voice (for each language), along with settings for the rate of speech and its pitch. (Not supported by all engines.) Changes can be made while speaking.
  • Hit escape to pause during playback.
  • Voice preferences are persistently stored in localStorage, with changes synced across windows (of a given site).
  • Ability to use JS in standalone manner (such as in bookmarklet).
  • Known to work in the latest desktop versions of Chrome, Firefox, and Safari. (Tested on OSX.) It does not work reliably in mobile/touch browsers on Android or iOS, apparently due both to the (still experimental) speechSynthesis API not being implemented well enough on those systems and/or programmatic range selection does not work the same way as on desktop. For these reasons, the functionality is disabled by default on mobile operating systems.

Try it out on standalone example with some test content.

Theme Config

The settings for Spoken Word are presented in an HTML5 dialog element. For browsers that do not yet support this feature, the plugin bundles the dialog-polyfill. The polyfill is only included if it is detected the browser does not support dialog natively. The inclusion of the polyfill can be disabled by adding the following to your theme or plugin:

add_filter( 'spoken_word_include_dialog_polyfill', '__return_false' );

For themes that have a sticky header (such as the nav menu in Twenty Seventeen) you may need to add some additional CSS to ensure that the sticky-positioned playback controls do not get hidden behind the sticky header. For example in Twenty Seventeen, you can add the following to the Custom CSS in the Customizer:

@media screen and (min-width: 782px) {
	body:not(.admin-bar) .spoken-word--active {
		top: calc( 0.5em + 70px );
	}
	body.admin-bar .spoken-word--active {
		top: calc( 0.5em + 32px + 70px );
	}
}

Internals

A bookmarklet can be used to load the Spoken Word functionality into any site, even non-WordPress sites where the plugin is not installed. The key is to use the appropriate contentSelector:

( () => {
	const link = document.createElement( 'link' );
	link.rel = 'stylesheet';
	link.href = 'https://unpkg.com/spoken-word/css/style.css';
	document.head.appendChild( link );

	const script = document.createElement( 'script' );
	script.src = 'https://unpkg.com/spoken-word/dist/spoken-word.js';
	script.addEventListener( 'load', () => {
		spokenWord.initialize( {
			contentSelector: [ /* 👈 Amend as desired. */
				'.hentry',
				'.entry-content',
				'.h-entry',
				'.e-content',
				'[itemprop="articleBody"]',
			].join( ', ' )
		} );
	} );
	document.head.appendChild( script );
} )();

The spokenWord.initialize() function takes an object as its argument which can have the following properties:

The dialog and the controls are rendered using Preact. For a list of all the modules used by this plugin, see the package.json.

This plugin is developed on GitHub where the source can be viewed. Please report issues there. Pull requests welcome. The spoken-word package is also published on npm.

Screenshots

Words are highlighted (selected) as they are spoken.

Words are highlighted (selected) as they are spoken.

Change the rate, pitch, and voices used in speech.

Change the rate, pitch, and voices used in speech.

Skip ahead to the desired paragraph with controls or via selecting with cursor.

Skip ahead to the desired paragraph with controls or via selecting with cursor.

Changelog

1.0.1 (2018-01-21)

Disable functionality in Android and iOS devices by default.

1.0.0 (2018-01-20)

Initial release.