Setup Voice Search
Learn how to setup voice search with Trieve
Overview
Trieve provides a simple way to integrate voice search into your application. This guide will walk you through the steps to set up voice search with Trieve.
For a full implementation example, take a look at the way we implement voice search in our search component.
Capturing Audio from the Microphone
To enable voice search, you’ll need to capture audio from the user’s microphone using the browser’s MediaRecorder
API.
1. Create a Voice Search Button
The following React component lets users start and stop voice recording:
Converting Audio to Base64
To send the recorded audio to Trieve, convert the audio blob into a base64 string.
Sending Audio to Trieve for Search
Once the audio is recorded and converted to base64, send it to Trieve. The platform will transcribe the speech using OpenAI Whisper and return the search results based on the transcription.
We return the transcribed text in the response header as x-tr-query
, which can be used to update the UI with the search query.
1. Handle Voice Search
Best Practices
Optimize Performance
- Keep recordings under 30 seconds to improve speed and accuracy.
- Use high-quality microphones for clearer transcription results.
Ensure Browser Compatibility
Different browsers support different audio formats. Handle this by selecting the correct MIME type:
Was this page helpful?