
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
speech2textjs
Advanced tools
Speech2TextJs is a lightweight and flexible library for developers looking to integrate speech-to-text functionality into their projects. It uses modern speech recognition technologies to provide accurate transcriptions of spoken language. Whether you're
Speech2text is a simple React hook for converting speech into text in real time. It uses the Web Speech API (webkitSpeechRecognition) to provide speech recognition functionality, allowing you to integrate voice-to-text in your React applications with minimal effort.
npm install speech2textjs
Basic Setup You can use the useSpeechToText hook to start listening and convert speech into text. Here's an example of how to use it in your React component:
import React, { useState } from 'react';
import { Button } from 'your-ui-library'; // Customize as per your UI library
import { Mic } from 'lucide-react'; // Optional, use for icon
import useSpeechToText from 'speech2text'; // Import the hook
function RecordAnswerSection() {
const [userAnswer, setUserAnswer] = useState("");
const { isListening, transcript, startListening, stopListening } = useSpeechToText({ continuous: true });
const startStopListening = () => {
if (isListening) {
stopVoiceInput();
} else {
startListening();
}
};
const stopVoiceInput = () => {
setUserAnswer(prev => prev + " " + transcript);
stopListening();
};
useEffect(() => {
if (isListening) {
const newText = transcript.replace(previousTranscript.current, "").trim();
if (newText) {
setUserAnswer(prev => prev + (newText ? " " + newText : ""));
previousTranscript.current = transcript;
}
}
}, [transcript, isListening]);
return (
<div>
<Button className="my-10" onClick={startStopListening}>
{isListening ? <h2><Mic /> Recording...</h2> : "Record Answer"}
</Button>
<Button onClick={() => { console.log(userAnswer); }}>
Show Recorded Answer
</Button>
<h2>{userAnswer}</h2>
<textarea
disabled={isListening}
value={userAnswer}
onChange={(e) => { setUserAnswer(e.target.value); }}
/>
</div>
);
}
export default RecordAnswerSection;
Example with Custom Options You can customize the options when using the hook, like so:
const { isListening, transcript, startListening, stopListening } = useSpeechToText({
continuous: true,
interimResults: true,
lang: 'en-GB',
});
FAQs
Speech2TextJs is a lightweight and flexible library for developers looking to integrate speech-to-text functionality into their projects. It uses modern speech recognition technologies to provide accurate transcriptions of spoken language. Whether you're
We found that speech2textjs demonstrated a healthy version release cadence and project activity because the last version was released less than 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
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.