Created
April 8, 2020 11:29
-
-
Save savelee/954802a2afaf64d6a2b5d637f0a40410 to your computer and use it in GitHub Desktop.
Client - Streaming to Dialogflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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