Stream Audio
After you have created an Audio Query, you can start streaming data.
You create a new conversation by calling streamAudio
on VoysisSession.
Assuming the user can given permissions for the website to access their microphone, the JavaScript library will automatically start streaming audio from the user's microphone to your Voysis endpoint.
The library will automatically detect when the user has stopped speaking, and stop streaming audio.
The streamAudio
method takes 2 parameters:
audioQueryResponse
: (optional) The response fromcreateAudioQuery
vadStopCallback
: (optional) A callback which will be triggered when we have detected that the user has stopped speaking.
When the query has been processed, the query result will be sent to your callback:
voysisSession.streamAudio().then(function (queryResults) {
console.log('The results to the query were: ' + queryResults);
}).catch(function (error) {
console.log('Problem streaming audio: ' + JSON.stringify(error));
});
The object passed to the callback will be the results of the query.
See Query Responses for details on the structure and meaning of the fields in the query response.
Below is an example response:
{
"id": "8a145526-9044-4218-9b6e-066cfef95e79",
"locale": "en-US",
"conversationId": "986e79de-6f4e-49dc-a128-41ff41661f3d",
"queryType": "audio",
"textQuery": {
"text": "show me red men's sneakers"
},
"audioQuery": {
"mimeType": "audio/pcm;bits=16;rate=16000"
},
"context": {
"attributes": {
"color": [
"red"
],
"gender": [
"men"
]
},
"keywords": [
"sneakers"
],
"price": {},
"sortBy": ""
},
"intent": "newSearch",
"reply": {
"text": "Here's what I found"
},
"entities": {
"products": []
},
"_links": {
"self": {
"href": "/queries/8a145526-9044-4218-9b6e-066cfef95e79"
},
"audio": {
"href": "/queries/8a145526-9044-4218-9b6e-066cfef95e79/audio"
}
},
"_embedded": {}
}
Updated about 7 years ago