Author Topic: Yandex translation command  (Read 8698 times)

0 Members and 1 Guest are viewing this topic.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Yandex translation command
« on: March 10, 2014, 06:28:11 PM »
Having fun with Yandex here. (Based on Phobophile's recommendation in this thread: http://voxcommando.com/forum/index.php?topic=757.msg12500#msg12500)

Seems like they have interesting language options. I wasn't systematic about checking all of the language codes (in the attached payload xml), but it worked with all those I tested.

NOTE: This command uses payload dictation, and therefore will only work in its current form with VoxCommando, not VoxCommandoSP.

My command, in which I translate English phrases into other languages:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="253" name="translate {1} to {2}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape.XML</cmdType>
    <cmdString>https://translate.yandex.net/api/v1.5/tr/translate?key={M:ydx_key.YandexAPI}&amp;text={1}&amp;lang={2}&amp;format=plain&amp;&amp;text</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <cmdString>{Match.1}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>translate</phrase>
  <payloadDictation>payloadDictation: Regular</payloadDictation>
  <phrase>to</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">translationLang.xml</payloadFromXML>
</command>

To use the above, you'd have to replace {M:ydx_key.YandexAPI} with your own API key. I stored mine as a map variable because it's insanely long.

translationLang.xml payload file is attached.

Enjoy.

[edited xml above to fix a glitch in my command phrase -- sorry about that]
« Last Edit: March 30, 2015, 11:26:14 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Hiryu

  • Contributor
  • ***
  • Posts: 53
  • Karma: 2
    • View Profile
Re: Yandex translation command
« Reply #1 on: August 16, 2014, 05:31:45 PM »
HEy nime5ster!  I first tried using the Bing Translation plugin, but it was a no go, since it seems the API keys they are giving out now don't work.  In any case, trying to go the Yandex route now -- I'm able to get it up and running, but I need more languages, specifically Asian languages (Japanese and Chinese).  I did a search online but couldn't find the a list for languages to correctly populate the values in the translationLang.xml -- could you point me in the right direction?  Thanks!

Hiryu

  • Contributor
  • ***
  • Posts: 53
  • Karma: 2
    • View Profile
Re: Yandex translation command
« Reply #2 on: August 16, 2014, 05:38:47 PM »
Also, am I assuming correctly that if I want VC to say the translation, I would need to have a corresponding (commensurate) TTS installed.  Say, if I ask VC to translate a word into French, then it would need to TTS.SetLang FR and then use TTS.Speak{LastResult}?

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Yandex translation command
« Reply #3 on: August 16, 2014, 05:55:04 PM »
If you want your computer to speak in language "X" then yes you need to have a TTS voice installed which speaks that specific language "X".  This should not be a problem if you are using the TTSMS since there are many voices in different languages available for free.  The quality of these free voices is generally not as good as the ones you pay for though.  Not a big surprise though is it?

With bing it was possible to speak in many languages via a web download.

Kalle has done something similar here with an animated face using a web service and robobrowser:
http://voxcommando.com/forum/index.php?topic=1456.msg12724#msg12724

Hiryu

  • Contributor
  • ***
  • Posts: 53
  • Karma: 2
    • View Profile
Re: Yandex translation command
« Reply #4 on: August 16, 2014, 05:58:50 PM »
Sorry for the barrage of posts.  I figured out the language codes -- and added zh for chinese.  That works.  The last part is figuring out how to tell VC to read it back to me in Chinese.

I have the Microsoft LiLi Chinese TTS installed.  And it is selectable under the TTS in options.

I've posted what I've come up with but it doesn't seem to work.  I think probably because my TTS.SetLang {2} is not the right way to go about it? 

Any advice?  Thanks for your help.

--giant .rtf attachment removed --
« Last Edit: February 04, 2015, 09:57:04 AM by jitterjames »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Yandex translation command
« Reply #5 on: August 16, 2014, 06:03:45 PM »
Please post the xml of your command, or at the very least a jpg if you need to show an image for some reason instead.

http://voxcommando.com/mediawiki/index.php?title=XML_on_the_forum

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Yandex translation command
« Reply #6 on: August 16, 2014, 06:05:30 PM »
I think probably because my TTS.SetLang {2} is not the right way to go about it?  
It depends on what the value of payload 2 is, but we don't know what that is.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Yandex translation command
« Reply #7 on: August 16, 2014, 06:06:21 PM »
Looks like Yandex doesn't have Japanese as an option -- at least I can't find it. They do have English to Chinese. The language code is listed as just zh . They're not specific about what kind of Chinese that is.

See http://api.yandex.com/translate/doc/dg/reference/getLangs.xml

The query
Code: [Select]
https://translate.yandex.net/api/v1.5/tr/getLangs?key=APIkey&ui=en returns the following languages:

Code: [Select]
<langs>
<Item key="ar" value="Arabic"/>
<Item key="az" value="Azerbaijani"/>
<Item key="be" value="Belarusian"/>
<Item key="bg" value="Bulgarian"/>
<Item key="bs" value="Bosnian"/>
<Item key="ca" value="Catalan"/>
<Item key="cs" value="Czech"/>
<Item key="da" value="Danish"/>
<Item key="de" value="German"/>
<Item key="el" value="Greek"/>
<Item key="en" value="English"/>
<Item key="es" value="Spanish"/>
<Item key="et" value="Estonian"/>
<Item key="fi" value="Finnish"/>
<Item key="fr" value="French"/>
<Item key="he" value="Hebrew"/>
<Item key="hr" value="Croatian"/>
<Item key="hu" value="Hungarian"/>
<Item key="hy" value="Armenian"/>
<Item key="id" value="Indonesian"/>
<Item key="is" value="Icelandic"/>
<Item key="it" value="Italian"/>
<Item key="ka" value="Georgian"/>
<Item key="lt" value="Lithuanian"/>
<Item key="lv" value="Latvian"/>
<Item key="mk" value="Macedonian"/>
<Item key="ms" value="Malay"/>
<Item key="mt" value="Maltese"/>
<Item key="nl" value="Dutch"/>
<Item key="no" value="Norwegian"/>
<Item key="pl" value="Polish"/>
<Item key="pt" value="Portuguese"/>
<Item key="ro" value="Romanian"/>
<Item key="ru" value="Russian"/>
<Item key="sk" value="Slovak"/>
<Item key="sl" value="Slovenian"/>
<Item key="sq" value="Albanian"/>
<Item key="sr" value="Serbian"/>
<Item key="sv" value="Swedish"/>
<Item key="tr" value="Turkish"/>
<Item key="uk" value="Ukrainian"/>
<Item key="vi" value="Vietnamese"/>
<Item key="zh" value="Chinese"/>
« Last Edit: August 16, 2014, 06:13:01 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Hiryu

  • Contributor
  • ***
  • Posts: 53
  • Karma: 2
    • View Profile
Re: Yandex translation command
« Reply #8 on: August 16, 2014, 06:08:07 PM »
Here's the XML -- I know for now this is not as flexible as TTS.SetLang {payload}, but in this instance I just set it to TTS.SetVoice Lili (the Chinese tTS name)

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.0.0.5-->
<command id="280" name="translate {1} to {2}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape.XML</cmdType>
    <params>
      <param>https://translate.yandex.net/api/v1.5/tr/translate?key={M:ydx_key.YandexAPI}&amp;text={1}&amp;lang={2}&amp;format=plain</param>
      <param>text</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.SetVoiceName</cmdType>
    <params>
      <param>Lili</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{Match.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <params>
      <param>{Match.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.SetLang</cmdType>
    <params>
      <param>en</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>translate</phrase>
  <payloadDictation>payloadDictation: Regular</payloadDictation>
  <phrase>to</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\translationLang.xml</payloadFromXML>
</command>

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Yandex translation command
« Reply #9 on: August 16, 2014, 06:10:36 PM »
Actually TTS.SetLang is for VoxWav TTS only.

You must use TTS.SetVoiceName

Hiryu

  • Contributor
  • ***
  • Posts: 53
  • Karma: 2
    • View Profile
Re: Yandex translation command
« Reply #10 on: August 16, 2014, 06:11:41 PM »
I figured -- so yeah, I set it to TTS.SetVoiceName -- but it still doesn't read it.  Same XML as above. 

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Yandex translation command
« Reply #11 on: August 16, 2014, 06:12:49 PM »
I think it would be simpler to forget about using a payloadXML for the different languages and just create a separate command for each set of languages you want to use.  There probably aren't that many different combinations that you would want to use, and then you can set the voice correctly for each.

Hiryu

  • Contributor
  • ***
  • Posts: 53
  • Karma: 2
    • View Profile
Re: Yandex translation command
« Reply #12 on: August 16, 2014, 06:19:01 PM »
OK -- thanks Jitterjames and nime5ster!  I think I figured it out.  Yeah, it won't be that many languages so I'll just stick with a logic block with the few languages I need.  Thanks!

Hiryu

  • Contributor
  • ***
  • Posts: 53
  • Karma: 2
    • View Profile
Re: Yandex translation command
« Reply #13 on: February 12, 2015, 03:17:11 PM »
Hey Nime5ter -- is the scrape on the xml still working for you on yandex?  It is returning an error for me.  It was working beautifully before when I last touched this, but in going through and cleaning up my VC commands, I tested this and it is no longer working.  ::confused

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Yandex translation command
« Reply #14 on: February 12, 2015, 03:34:43 PM »
Yes, the original command I posted at the beginning of the thread (http://voxcommando.com/forum/index.php?topic=1444.msg12503#msg12503) is working fine for me.

I don't know if that's the command you're referring to.

Are you sure it's the scrape that's generating an error? If so, what kind of error? (You can roll over the error in the history panel to see the details, or check your VC log).
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)