Last active
October 18, 2022 14:22
-
-
Save sorluc/a7223905140d719c1b74b95eb7eb7860 to your computer and use it in GitHub Desktop.
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
var myCustomer = 'YOUR CUSTOMER NAME AT WHISPEAK'; | |
var myApplication = 'with-asr/YOU WHISPEAK APPLICATION ID'; | |
var id = idRepository.getAttribute(sharedState.get("_id"), "fr-attr-istr2").iterator().next(); | |
var token, text; | |
var result = sharedState.get("voiceRecordedBlob").slice("data:audio/wav;base64,".length); | |
var decodedString = java.lang.String(org.forgerock.util.encode.Base64.decode(result),"ISO-8859-1"); | |
var requestCheckVoice = new org.forgerock.http.protocol.Request(); | |
var boundary = java.lang.String('----WebKitFormBoundary' + (new Date()).getTime()); | |
requestCheckVoice.setMethod('POST'); | |
requestCheckVoice.setUri('https://' + myCustomer + '.whispeak.io/v1/apps/' + myApplication + '/auth'); | |
requestCheckVoice.getHeaders().add("Authorization","Bearer " + sharedState.get("voiceRecordedtoken")); | |
requestCheckVoice.getHeaders().add("Content-Type","multipart/form-data; boundary=" + boundary); | |
var rq = String('--' + boundary + '\r\nContent-Disposition:form-data;name="file";filename="file.wav"\r\nContent-Type:audio/wav\r\n\r\n' + | |
decodedString + | |
'\r\n--' + boundary + '\r\nContent-Disposition:form-data;name="id"\r\n\r\n' + | |
id + | |
'\r\n--' + boundary + '--\r\n'); | |
requestCheckVoice.getEntity().setString(rq); | |
var responseCheckVoice = httpClient.send(requestCheckVoice).get(); | |
var responseCheckVoiceStatus = responseCheckVoice.getStatus(); | |
var jsonResultCheckVoice = JSON.parse(responseCheckVoice.getEntity().getString()) | |
if (responseCheckVoiceStatus.getCode() == 200) { | |
outcome = "true"; | |
logger.error("-------------------------------------------> JSON result.details: " + jsonResultCheckVoice.details); | |
logger.error("-------------------------------------------> JSON result.asserts[0].value: " + jsonResultCheckVoice.asserts[0].value); | |
logger.error("-------------------------------------------> JSON result.asserts[1].value: " + jsonResultCheckVoice.asserts[1].value); | |
} else if (responseCheckVoiceStatus.getCode() == 404 || responseCheckVoiceStatus.getCode() == 400){ | |
nodeState.putShared("errorMessage", "Signature not found."); | |
outcome ="unregistered"; | |
} else { | |
nodeState.putShared("errorMessage", "Voice recognition failed.");//: "+responseCheckVoice.getEntity().getString()+"!!!"); | |
outcome ="failed"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment