> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Build a voice to text search

> High-level overview over how to build a voice-to-text search with Algolia.

export const Records = () => <Tooltip tip="A record is a searchable object in an Algolia index. Each record consists of named attributes." cta="Algolia records" href="/doc/guides/sending-and-managing-data/prepare-your-data#algolia-records">
    records
  </Tooltip>;

export const Index = () => <Tooltip tip="An Algolia index is a searchable dataset that consists of records and configuration settings. These settings define how the records are searched and ranked.">
    index
  </Tooltip>;

Your app needs three things to build a voice search experience:

* A voice **[input](/doc/guides/solutions/ecommerce/voice-search#input—the-speech-to-text-layer)** using a speech-to-text service
* An **[output](#output)** to display results
* The suggested **[Algolia settings](#algolia-settings)** for optimizing your voice search.

## Sample app

<Card title="View code on GitHub" icon="github" href="https://github.com/algolia/voice-search-widget">
  View the voice to text search example code on GitHub.
</Card>

For more example code, see:

* [Autocomplete with voice search (iOS)](https://github.com/algolia/instantsearch-ios-examples/tree/master/Examples/VoiceSearch)
* [Voice overlay (iOS)](https://github.com/algolia/voice-overlay-ios)
* [Voice overlay (Android)](https://github.com/algolia/voice-overlay-android)

## Input—the speech-to-text layer

Since Algolia only handles text searching, you must convert your user's speech to text.
If you're building on top of a voice assistant like Amazon Alexa, you get built-in speech-to-text support.
This is also the case if you're building iOS or Android native apps or explicitly targeting the Chrome browser. For all other web apps, you'll need an external service. Some options are [Google Cloud Speech to Text](https://cloud.google.com/speech-to-text/), [Azure Cognitive Services](https://azure.microsoft.com/en-us/services/cognitive-services/speech-to-text/), or [AssemblyAI](https://www.assemblyai.com).

You need to send the user's speech to a speech-to-text service, receive the text, and then send that text to Algolia as a search query.
For example, the [sample app](#sample-app) uses Google's Speech-to-text API to interrogate the voice input:

```js JavaScript icon=code theme={"system"}
function startRecognitionStream(io) {
  this.recognizeStream = this.gcpClient
    .streamingRecognize(this.request)
    .on("error", console.error)
    .on("data", data => {
      process.stdout.write(
        data.results[0] && data.results[0].alternatives[0]
          ? `Transcription: ${data.results[0].alternatives[0].transcript}\n`
          : `\n\nReached transcription time limit, press Ctrl+C\n`
      );

      io.emit("dataFromGCP", data.results[0].alternatives[0].transcript);

      //Stop speech recognition wheb user stops talking
      if (data.results[0] && data.results[0].isFinal) {
        io.emit("endSpeechRecognition", {});
      }
    });
  }
```

## Output

You can convert the text you receive from the speech-to-text layer into speech or display them as text (as in the [sample app](#sample-app)).

If you do need text-to-speech support, your choices are:

* **Built-in.** Voice assistants have text-to-speech support. All browsers that implement the [SpeechSynthesis API](https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis) offer support.
* **Third-party.** You can use solutions such as [Azure Cognitive Services](https://azure.microsoft.com/en-us/services/cognitive-services/speech-to-text/), [AWS Polly](https://aws.amazon.com/polly/), or [Google Cloud Text-to-speech](https://cloud.google.com/text-to-speech).

For example, the following code uses the SpeechSynthesis API to announce the titles of search results:

```js JavaScript icon=code theme={"system"}
// The search input
const searchInput = document.querySelector('#search-input');

// The search results
const searchResults = document.querySelector('#search-results');

// Create an Algolia InstantSearch instance
const search = instantsearch({
  appId: 'ALGOLIA_APPLICATION_ID',
  apiKey: 'ALGOLIA_SEARCH_API_KEY',
  // Replace with the name of the index you want to search
  indexName: 'YourIndexName',
  // Bind the search input to the InstantSearch instance
  searchParameters: {
    query: searchInput.value
  }
});

// Initialize the search
search.start();

// Listen for search results
search.on('render', () => {
  // Get the title of search results
  const titles = searchResults
    .querySelectorAll('.Hits-item')
    .map(item => item.querySelector('.title').textContent);

  // Speak the titles using the speechSynthesis API
  titles.forEach(title => {
    const msg = new SpeechSynthesisUtterance(title);
    window.speechSynthesis.speak(msg);
  });
});
```

Customize this code to fit your specific needs.
For example, you could add a button to control when the titles are spoken,
or change the output to include information from other attributes.

## Algolia settings

* Set [`removeStopWords`](/doc/api-reference/api-parameters/removeStopWords) to `true` or the appropriate language code (for example, `en`). This will remove words like "a," "an," or "the" that don't add value to the query.
* Set [`ignorePlurals`](/doc/api-reference/api-parameters/ignorePlurals) to `true` or the appropriate language code. This makes words like "car" and "cars" equivalent.
* Send the entire query string as [`optionalWords`](/doc/api-reference/api-parameters/optionalWords). When searching conversationally, searchers might use words that aren't in your <Index />. Making all words optional means that <Records /> don't need to match every word, but records matching more words will rank higher.
* Use [`analyticsTags`](/doc/api-reference/api-parameters/analyticsTags) if you want to identify a search as being voice-driven

<Note>
  As an alternative to setting `removeStopWords` and `ignorePlurals` individually,
  you can use the [`naturalLanguages`](/doc/api-reference/api-parameters/naturalLanguages) parameter to set both these behaviors in one call.
</Note>

## Add dynamic filters with Rules

To help users refine their search to find more relevant results, consider [adding rules to apply filters based on what they say](/doc/guides/managing-results/rules/detecting-intent/how-to/applying-a-filter-if-the-query-match-a-facet-value).

## See also

* [`voiceSearch` (InstantSearch.js)](/doc/api-reference/widgets/voice-search/js)
* [`voiceSearch` (React InstantSearch )](/doc/api-reference/widgets/voice-search/react)
* [`voiceSearch` (Vue InstantSearch)](/doc/api-reference/widgets/voice-search/vue)
* [Voice search with InstantSearch Android](/doc/guides/building-search-ui/ui-and-ux-patterns/voice-search/android)
* [Voice search with InstantSearch iOS](/doc/guides/building-search-ui/ui-and-ux-patterns/voice-search/ios)
