Skip to content

Commit

Permalink
Merge pull request #152 from tombohub/patch-1
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
JamesBrill committed Apr 14, 2024
2 parents 6b28cf1 + 96ac055 commit 303cc7d
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To import in your React code:

The most basic example of a component using this hook would be:

```
```javascript
import React from 'react';
import SpeechRecognition, { useSpeechRecognition } from 'react-speech-recognition';

Expand Down Expand Up @@ -103,7 +103,7 @@ You can find the full guide for setting up a polyfill [here](docs/POLYFILLS.md).
* Install `@speechly/speech-recognition-polyfill` in your web app
* You will need a Speechly app ID. To get one of these, sign up for free with Speechly and follow [the guide here](https://docs.speechly.com/quick-start/stt-only/)
* Here's a component for a push-to-talk button. The basic example above would also work fine.
```
```javascript
import React from 'react';
import { createSpeechlySpeechRecognition } from '@speechly/speech-recognition-polyfill';
import SpeechRecognition, { useSpeechRecognition } from 'react-speech-recognition';
Expand Down Expand Up @@ -144,7 +144,7 @@ export default Dictaphone;

If you choose not to use a polyfill, this library still fails gracefully on browsers that don't support speech recognition. It is recommended that you render some fallback content if it is not supported by the user's browser:

```
```javascript
if (!browserSupportsSpeechRecognition) {
// Render some fallback content
}
Expand All @@ -167,7 +167,7 @@ For all other browsers, you can render fallback content using the `SpeechRecogni

Even if the browser supports the Web Speech API, the user still has to give permission for their microphone to be used before transcription can begin. They are asked for permission when `react-speech-recognition` first tries to start listening. At this point, you can detect when the user denies access via the `isMicrophoneAvailable` state. When this becomes `false`, it's advised that you disable voice-driven features and indicate that microphone access is needed for them to work.

```
```javascript
if (!isMicrophoneAvailable) {
// Render some fallback content
}
Expand All @@ -181,7 +181,7 @@ Before consuming the transcript, you should be familiar with `SpeechRecognition`
To start listening to speech, call the `startListening` function.
```
```javascript
SpeechRecognition.startListening()
```
Expand All @@ -191,29 +191,29 @@ This is an asynchronous function, so it will need to be awaited if you want to d
To turn the microphone off, but still finish processing any speech in progress, call `stopListening`.
```
```javascript
SpeechRecognition.stopListening()
```
To turn the microphone off, and cancel the processing of any speech in progress, call `abortListening`.
```
```javascript
SpeechRecognition.abortListening()
```
## Consuming the microphone transcript
To make the microphone transcript available in your component, simply add:
```
```javascript
const { transcript } = useSpeechRecognition()
```
## Resetting the microphone transcript
To set the transcript to an empty string, you can call the `resetTranscript` function provided by `useSpeechRecognition`. Note that this is local to your component and does not affect any other components using Speech Recognition.
```
```javascript
const { resetTranscript } = useSpeechRecognition()
```
Expand Down Expand Up @@ -248,7 +248,7 @@ To make commands easier to write, the following symbols are supported:
### Example with commands
```
```javascript
import React, { useState } from 'react'
import SpeechRecognition, { useSpeechRecognition } from 'react-speech-recognition'

Expand Down Expand Up @@ -318,13 +318,13 @@ By default, the microphone will stop listening when the user stops speaking. Thi
If you want to listen continuously, set the `continuous` property to `true` when calling `startListening`. The microphone will continue to listen, even after the user has stopped speaking.
```
```javascript
SpeechRecognition.startListening({ continuous: true })
```
Be warned that not all browsers have good support for continuous listening. Chrome on Android in particular constantly restarts the microphone, leading to a frustrating and noisy (from the beeping) experience. To avoid enabling continuous listening on these browsers, you can make use of the `browserSupportsContinuousListening` state from `useSpeechRecognition` to detect support for this feature.
```
```javascript
if (browserSupportsContinuousListening) {
SpeechRecognition.startListening({ continuous: true })
} else {
Expand All @@ -338,7 +338,7 @@ Alternatively, you can try one of the [polyfills](docs/POLYFILLS.md) to enable c
To listen for a specific language, you can pass a language tag (e.g. `'zh-CN'` for Chinese) when calling `startListening`. See [here](docs/API.md#language-string) for a list of supported languages.
```
```javascript
SpeechRecognition.startListening({ language: 'zh-CN' })
```
Expand Down

0 comments on commit 303cc7d

Please sign in to comment.