Interpret languages
This flow uses the Watson language identification and machine translation features in order to interpret to and from French, Spanish, Arabic and Portugese. Just start chatting with Moni.ai, your virtual assistant, and she will translate in realtime.
Please not that Watson li, mt and the Moni.ai nodes are required.
[{"id":"a69183e7.596e8","type":"Moni.ai in","name":"","trigger":"interpret","username":"","password":"","x":174,"y":230,"z":"7cb39cf0.834c64","wires":[["7d1e5257.82e1ac"]]},{"id":"712a0e0c.8ed5f","type":"watson-translate","name":"","language":"","x":798,"y":469,"z":"7cb39cf0.834c64","wires":[["43f2a9b3.bc0d58"]]},{"id":"43f2a9b3.bc0d58","type":"Moni.ai ask","name":"","trigger":"","x":185,"y":395,"z":"7cb39cf0.834c64","wires":[["839ef838.7c6108"]]},{"id":"7d1e5257.82e1ac","type":"change","name":"\"just start talking...\"","rules":[{"t":"set","p":"payload","to":"Ok, just start talking - I'll try to interpret to English and back - say \"stop it\" when finished."}],"action":"","property":"","from":"","to":"","reg":false,"x":154,"y":338,"z":"7cb39cf0.834c64","wires":[["43f2a9b3.bc0d58"]]},{"id":"839ef838.7c6108","type":"watson-language-identification","name":"","x":333,"y":485,"z":"7cb39cf0.834c64","wires":[["79bca8fd.864358"]]},{"id":"e9eff58f.161008","type":"function","name":"set language code","func":"if (msg.tlang) {\n msg.lang = \"enus\";\n context.lang = msg.tlang;\n}\nif (msg.lang) {\n if (msg.lang != \"enus\") {\n context.lang = msg.lang;\n msg.lang = \"mt-\" + context.lang + \"-enus\";\n } else if (!context.lang) {\n context.userinput = msg.payload;\n return [msg,null];\n } else {\n msg.lang = \"mt-enus-\" + context.lang;\n }\n} \nif (context.userinput) {\n msg.payload = context.userinput;\n context.userinput = null;\n}\nreturn [null,msg];","outputs":"2","valid":true,"x":772,"y":567,"z":"7cb39cf0.834c64","wires":[["1c5e8ba8.e3a174"],["712a0e0c.8ed5f"]]},{"id":"1c5e8ba8.e3a174","type":"Moni.ai ask","name":"","trigger":"What is the target language? Spanish, Portugese, French or Arabic?","x":555,"y":770,"z":"7cb39cf0.834c64","wires":[["524e6d7d.adb194"]]},{"id":"524e6d7d.adb194","type":"function","name":"set target language","func":"switch (msg.payload) {\n case 'spanish':\n msg.tlang = \"eses\";\n break;\n case 'portugese':\n msg.tlang = \"ptbr\";\n break;\n case 'french':\n msg.tlang = \"frfr\";\n break;\n case 'arabic':\n msg.tlang = \"arar\";\n break;\n}\nreturn msg;","outputs":1,"valid":true,"x":876,"y":695,"z":"7cb39cf0.834c64","wires":[["e9eff58f.161008"]]},{"id":"79bca8fd.864358","type":"function","name":"remove \"-\" in language code","func":"msg.lang = msg.lang.replace(\"-\",\"\").toLowerCase();\nif (msg.lang != \"enus\" && msg.lang != \"eses\" &&msg.lang != \"arar\" && msg.lang != \"frfr\" && msg.lang != \"ptbr\") {\n msg.lang = \"enus\"; \n}\nreturn msg;","outputs":1,"valid":true,"x":382,"y":568,"z":"7cb39cf0.834c64","wires":[["e9eff58f.161008"]]}]