
Product
Announcing Precomputed Reachability Analysis in Socket
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
A React component that synthesis text into speech using Web Speech API
A React component that synthesis text into speech using Web Speech API.
This project scaffold can be found at compulim/react-component-template
.
Try out the demo at https://compulim.github.io/react-say/.
First, run npm install react-say
for production build. Or run npm install react-say@master
for latest development build.
The following will speak the text immediately upon showing up. Some browsers may not speak the text until the user interacted with the page.
import Say from 'react-say';
export default props =>
<Say speak="A quick brown fox jumped over the lazy dogs." />
You may want to customize the speech by varying pitch, rate, and volume. You can use <Composer>
and <Say>
to say your text.
import Say from 'react-say';
export default props =>
<Say
pitch={ 1.1 }
rate={ 1.5 }
speak="A quick brown fox jumped over the lazy dogs."
volume={ .8 }
/>
Note: variation will take effect for new/modified
<Say>
You may want to say something after the user interacted with the page, for example, after clicking on a button. We have built <SayButton>
that speak immediately after clicking on it. Some browsers may requires "priming" with a button.
import { SayButton } from 'react-say';
export default props =>
<SayButton
onClick={ event => console.log(event) }
speak="A quick brown fox jumped over the lazy dogs."
>
Tell me a story
</SayButton>
Instead of passing a SpeechSynthesisVoice
object, you can pass a function (voices: SpeechSynthesisVoice[]) => SpeechSynthesisVoice
to select the voice just before the text is synthesized.
import Say from 'react-say';
export default props =>
<Say
speak="A quick brown fox jumped over the lazy dogs."
voice={ voices => [].find.call(voices, v => v.lang === 'zh-HK') }
/>
Note: it also works with
<SayButton>
.
SpeechSynthesis
You can bring your own window.speechSynthesis
and window.speechSynthesisUtterance
for custom speech synthesis. For example, you can bring Azure Cognitive Services thru web-speech-cognitive-services
package.
import Say from 'react-say';
import { speechSynthesis, SpeechSynthesisUtterance, SubscriptionKey } from 'web-speech-cognitive-services';
// You will need to wait until the speech token has been exchanged
// The part has been omitted for code clarity
speechSynthesis.speechToken = new SubscriptionKey('your subscription key');
export default props =>
<Say
speak="A quick brown fox jumped over the lazy dogs."
speechSynthesis={ speechSynthesis }
speechSynthesisUtterance={ SpeechSynthesisUtterance }
/>
Note:
speechSynthesis
is camel-casing because it is an instance.
<Say>
or <SayButton>
is unmounted, the utterance will continue to speak
Like us? Star us.
Want to make it better? File us an issue.
Don't like something you see? Submit a pull request.
FAQs
A React component that synthesis text into speech using Web Speech API
The npm package react-say receives a total of 4,905 weekly downloads. As such, react-say popularity was classified as popular.
We found that react-say demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.