-
Add
setResultsto hook return values in order to have more control of manually setting the results state array. Thanks to https://github.com/marharyta for the suggestion #12 -
Fixed bug where
handleRecordingTimeoutwould not be cleared when repeatedly callingstartSpeechToTextcausing recording to stop unexpectedly -
Remove
setIsRecording(false)fromspeechEvents.on('stopped_speaking')event logic in order to have more consistent functionality between both WebSpeechAPI and cross-browser google cloud platforms.-
Previously
setIsRecording(false)was being called here because technically the microphone stops recording whenstopRecordingis invoked insrc/Hooks/indexline 236 until the google cloud API promise gets resolved. However, this is not the case when using the Chrome WebSpeechAPI as the WebSpeechAPI continues recording microphone andsetIsRecording(false)is only called on therecognition.onendevent. -
This could be a potential breaking change if previous code was expecting the
isRecordingboolean to change during the few hundred milliseconds it takes for the google cloud API promise to resolve
-
-
Update
package.jsonpeerDependenciesofreactandreact-domfrom^16.8.0to>=16.8.0to potentially fix issues using latest versions of react. Thanks to https://github.com/abhi8233 for reporting #13
- Add new
useLegacyResultshook arg to opt into new array of objects results - Add new array of objects results containing timestamp, transcript and speechBlob properties for each speech result
- Add default
timeoutvalue of 10000 - Add default
speechRecognitionPropertiesvalue of{ interimResults: true }for displaying realtime speech to text result
It is recommended to opt into new results by passing useLegacyResults: false as the legacy array of string results will be completely removed in a future version
- Added functionality to return real-time speech result while speaking for
SpeechRecognitionweb API
Hook now returns an interimResult variable which is a string and will be updated as you speak if opting in using the speech recognition properties config of speechRecognitionProperties: { interimResults: true }
ex:
const {
error,
isRecording,
results,
startSpeechToText,
stopSpeechToText,
interimResult
} = useSpeechToText({
continuous: true,
crossBrowser: true,
googleApiKey: process.env.REACT_APP_API_KEY,
timeout: 10000,
speechRecognitionProperties: { interimResults: true }
});
return (
<ul>
{results.map((result, index) => (
<li key={index}>{result}</li>
))}
{interimResult && <li>{interimResult}</li>}
</ul>
)- When SpeechRecognition result event returns
isFinal, theinterimResultvalue will be set toundefined, this allows you to conditionally display the real-time interimResult while speech is in progress, then display the final result from the results array once result is final
