Created
November 24, 2016 18:39
-
-
Save davrous/00bd669730a8138239795fe86f4cde58 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
analyzeThisImage(url) { | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = () => { | |
if (xhr.readyState == 4 && xhr.status == 200) { | |
var response = document.querySelector('#response'); | |
var reponse = JSON.parse(xhr.response); | |
var resultToSpeak = `With a confidence of ${Math.round(reponse.description.captions[0].confidence * 100)}%, I think it's ${reponse.description.captions[0].text}`; | |
console.log(resultToSpeak); | |
if (!this._useBingTTS || BINGSPEECHKEY === "") { | |
var synUtterance = new SpeechSynthesisUtterance(); | |
synUtterance.text = resultToSpeak; | |
window.speechSynthesis.speak(synUtterance); | |
} | |
else { | |
this._bingTTSclient.synthesize(resultToSpeak); | |
} | |
} | |
}; | |
xhr.onerror = (evt) => { | |
console.log(evt); | |
}; | |
try { | |
xhr.open('POST', 'https://api.projectoxford.ai/vision/v1.0/describe'); | |
xhr.setRequestHeader("Content-Type", "application/json"); | |
xhr.setRequestHeader("Ocp-Apim-Subscription-Key", COMPUTERVISIONKEY); | |
var requestObject = { "url": url }; | |
xhr.send(JSON.stringify(requestObject)); | |
} | |
catch (ex) { | |
console.log(ex); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment