IBM Watson is a cognitive computing platform that you can use to add intelligence and natural language analysis to your own applications. Watson employs natural language processing, hypothesis generation, and dynamic learning to deliver solutions for natural language question and answer services, sentiment analysis, relationship extration, concept expansion, and language/translation services. ..and, it is available for you to check out with IBM Bluemix cloud services.
Watson won Jeopardy, tackles genetics, creates recipes, and so much more. It is breaking new ground on a daily basis.
The IBM Watson™ Question Answer (QA) service provides an API that give you the power of the IBM Watson cognitive computing system. With this service, you can connect to Watson, pose questions in natural language, and receive responses that you can use within your application.
In this post, I’ve hooked the Watson QA node.js starter project to the Web Speech API speech recognition and speech synthesis APIs. Using these APIs, you can now have a conversation with Watson. Ask any question about healthcare, and see what watson has to say. Check out the video below to see it in action.
You can check out a live demo at:
Just click on the microphone button, allow access to the system mic, and start talking. Just a warning, lots of background noise might interfere with the API’s ability to recognize & generate a meaningful transcript.
This demo only supports Google Chrome only at the time of writing. You can check out where Web Speech is supported at caniuse.com.
You can check out the full source code for this sample on IBM Jazz Hub (git):
I basically just took the Watson QA Sample Application for Node.js and started playing around with it to see what I could do…
This demo uses the Watson For Healthcare data set, which contains information from HealthFinder.gov, the CDC, National Hear Lung, and Blood Institute, National Institute of Arthritis and Musculoskeletal and Skin Diseases, National Institute of Diabetes and Digestive and Kidney Diseases, National Institute of Neurological Disorders and Stroke, and Cancer.gov. Just know that this is a beta service/data set – implementing Watson for your own enterprise solutions requires system training and algorithm development for Watson to be able to understand your data.
Using Watson with this dataset, you can ask conditional questions, like:
- What is X?
- What causes X?
- What is the treatment for X?
- What are the symptoms of X?
- Am I at risk of X?
Procedure questions, like:
- What should I expect before X?
- What should I expect after X?
General health auestions, like:
- What are the benefits of taking aspirin daily?
- Why do I need to get shots?
- How do I know if I have food poisoning?
Or, action-related questions, like:
- How can I quit smoking?
- What should I do if my child is obese?
- What can I do to get more calcium?
Watson services are exposed through a RESTful API, and can easily be integrated into an existing application. For example, here’s a snippet demonstrating how you can consume the Watson QA service inside of a Node.js app:
[js]var parts = url.parse(service_url +’/v1/question/healthcare’);
var options = {
host: parts.hostname,
port: parts.port,
path: parts.pathname,
method: ‘POST’,
headers: {
‘Content-Type’ :’application/json’,
‘Accept’:’application/json’,
‘X-synctimeout’ : ’30’,
‘Authorization’ : auth
}
};
// Create a request to POST to Watson
var watson_req = https.request(options, function(result) {
result.setEncoding(‘utf-8’);
var response_string = ”;
result.on(‘data’, function(chunk) {
response_string += chunk;
});
result.on(‘end’, function() {
var answers = JSON.parse(response_string)[0];
var response = extend({ ‘answers’: answers },req.body);
return res.render(‘response’, response);
});
});[/js]
Hooking into the Web Speech API is just as easy (assuming you’re using a browser that implements the Web Speech API – I built this demo using Chrome on OS X). On the client side, you just need need to create a SpeechRecognition instance, and add the appropriate event handlers.
[js]var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = true;
recognition.onstart = function() { … }
recognition.onresult = function(event) {
var result = event.results[event.results.length-1];
var transcript = result[0].transcript;
// then do something with the transcript
search( transcript );
};
recognition.onerror = function(event) { … }
recognition.onend = function() { … }[/js]
To make your app talk back to you (synthesize speech), you just need to create a new SpeechSynthesisUtterance object, and pass it into the window.speechSynthesis.speak() function. You can add event listeners to handle speech events, if needed.
[js]var msg = new SpeechSynthesisUtterance( tokens[i] );
msg.onstart = function (event) {
console.log(‘started speaking’);
};
msg.onend = function (event) {
console.log(‘stopped speaking’);
};
window.speechSynthesis.speak(msg);[/js]
Check out these articles on HTML5Rocks.com for more detail on Speech Recognition and Speech Synthesis.
Here are those links again…
- Live interactive application (requires Chrome): https://watsonhealthqa.mybluemix.net/
- Full source: https://hub.jazz.net/project/andrewtrice/WatsonHealthQA-SpeechAPI/overview
You can get started with Watson services for Bluemix at https://console.ng.bluemix.net/#/store/cloudOEPaneId=store