Last active
October 18, 2022 14:24
-
-
Save sorluc/c5a3c3d5bc892dd550baa96f5d05e825 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/YOUR WHISPEAK APPLICATION ID'; | |
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 + '/enroll'); | |
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\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() == 201) { | |
outcome = "true"; | |
idRepository.setAttribute(sharedState.get("_id"), "fr-attr-istr2", [jsonResultCheckVoice.id]); | |
idRepository.setAttribute(sharedState.get("_id"), "fr-attr-imulti1", ["api_link:"+jsonResultCheckVoice.revocation.api_link,"signature_secret_password:"+jsonResultCheckVoice.revocation.signature_secret_password,"ui_link:"+jsonResultCheckVoice.revocation.ui_link]); | |
} else { | |
nodeState.putShared("errorMessage", "Voice enrollment failed."+jsonResultCheckVoice.id+sharedState.get("_id"));//: "+responseCheckVoice.getEntity().getString()+"!!!"); | |
outcome ="failed"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment