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

speech-paragraph

v0.0.1

Published

A Web Component that enables the native paragraph HTML element to read out its text through Web Speech Synthesis

Downloads

5

Readme

speech-paragraph

A Custom Element that extends the native paragraph HTML element <p> to enable it to read its text out loud using Web SpeechSynthesis.

Usage:

<script type="module" src="/src/speech-paragraph.js"></script>

<p is="speech-paragraph">
  This text will be read out loud.
</p>

In browsers that don't support extending native HTML elements, the element speech-paragraph can be used:

<script type="module" src="/src/speech-paragraph.js"></script>

<speech-paragraph>
  This text will be read out loud.
</speech-paragraph>

A play button will appear in the top-right corner of the paragraph. When pressed, the text of the paragraph will be read out loud and the play button will change into a pause button.

To cancel speaking instead of pausing, click outside the paragraph.

You can also select a portion of text inside the paragraph to play. In that case, the play button will appear at the start of the selection.

Selecting a language

The default language is US English, but you can specify the language with the lang attribute which takes as value a BCP 47 language tag.

For example: en-US or simply en.

<p is="speech-paragraph" lang="en-US">
<speech-paragraph lang="en-US">

Selecting a voice

For every language, the browser provides an array of available voices. A voice from this array can by chosen by specifying its name in the voice attribute.

To get the array of available voices, get a reference to the element and inspect the voices property. The easiest way to do this is to click the element in the Elements panel of your browser's dev tools which will assign it to the special $0 variable:

$0.voices

which will show the array of available voices like this:

0: SpeechSynthesisVoice {voiceURI: 'Alex', name: 'Alex', lang: 'en-US', localService: true, default: true}
1: SpeechSynthesisVoice {voiceURI: 'Fred', name: 'Fred', lang: 'en-US', localService: true, default: false}
2: SpeechSynthesisVoice {voiceURI: 'Samantha', name: 'Samantha', lang: 'en-US', localService: true, default: false}
3: SpeechSynthesisVoice {voiceURI: 'Victoria', name: 'Victoria', lang: 'en-US', localService: true, default: false}
4: SpeechSynthesisVoice {voiceURI: 'Google US English', name: 'Google US English', lang: 'en-US', localService: false, default: false}

A voice is selected by specifying its name property, so to select "Victoria":

<p is="speech-paragraph" lang="en-US" voice="Victoria">
<speech-paragraph lang="en-US" voice="Victoria">

Setting the playback speed

The speech at which the text is spoken can be set with the rate attribute. It accepts a value between 0.5 and 1.5. The default value is 1.

<p is="speech-paragraph" rate="0.8>
<speech-paragraph rate="0.8>

Styling

The component exposes the following CSS custom properties for styling :

  • --button-size: size of the play and pause button. Default: 12px
  • --button-color: color of the play and pause button. Default: #000000
  • --text-highlight-color: background color of selected text inside the element. Default: #ffff00

Demo

To run the demo, run npm install once and then npm start and view the demo at http://localhost:8080