Author Topic: German Weather in combination with TTS?  (Read 3155 times)

0 Members and 1 Guest are viewing this topic.

derCel

  • Jr. Member
  • **
  • Posts: 4
  • Karma: 0
    • View Profile
German Weather in combination with TTS?
« on: October 12, 2011, 07:18:35 AM »

Hi all,

I'm playing around with VC for some days now and I yet have a lot to learn.
I have a question regarding the weather function provided in VC -

Is it possible to trigger a different weather page instead the built in one and use it with TTS.speak?
What I'm currently doing using the provided weather function is:  after fetching the weather for my location switching the voice to EN then using TTS.speak with {lastresult}, once done switching back to German.

While this is okay to some extent (even using EN Anna) I'd really prefer a German weather forecast instead.

If someone could help me that would be really great!

Thanks a lot,
Cel

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: German Weather in combination with TTS?
« Reply #1 on: October 12, 2011, 10:34:47 AM »
welcome derCel.

this is not technically possible at the moment.  however with the plugin framework being almost finished, this is one area where new plugins will be handy.  I just happen to be busy with too many other things right now to deal with this.

If you are feeling ambitious, there may still be a solution for you.  There is a generic function called scrape which lets you get any website as long as it is not password protected

you can then use Results.RegEx to search for patterns and get the data you want off of that website, such as current temperature.

I'm attaching a sample command that scrapes the VoxCommando forum and shows the subject and poster name of the the last post.

derCel

  • Jr. Member
  • **
  • Posts: 4
  • Karma: 0
    • View Profile
Re: German Weather in combination with TTS?
« Reply #2 on: October 12, 2011, 04:07:46 PM »

Thanks a lot James!

Using your example I was able to come up with a solution.

Code: [Select]

<command id="314" name="Wetter heute" enabled="true" alwaysOn="False" confirm="False" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>Scrape</cmdType>
                <cmdString>http://de.wetter.yahoo.com/deutschland/<< your location here >>/</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>Results.RegEx</cmdType>
                <cmdString>yw-cond"&gt;(.*)&lt;/div&gt;&lt;dl&gt;&lt;dt&gt;</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>TTS.Speak</cmdType>
                <cmdString>Im Moment {Match.1} und</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>Results.RegEx</cmdType>
                <cmdString>Temperatur:&lt;/dt&gt;&lt;dd&gt;(.*)&amp;deg;C</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>TTS.Speak</cmdType>
                <cmdString>{Match.1} Grad.</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
        </command>


One question though (more out of curiosity) as I'm new to regEx.
What do I have to do in case a regex condition (string) contains a space like in the line below found in the weather API of google > http://www.google.de/ig/api?weather=Berlin < ?

<condition data="Nieselregen"/>

I tried the following RegEx pattern without any success because of the space in the tag I think:

<condition data="(.*)"/>

Thanks a lot,
Cel

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: German Weather in combination with TTS?
« Reply #3 on: October 12, 2011, 05:31:22 PM »
I always find regex a bit tricky and it involved some trial and error.  I use this as a guide:

http://www.mikesdotnetting.com/Article/46/CSharp-Regular-Expressions-Cheat-Sheet

edit: according to that reference, it would be \s but you probably also need to use (.*?) to make it non-greedy (find the shorted match).
« Last Edit: October 12, 2011, 05:58:33 PM by jitterjames »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: German Weather in combination with TTS?
« Reply #4 on: October 12, 2011, 06:17:12 PM »
by the way, this google weather api looks really useful and I did not know about it even though I recently looked around for different options to scrape from.  Thanks for letting us know about it.

I will probably create a plugin based on this scraper when I get a chance.  Now that you know how to do your own scraping though, you can see that you can do anything you want with a bit of work!

derCel

  • Jr. Member
  • **
  • Posts: 4
  • Karma: 0
    • View Profile
Re: German Weather in combination with TTS?
« Reply #5 on: October 12, 2011, 06:45:36 PM »

It works! The following did the trick - <condition\sdata="(.*?)"/>
I did not understand how the ? works and to be honest I still don't get it why you need to combine * and ? to limit the output to just what I want.  ;D

Many thanks for your help James!
Cel

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: German Weather in combination with TTS?
« Reply #6 on: October 12, 2011, 07:07:09 PM »
consider if you have this data from a web scrape:

<thingA data="aaaa"/><thingB data="bbbb"/>

if you use this regex:    <thingA data="(.*)"/>

it will match like this

<thingA data="aaaa"/><thingB data="bbbb"/>

because  .  means any character, and * is greedy, which means it will find the largest match it can *? is not greedy and will find the smallest match it can.  Adding the ? just means "make it not greedy"
<thingA data="aaaa"/><thingB data="bbbb"/>

and by the way, the brackets around it mean this is something we are going to keep and use as a match.

It's confusing at first.  I always get confused when I come back to regex after not using it for a while.

derCel

  • Jr. Member
  • **
  • Posts: 4
  • Karma: 0
    • View Profile
Re: German Weather in combination with TTS?
« Reply #7 on: October 13, 2011, 04:46:09 AM »
Ok, I think I got it now. Thanks for taking the time to explain this to me, James!

Cel

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: German Weather in combination with TTS?
« Reply #8 on: October 13, 2011, 11:10:35 AM »
When I was trying to wrap my head around regular expressions a while back, I found this tutorial really useful: http://www.regular-expressions.info/tutorialcnt.html

It is language agnostic, and a good overview, but probably more than anyone needs to solve one particular problem.
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)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: German Weather in combination with TTS?
« Reply #9 on: October 17, 2011, 11:58:27 PM »
new google weather plugin... should be pretty easy / poweful

http://voxcommando.com/forum/index.php?topic=617.msg4487#msg4487

you should use VC version 0.913 for best results: http://voxcommando.com/forum/index.php?topic=616.0