Signature
Import
About this widget
ThevoiceSearch
widget lets users perform a voice-based query.
It uses the Web Speech API,
which only Chrome (from version 25) has implemented so far.
This means the voiceSearch
widget only works on desktop Chrome and Android Chrome.
It doesn’t work on iOS Chrome, which uses the iOS WebKit.
Examples
JavaScript
Options
The CSS Selector or
HTMLElement
to insert the widget into.Whether to trigger the search as you speak.
If
false
, search is triggered only after speech is finished.
If true
, search is triggered whenever the engine delivers an interim transcript.JavaScript
The language you want your
voiceSearch
widget to recognize.
The default (all languages
) can result in false positives.
For example, an English word you pronounce might be recognized as a French word,
which can cause irrelevant results.
Make sure to give a BCP 47 language tag,
like en-US
or fr-FR
.
This language is automatically forwarded to the queryLanguages
query parameter.JavaScript
A function that receives the current query and returns the list of search parameters you want to enable for voice search.By default, the following query parameters are set:
ignorePlurals
totrue
removeStopWords
totrue
optionalWords
to the current query
additionalQueryParameters
.JavaScript
The CSS classes you can override:
root
. The root element of the widget.button
. The button element.status
. The status element.
JavaScript
Templates
You can customize parts of a widget’s UI using the Templates API. Each template includes anhtml
function,
which you can use as a tagged template.
This function safely renders templates as HTML strings and works directly in the browser—no build step required.
For details, see Templating your UI.
The
html
function is available in InstantSearch.js version 4.46.0 or later.The template used for displaying the button.
The template used for displaying the status.
HTML output
HTML
Customize the UI with connectVoiceSearch
If you want to create your own UI of the voiceSearch
widget, you can use connectors.
To use connectVoiceSearch
, you can import it with the declaration relevant to how you installed InstantSearch.js.
JavaScript
Create a render function
This rendering function is called before the first search (init
lifecycle step)
and each time results come back from Algolia (render
lifecycle step).
JavaScript
Render options
true
if user’s browser supports voice search.JavaScript
Starts listening to user’s speech, or stops it if already listening.
JavaScript
true
if listening to user’s speech.JavaScript
An object containing the following states regarding speech recognition:
status: string
. Current status (initial
|askingPermission
|waiting
|recognizing
|finished
|error
).transcript: string
. Currently recognized transcript.isSpeechFinal: boolean
.true
if speech recognition is finished.errorCode: string | undefined
. An error code (if any). Refer to the spec for more information.
JavaScript
All original widget options forwarded to the render function.
JavaScript
Create and instantiate the custom widget
First, create your custom widgets using a rendering function. Then, instantiate them with parameters. There are two kinds of parameters you can pass:- Instance parameters. Predefined options that configure Algolia’s behavior.
- Custom parameters. Parameters you define to make the widget reusable and adaptable.
renderFunction
, both instance and custom parameters are accessible through connector.widgetParams
.
JavaScript
Instance options
Whether to trigger the search as you speak.
If
false
, search is triggered only after speech is finished.
If true
, search is triggered as many times as the engine delivers an interim transcript.JavaScript
The language you want your
voiceSearch
widget to recognize.
The default (all languages
) can result in false positives.
For example, an English word you pronounce might be recognized as a French word,
which can cause irrelevant results.
Make sure to give a BCP 47 language tag,
like en-US
or fr-FR
.
This language is automatically forwarded to the queryLanguages
query parameter.JavaScript
A function that receives the current query and returns the list of search parameters you want to enable for voice search.By default, the following query parameters are set:
ignorePlurals
totrue
removeStopWords
totrue
optionalWords
to the current query
additionalQueryParameters
.JavaScript