What ? Can I watch Taxi Driver movie on IBMi via Netflix ?
No, but using only RPG and SQL UDF HTTPGETBLOB now you can call an IBM Watson API and transform a generic text (in different languages) in a wav/flac file and play it with a simple STRPCCMD.
Let’s start from the beginning.
I have always been fashinated by IBM Watson and machine learning so, when I see something about IBMi and IBM Watson I have to understand and try.
Some days ago I found an interesting Paul Tuohy’s post (RPG Talk to Watson ) and immediately I downloaded source code and test it on my IBMi … Awsome !, I can translate from different languages a text or a document only with a simple procedure and SQL.
But what IBM Watson can offer to me ? Reading Watson Services page we can find some other interesting services, someone free other for a fee :
- Document Conversion to convert PDF, Word, HTML into HTML, Plain Text or JSON Answer Unit, very interesting
- Speech to Text or Text to Speech
- Visual Recognition to understand content of images ..
We can start with something simple … from text to speech, only with RPG, SQL and a PC to play sounds.
Let’s we dig into the code to understand this simple program:
1 – Blob_file SQL Type : is a kind of variables to store a documents or a files (Blob type) but automatically save date in an IFS file : when you declare a xxx variable as a Blob_File SQL type you can use xxx_Name variable for Path & File name on IFS where content of the variable will be stored. You can choose also if Overwrite or not this IFS file with xxx_FO variable
dcl-s FileWave SQLType(BLOB_FILE); FileWave_Name=%trim(MyIFSPath)+%trim(FileName); FileWave_NL=%Len(%TrimR(FileWave_Name)); FileWave_FO=SQFOVR; // Overwrite
2 – Urlencode : when you deal with URLs you must remember to UrlEncode strings of text, here we use another good SQL UDF:
exec SQL values trim(systools.urlencode(:str1, '')) into :str2;
3 – HTTPGETBLOB : Now the core of the program … call Watson Api with HTTPGETBLOB SQL function … we get the result in FileWave variable, is a Blob_file variable so we have our file on IFS-
exec SQL select systools.httpgetblob(:str1, '') xx into :FileWave from sysibm.sysdummy1;
4 – STRPCCMD: Now we have got our wav file on IFS … let’s we play it from our PC
Cmd='STRPCO'; monitor; QCmdExc(cmd:%len(%trim(cmd))); on-error; endmon; Cmd='STRPCCMD PCCMD(''start'+%trim(FileWavePC)+''') PAUSE(*NO)'; QCmdExc(cmd:%len(%trim(cmd)));
Conclusion: here’s another example on HTTPGETCLOB / HTTPGETBLOB functions to be added to other example here in Faq400.com
- IBMi and IFTTT integration with HTTPGETBLOB (Monitor QSYSOPR Messages and send them to our Iphone)
- Bitcoin and IBMi with HTTPGETCLOB
- Getting Euro Exchange Rates from BCE/ECB with HTTPGETBLOB