Author Topic: Internet Radio  (Read 22290 times)

0 Members and 1 Guest are viewing this topic.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Internet Radio
« on: July 16, 2013, 11:41:20 AM »
Did you know that you can play internet audio streams with VoxCommando?

Here is a sample group that plays one of my favourite radio stations, "Radio Paradise".

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<commandGroup open="False" name="radio paradise" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="93" name="Stream Radio Paradise" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Sound.PlayStream</cmdType>
      <cmdString>http://www.radioparadise.com/m3u/mp3-128.m3u</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Stream Radio Paradise, start the stream</phrase>
  </command>
  <command id="87" name="what playing on radio paradise" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Scrape</cmdType>
      <cmdString> http://www.radioparadise.com/xml/chumby.xml</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <cmdString>&gt;(.+)&lt;</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>This is {Match.5}, by {Match.4}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.Speak</cmdType>
      <cmdString>This is {Match.5}, by {Match.4}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>whats playing on radio paradise</phrase>
  </command>
  <command id="88" name="stop the stream" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Sound.StopStream</cmdType>
      <cmdString />
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>stop the stream</phrase>
  </command>
</commandGroup>

This groups has 3 commands.
* One to start playing the stream (internet connection required of course)
* One to stop playing
* One to scrape "now playing" information from the Radio Paradise website.
« Last Edit: July 16, 2013, 12:14:29 PM by jitterjames »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Internet Radio
« Reply #1 on: July 16, 2013, 01:12:56 PM »
Cool, and seemingly simple, except for the tricksy regular expressions (RegEx) bit that you use to get the artist and song info from the Radio Paradise site. At least for the uninitiated.

It's nice that they provide that clean xml though!

So, if I may, I'm going to try here to dissect how your RegEx action works. As per VC's instructions, I used this RegEx cheat sheet as a guide: http://www.mikesdotnetting.com/Article/46/CSharp-Regular-Expressions-Cheat-Sheet.

First, in your command you scrape the whole page chumby.xml (which seems to provide metadata on the four most recent songs played/playing?).

Within the page that you've just scraped, in RegEx speak you are then looking for a particular pattern (.+), which must appear between the characters ">" and "<".  Because you're using Results.RegEx, it won't evaluate expressions across new lines -- that would require us to use the action Results.RegExSingle not Results.RegEx.

This means that:

1. It will look for the first instance of the character ">"
2. Whatever is in parentheses ( ) is what it will define as the pattern that we want to capture. So, it should find, capture, and continue to capture any subsequent characters after a ">" -- except if it encounters a newline character -- up until it encounters the next "<".
3. It will store everything between the > and < characters (as long as there are no newline characters, because RegEx looks for patterns line by line) as a match.

So, looking at an excerpt from the Radio Paradise chumby.xml page:

<?xml version='1.0' encoding='UTF-8'?>[new line here, so won't use this ">" but will keep looking for the next one]
<playlist>[new line here, so won't use this ">" but will keep looking for the next one, etc. throughout this scrape]
<refresh_time>1373990601</refresh_time> [Match.1]
  <song>[new line here, so won't use this]
    <playtime>8:59 am</playtime> [Match.2]
    <timestamp>1373990367</timestamp> [Match.3]
    <artist>Susie Suh</artist> [Match.4]
    <title>Feather In The Wind</title> [Match.5]
    <album>The Bakman Tapes</album> [Match.6]
    <songid>43357</songid> [Match.7]
    <rating>6.5</rating> [Match.8]
    <coverart>htp://www.radioparadise.com/graphics/covers/m/B006ONTX82.jpg</coverart> [Match.9]
  </song>

So, to announce that it is playing {song x} by {artist y}, we need
Code: [Select]
song = {Match.5} and artist = {Match.4}
Did I get that right?
« Last Edit: February 22, 2016, 10:59:56 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)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Internet Radio
« Reply #2 on: July 16, 2013, 01:40:23 PM »
Absatively.  So if anyone wanted to include the album name too, they could use {Match.6}

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: Internet Radio
« Reply #3 on: July 16, 2013, 01:55:13 PM »
Hi nime5ter - great explanation  :clap ::bow ::duh

So this is also very helpful for any other scrape command.

Thanks
***********  get excited and make things  **********

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Internet Radio
« Reply #4 on: July 16, 2013, 02:35:23 PM »
Hi nime5ter - great explanation  :clap ::bow ::duh

So this is also very helpful for any other scrape command.

You are very generous with your praise, thanks Kalle.  :biglaugh

By the way, I edited my post above to try to make a couple points more clear ... not sure if it helped.

It seems like a good idea to try to master this RegEx stuff in order to make the scrape action truly useful. But I suspect the Radio Paradise example is particularly simple; how many sites will have this nice clean xml code to scrape??

For example, I think it could be fun to ask Vox about movies currently playing in theatres -- what's playing at local cinemas tonight, at what times are particular movies playing.

Since IMDB provides this information (as does Google), it would be great if I could scrape their sites. But looking at the page source of one of those pages (e.g. http://www.imdb.com/showtimes/), I'm pretty sure I could never figure it out.

Bummer!
« Last Edit: July 16, 2013, 02:45:30 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)

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: Internet Radio
« Reply #5 on: July 16, 2013, 02:53:01 PM »
That is true, the most sites have a very confused code  :bonk , but I think a python script with "BeautifulSoup" can do this.

https://www.youtube.com/watch?v=Ap_DlSrT-iE

http://www.crummy.com/software/BeautifulSoup/bs3/documentation.html#Navigating the Parse Tree
« Last Edit: July 16, 2013, 03:47:28 PM by jitterjames »
***********  get excited and make things  **********

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Internet Radio
« Reply #6 on: July 16, 2013, 02:59:27 PM »
Hmm. I will leave it to you full-on nerdz to figure that out. Back to work here.
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: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Internet Radio
« Reply #7 on: July 16, 2013, 04:09:25 PM »
Since I am the "head nerd" around these parts, and because I can't resist playing the regex game, I've done the easiest thing based on the movie challenge.

This command will list the movies playing today for your location.  I've used my postal code for the imdb URL so for it to be of any use to you, you would need to modify the URL in the scrape action.

[26-MARCH-2015 -- While the concept is still valid, you will need to update the regular expression in the command below for this command to work because the IMDB website has changed since this was posted.]

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="176" name="local movies today" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <cmdString>http://www.imdb.com/showtimes/location/CA/J0R1H0</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <cmdString>alt="(.*?)\bPoster"</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.MatchConcat</cmdType>
    <cmdString>{CR}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <cmdString>{LastResult}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>local movies today</phrase>
</command>
« Last Edit: March 26, 2015, 10:04:52 AM by nime5ter »

Graves

  • Jr. Member
  • **
  • Posts: 17
  • Karma: 0
    • View Profile
Re: Internet Radio
« Reply #8 on: August 14, 2013, 03:04:15 AM »
Is there anyway to add 2 stations.  What i mean is say.  Computer play radio. Computer  response would be- which station would u prefer rock or metal.  Then i would say which one and it would play it.  And an option to change stations as well by saying change station.  Im still getting the hang of this.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Internet Radio
« Reply #9 on: August 14, 2013, 08:50:06 AM »
Typically, we would just create one command for each station.

Play me some rock radio

Play me some metal radio

There is no need for the other back and forth conversation with TTS really, but you can create the "fluff" if you want.  The concept of an actual menu of choices does not exist in VoxCommando yet.

What would the "change station" command actually do?  Play the "other" station?  Play one at random?

Graves

  • Jr. Member
  • **
  • Posts: 17
  • Karma: 0
    • View Profile
Re: Internet Radio
« Reply #10 on: August 14, 2013, 10:01:49 AM »
The change station would be to go to the next one or possibly random.  I see what ur saying that making two commands Would be best.  I was trying to make a Jarvis lol.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Internet Radio
« Reply #11 on: August 14, 2013, 11:23:57 AM »
Typically, we would just create one command for each station.

Play me some rock radio

Play me some metal radio


Although this doesn't address the Jarvis issue or random station playing, the actual selection of rock station/metal station/talk radio station could be done in one command using a payload XML solution similar to what I did here: http://voxcommando.com/forum/index.php?topic=1119.0.

In that case, "rock" or "metal" would only play the one particular stream you've assigned to each genre though. To have VC randomly choose a stream from a library of streams in the 'rock' genre would require something more elaborate.
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: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Internet Radio
« Reply #12 on: August 21, 2013, 11:29:21 AM »
Here is a quite a fancy set of commands for playing radio streams from "Shoutcast"

You request a genre of music, and then VC will go load a list of shoutcast stations for that genre, select one at random, and start playing it.

Streams can either be played directly from VC or they can be opened in another program like mediaMonkey, or iTunes

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<commandGroup open="True" name="shoutcast" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="184" name="playRadioMatch" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Creates a playlist file using an URL stored as a match in the &quot;shoutcast genre&quot; command, and then opens it with the default program associated with .pls files.&#xD;&#xA;&#xD;&#xA;Alternatively the stream could be opened directly in VoxCommando.">
    <action>
      <cmdType>Scrape</cmdType>
      <cmdString>{Match.{1}}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>File.Write</cmdType>
      <cmdString>radio.pls&amp;&amp;{LastResult}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Launch.OpenFile</cmdType>
      <cmdString>radio.pls</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <cmdString>File.=(.*)</cmdString>
      <cmdRepeat>0</cmdRepeat>
    </action>
    <action>
      <cmdType>Sound.PlayStream</cmdType>
      <cmdString>{Match.1}</cmdString>
      <cmdRepeat>0</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <cmdString>Title.=\(.*?\)(.*)</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.Speak</cmdType>
      <cmdString>Now playing {Match.1}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>Now playing {Match.1}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>playRadioMatch</event>
  </command>
  <command id="167" name="shoutcast genre" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Given a genre as payload {1} this command will scan the various shoutcast radio stations available matching that genre.  These feeds are all stored as matches using RegEx.  It will thengenerate a random number (using Python) that is used to select a station.  An event &quot;playRadioMatch&quot; is then generated with the random number as the payload.  See the command &quot;playRadioMatch&quot; to see how the station is then played.">
    <action>
      <cmdType>VC.Off</cmdType>
      <cmdString />
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Sound.StopStream</cmdType>
      <cmdString />
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.Stop</cmdType>
      <cmdString />
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.Speak</cmdType>
      <cmdString>searching for {1} stations</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Scrape</cmdType>
      <cmdString>http://www.shoutcast.com/radio/{1}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <cmdString>href="(.*?)".*?class="playbutton</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PY.ExecString</cmdType>
      <cmdString>import random</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PY.ExecString</cmdType>
      <cmdString>result = random.randint(1,{#M})</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.Speak</cmdType>
      <cmdString>Found {#M} stations, playing number {LastResult}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.TriggerEvent</cmdType>
      <cmdString>playRadioMatch&amp;&amp;{LastResult}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>shoutcast, radio</phrase>
    <phrase>genre, station</phrase>
    <payloadList>Alternative,Blues,Classical,Country,Decades,Easy Listening,Electronic,Folk,Inspirational,International,Jazz,Latin,Metal,Misc,New Age,Pop,Public Radio,Rap,Reggae,Rock,Baroque,Soundtracks,Talk,Themes</payloadList>
  </command>
  <command id="185" name="stop stream" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Sound.StopStream</cmdType>
      <cmdString />
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>stop stream</phrase>
  </command>
</commandGroup>

StrikemanXL

  • $upporter
  • Jr. Member
  • *****
  • Posts: 13
  • Karma: 1
    • View Profile
Re: Internet Radio
« Reply #13 on: August 22, 2013, 04:08:49 PM »
I get this error when I run your above code
22/08/2013 19:50:54   914   received udp command:vc.tellvox&&radio genre Baroque
22/08/2013 19:50:54   914   action repeat set to: 1
22/08/2013 19:50:54   914   Action:  vc.tellvox - radio genre Baroque
22/08/2013 19:50:54   920   emulating recognition on string:radio genre Baroque
22/08/2013 19:50:54   966   semanticID: 172
22/08/2013 19:50:54   967   kvp: command | 172
22/08/2013 19:50:54   967   kvp: p172d1 | Baroque
22/08/2013 19:50:54   968   semanticID: 172
22/08/2013 19:50:54   969   kvp: command | 172
22/08/2013 19:50:54   969   kvp: p172d1 | Baroque
22/08/2013 19:50:54   969   alternate:radio genre Baroque
22/08/2013 19:50:54   991   doCommand:shoutcast genre
22/08/2013 19:50:54   992   action repeat set to: 1
22/08/2013 19:50:54   992   Action:  VC.Off -
22/08/2013 19:50:55   5   action repeat set to: 1
22/08/2013 19:50:55   5   Action:  Sound.StopStream -
22/08/2013 19:50:55   8   System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
   at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
   at System.Windows.Forms.Control.Invoke(Delegate method)
   at r.a(bv A_0, List`1 A_1)
   at r.b(ba A_0)
   at r.a(ba A_0)
   at r.a(Object A_0, SpeechRecognizedEventArgs A_1)

btw im using VC version 1.1.0.0  because when i click on the dropbox link you posted for VC 1.132  it says its empty.....

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Internet Radio
« Reply #14 on: August 22, 2013, 05:55:40 PM »
Sorry.  You can get the latest version here: http://voxcommando.com/forum/index.php?topic=1164.0

You will need to enable the python plugin (py) in VC options and you need something installed that can play .pls (playlist files)

Or if you want to play the stream directly in VC you can edit the command "playRadioMatch".

-Disable the actions (File.Write and Launch.OpenFile) by changing the 1s to 0s (or delete the actions)
-Enable the next two actions that are currently being skipped by changing the 0s to 1s