Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@untemps/react-vocal

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@untemps/react-vocal

React component to initiate a SpeechRecognition session

  • 1.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
54
decreased by-55%
Maintainers
1
Weekly downloads
 
Created
Source

react-vocal

Vocal

A React component to initiate a SpeechRecognition session

npm GitHub Workflow Status Codecov

Disclaimer

The Web Speech API is supported by Chrome only so far. On other browsers, the Vocal component won't display anything.

Installation

yarn add @untemps/react-vocal

Usage

Import the Vocal component:

import Vocal from '@untemps/react-vocal'

Instantiate it:

const App = () => {
	const [result, setResult] = useState('')

	const _onVocalStart = () => {
		setResult('')
	}

	const _onVocalResult = (result) => {
		setResult(result)
	}

	return (
		<div className="App">
			<span style={{ position: 'relative' }}>
				<Vocal
					onStart={_onVocalStart}
					onResult={_onVocalResult}
					style={{ width: 16, position: 'absolute', right: 10, top: -2 }}
				/>
				<input defaultValue={result} style={{ width: 300, height: 40 }} />
			</span>
		</div>
	)
}

By default, Vocal displays an icon with two states (idle/listening):

Idle icon Listening icon

But you can provide your own component:

const App = () => {
	const [isListening, setIsListening] = useState('')

	const _onSpeechStart = () => {
		setIsListening(true)
	}

	const _onSpeechEnd = () => {
		setIsListening(false)
	}

	return (
		<Vocal onSpeechStart={_onSpeechStart} onSpeechEnd={_onSpeechEnd}>
			{isListening ? 'Waiting for vocal' : <button>Click to speech</button>}
		</Vocal>
	)
}

The component passed as children must respect the following constraints:

  • Be a single valid element. Neither array of elements nor string.
  • Accept a onClick handler used to trigger the recognition session. If the component provides its own onClick callback, it will be overridden by the Vocal component implementation.

API

PropsTypeDefaultDescription
timeoutnumber3000Defines the time in ms to wait before discarding the recognition
styleobjectnullDefines the styles of the default element if className is not specified
classNamestringnullDefines the class of the default element
onStartfuncnullDefines the handler called when the recognition starts
onEndfuncnullDefines the handler called when the recognition ends
onSpeechStartfuncnullDefines the handler called when the speech starts
onSpeechEndfuncnullDefines the handler called when the speech ends
onResultfuncnullDefines the handler called when a result is recognized
onErrorfuncnullDefines the handler called when an error occurs
onNoMatchfuncnullDefines the handler called when no result can be recognized

Todos

  • Rewrite with TypeScript
  • Expose SpeechRecognition properties via props
  • Add a connector management to plug external speech-to-text services in

Keywords

FAQs

Package last updated on 13 Jul 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc