{"id":1014,"date":"2015-02-21T15:41:44","date_gmt":"2015-02-21T02:41:44","guid":{"rendered":"http:\/\/www.davidbrebner.com\/?p=1014"},"modified":"2015-02-21T15:50:15","modified_gmt":"2015-02-21T02:50:15","slug":"ibm-watson-services-with-umajin","status":"publish","type":"post","link":"https:\/\/davidbrebner.com\/?p=1014","title":{"rendered":"IBM Watson services with Umajin"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/www.davidbrebner.com\/wp-content\/uploads\/2015\/02\/watson.jpg\" alt=\"watson\" width=\"900\" height=\"296\" class=\"alignnone size-full wp-image-1015\" srcset=\"https:\/\/davidbrebner.com\/wp-content\/uploads\/2015\/02\/watson.jpg 900w, https:\/\/davidbrebner.com\/wp-content\/uploads\/2015\/02\/watson-150x49.jpg 150w, https:\/\/davidbrebner.com\/wp-content\/uploads\/2015\/02\/watson-300x99.jpg 300w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>This is a demo of using the IBM Watson image recognition service along with the IBM Watson text to speech service.<\/p>\n<p>When you pick a photo it will classify it and read out the two top matching &#8216;labels&#8217;.<\/p>\n<p><iframe width=\"840\" height=\"520\" src=\"https:\/\/www.youtube.com\/embed\/Z37Do6gq1Xc\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>In this demo we use the demo images already on the Watson servers, but it&#8217;s possible to have your own corpus of images and build your own special purpose image recognition system on top of Watson.<\/p>\n<p>The code posts the URL of the image to the Watson visual recognition system and then when the result is returned it passes the URL of the text to speech service with the text URL encoded to the media player component which will playback the wav file which is generated. <\/p>\n<pre>\r\ngw_text = 0\r\ngw_video = 0\r\n\r\nregister(\"watson_image\",\"Watson Image\",\"string:image url,component:text:text,component:video:video\")\r\nfunction watson_image (img,ctext,cvideo)\r\n\tif img==nil then\r\n\t\t--do nothing\r\n\telse\r\n\t\tgw_text = ctext\r\n\t\tgw_video = cvideo\r\n\t\thttp_post(\"http:\/\/visual-recognition-demo.mybluemix.net\/\",\r\n                 \"classifier=0&url=\"..encode(img,\"url\")..\"&text=&service_request=&service_response=\",\r\n                 \"\",\"watson_success\",\"\")\t\r\n\tend\r\nend\r\n\r\nfunction watson_success(data)\r\n\tlocal result = JSON_:decode(data)\r\n\t--work out the first two names and percentages \r\n        --remove underscores or they will be pronounced and trim percentages to the two primary digits\r\n\tlocal name1 = string.gsub(result.images[1].labels[1].label_name,\"_\",\" \")\r\n\tlocal perc1 = string.sub(tostring(tonumber(result.images[1].labels[1].label_score) * 100),1,2)..\"%\"\r\n\tlocal name2 = string.gsub(result.images[1].labels[2].label_name,\"_\",\" \")\r\n\tlocal perc2 = string.sub(tostring(tonumber(result.images[1].labels[2].label_score) * 100),1,2)..\"%\"\r\n\r\n\t--set the text box\r\n\tlocal recog = name1 .. \" \" .. perc1 .. \"\\n\" .. name2 .. \" \" .. perc2\r\n\tset_property(gw_text,\"text\",recog)\r\n\t\r\n\t--convert the text to speech and playback\r\n\tlocal url = \"http:\/\/text-to-speech-demo.mybluemix.net\/synthesize?text=\"..\r\n                     encode(recog,\"url\") ..\"&voice=VoiceEnUsLisa&accept=audio\/wav\"\r\n\tcall_action(\"play_video\",get_component_uuid(gw_video),url)\r\nend\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is a demo of using the IBM Watson image recognition service along with the IBM Watson text to speech [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[],"class_list":["post-1014","post","type-post","status-publish","format-standard","hentry","category-umaijn"],"_links":{"self":[{"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/posts\/1014","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1014"}],"version-history":[{"count":9,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/posts\/1014\/revisions"}],"predecessor-version":[{"id":1024,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/posts\/1014\/revisions\/1024"}],"wp:attachment":[{"href":"https:\/\/davidbrebner.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}