Skip to content

Instantly share code, notes, and snippets.

@cbattlegear
Created October 15, 2019 18:14
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 cbattlegear/ee805737a7c5d49d1f94c24982e877d2 to your computer and use it in GitHub Desktop.
Save cbattlegear/ee805737a7c5d49d1f94c24982e877d2 to your computer and use it in GitHub Desktop.
function _HeyMisty(data) {
misty.PlayAudio("s_PhraseHello.wav");
//Record Voice Command
misty.StartRecordingAudio("VoiceCommand.wav");
misty.Pause(3000);
misty.StopRecordingAudio();
misty.Pause(1000);
//Check if Exists
misty.GetAudioList();
_registerHeyMistyInteraction();
}
//Callback function to check if voice command happened
function _GetAudioList(data) {
let containsNewFile = false;
var audioArr = data.Result;
for (let i = 0; i < audioArr.length; i++) {
if (audioArr[i].Name === "VoiceCommand.wav") {
containsNewFile = true;
}
}
if (containsNewFile) {
misty.GetAudioFile("VoiceCommand.wav", "_ProcessVoiceCommand");
misty.PlayAudio("VoiceCommand.wav", 100, 500);
}
else {
misty.Debug("file was not found");
}
}
//Use Base64 of wav to send to Azure Function
function _ProcessVoiceCommand(data) {
var voicecommand = data.Result;
var sound = {"SoundData": voicecommand.Base64};
misty.SendExternalRequest("POST", "http://url/api/IntentDetection", null, null, JSON.stringify(sound), "true", "true", "responsevoice.wav", "audio/x-wav");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment