News:

There is a soft-mute function which we use with the commands like "What song is this?" There is one for system volume, one for each of: MediaMonkey, XBMC, iTunes, MediaPortal.

Main Menu

German Weather in combination with TTS?

Started by derCel, October 12, 2011, 07:18:35 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

derCel


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

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


Thanks a lot James!

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



<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

#3
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).

jitterjames

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


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

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

Ok, I think I got it now. Thanks for taking the time to explain this to me, James!

Cel

nime5ter

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