Skip to content

Instantly share code, notes, and snippets.

@WoolDoughnut310
Created August 23, 2022 09:24
Show Gist options
  • Save WoolDoughnut310/5b8387a2ff32ecf6426646f20e8d8e3a to your computer and use it in GitHub Desktop.
Save WoolDoughnut310/5b8387a2ff32ecf6426646f20e8d8e3a to your computer and use it in GitHub Desktop.
// lib/initVoiceRequest.ts
export default function initVoiceRequest(
recorder: any,
conversationState: object,
handlers: RequestHandlers
) {
// @ts-ignore (2339)
const voiceRequest = new window.Houndify.VoiceRequest({
//Your Houndify Client ID
clientId: "{YOUR_CLIENT_ID}",
authURL: "/houndifyAuth",
//REQUEST INFO JSON
//See https://houndify.com/reference/RequestInfo
requestInfo: {
UserID: "test_user",
//See https://www.latlong.net/ for your own coordinates
Latitude: 37.388309,
Longitude: -121.973968,
},
//Pass the current ConversationState stored from previous queries
//See https://www.houndify.com/docs#conversation-state
conversationState,
//Sample rate of input audio
sampleRate: recorder.sampleRate,
//Enable Voice Activity Detection
//Default: true
enableVAD: true,
//Partial transcript, response and error handlers
onTranscriptionUpdate: handlers.onTranscriptionUpdate,
onResponse: function (response: any, info: any) {
recorder.stop();
handlers.onResponse(response, info);
},
onError: function (err: any, info: any) {
recorder.stop();
handlers.onError(err, info);
},
});
return voiceRequest;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment