
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
react-voice-handler
Advanced tools
A lightweight React hook for voice commands using the Web Speech API with multi-language support and error handling.
React Voice Handler is a lightweight custom hook for recognizing voice commands using the Web Speech API in React applications. It allows you to trigger actions based on voice input, making your applications more interactive.
webkitSpeechRecognition fallback).LangEnum.To install this package in your project, run the following command:
npm install react-voice-handler
Here’s an example of how to use useVoiceCommands in your React application:
import React from 'react';
import { useVoiceCommands, LangEnum } from 'react-voice-handler';
const App: React.FC = () => {
const commands = [
{ command: 'hello', action: () => alert('Hello there!') },
{ command: '안녕하세요', action: () => alert('hello') },
{ command: 'goodbye', action: () => alert('Goodbye!') },
];
const { startRecognition, stopRecognition } = useVoiceCommands(commands, { continuous: true, lang: LangEnum.EnglishUS });
return (
<div>
<h1>Voice Command App</h1>
<button onClick={startRecognition}>Start Listening</button>
<button onClick={stopRecognition}>Stop Listening</button>
</div>
);
};
export default App;
The useVoiceCommands hook supports a wide range of languages and dialects through the LangEnum. By default, it uses LangEnum.EnglishUS, but you can customize the language by passing the lang option in the configuration object.
For example, to use Spanish (Spain):
const { startRecognition, stopRecognition } = useVoiceCommands(commands, { lang: LangEnum.SpanishSpain });
Here are some of the available languages in the LangEnum:
LangEnum.EnglishUSLangEnum.EnglishUKLangEnum.SpanishSpainLangEnum.FrenchFranceLangEnum.GermanGermanyLangEnum.ChineseSimplifiedLangEnum.JapaneseJapanLangEnum.RussianRussiaContinuous Mode allows the voice recognition to keep listening after recognizing a command. Use this mode if you expect multiple commands over time without manually restarting the recognition.
const { startRecognition, stopRecognition } = useVoiceCommands(commands, { continuous: true });
Non-Continuous Mode stops the voice recognition after recognizing a command. Use this mode if you only expect a single command and want to manually restart recognition.
const { startRecognition, stopRecognition } = useVoiceCommands(commands, { continuous: false });
The hook accepts the following parameters:
commands: An array of objects where each object contains a command string and an action function. Example:
const commands = [
{ command: 'hello', action: () => alert('Hello there!') },
{ command: '안녕하세요', action: () => alert('hello') },
{ command: 'goodbye', action: () => alert('Goodbye!') },
];
continuous (optional): A boolean indicating if the recognition should continue after recognizing a command. Default is false.
lang (optional): A language variant from the LangEnum enum. Example: LangEnum.EnglishUS. Default is LangEnum.EnglishUS.
The hook allows error handling by passing a custom onError function in the options. For example:
const handleError = (error) => { console.error('Speech recognition error:', error); };
const { startRecognition, stopRecognition } = useVoiceCommands(commands, { onError: handleError });
FAQs
A lightweight React hook for voice commands using the Web Speech API with multi-language support and error handling.
We found that react-voice-handler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.