This is a demo of using the IBM Watson image recognition service along with the IBM Watson text to speech service.
When you pick a photo it will classify it and read out the two top matching ‘labels’.
In this demo we use the demo images already on the Watson servers, but it’s possible to have your own corpus of images and build your own special purpose image recognition system on top of Watson.
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.
gw_text = 0 gw_video = 0 register("watson_image","Watson Image","string:image url,component:text:text,component:video:video") function watson_image (img,ctext,cvideo) if img==nil then --do nothing else gw_text = ctext gw_video = cvideo http_post("http://visual-recognition-demo.mybluemix.net/", "classifier=0&url="..encode(img,"url").."&text=&service_request=&service_response=", "","watson_success","") end end function watson_success(data) local result = JSON_:decode(data) --work out the first two names and percentages --remove underscores or they will be pronounced and trim percentages to the two primary digits local name1 = string.gsub(result.images[1].labels[1].label_name,"_"," ") local perc1 = string.sub(tostring(tonumber(result.images[1].labels[1].label_score) * 100),1,2).."%" local name2 = string.gsub(result.images[1].labels[2].label_name,"_"," ") local perc2 = string.sub(tostring(tonumber(result.images[1].labels[2].label_score) * 100),1,2).."%" --set the text box local recog = name1 .. " " .. perc1 .. "\n" .. name2 .. " " .. perc2 set_property(gw_text,"text",recog) --convert the text to speech and playback local url = "http://text-to-speech-demo.mybluemix.net/synthesize?text=".. encode(recog,"url") .."&voice=VoiceEnUsLisa&accept=audio/wav" call_action("play_video",get_component_uuid(gw_video),url) end