Const
import { useNostoAppState, useSpeechToText, speechToTextSupported } from "@nosto/search-js/preact/hooks"
export default function MyComponent() {
const { newSearch } = useActions()
const { startListening, stopListening, listening } = useSpeechToText({
onResult: query => newSearch({ query }),
onError: error => console.error("Speech recognition error:", error)
})
if (!speechToTextSupported) {
return null
}
return (
<button
onClick={() => {
if (listening) {
stopListening()
} else {
startListening()
}
}}
>
🎤︎︎
</button>
)
}
Preact hook that provides speech-to-text functionality using the Web Speech API.