Skip to content

Instantly share code, notes, and snippets.

@savelee
Created April 8, 2020 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save savelee/954802a2afaf64d6a2b5d637f0a40410 to your computer and use it in GitHub Desktop.
Save savelee/954802a2afaf64d6a2b5d637f0a40410 to your computer and use it in GitHub Desktop.
Client - Streaming to Dialogflow
// 1)
stopRecording.onclick = function() {
// recording stopped
startRecording.disabled = false;
stopRecording.disabled = true;
// stop audio recorder
recordAudio.stopRecording(function() {
// after stopping the audio, get the audio data
recordAudio.getDataURL(function(audioDataURL) {
//2)
var files = {
audio: {
type: recordAudio.getBlob().type || 'audio/wav',
dataURL: audioDataURL
}
};
// submit the audio file to the server
socketio.emit('message', files);
});
});
};
// 3)
// when the server found results send
// it back to the client
const resultpreview = document.getElementById('results');
socketio.on('results', function (data) {
console.log(data);
// show the results on the screen
if(data[0].queryResult){
resultpreview.innerHTML += "" + data[0].queryResult.fulfillmentText;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment