alexa-pi / AlexaPiDEPRECATED

DEPRECATED - Use https://github.com/alexa-pi/AlexaPi instead ...Turn a Raspberry Pi into an Alexa Client
https://github.com/alexa-pi/AlexaPi
MIT License
587 stars 439 forks source link

TuneIn ... so close #71

Closed GemBro closed 8 years ago

GemBro commented 8 years ago

Running AlexaPi 1.1 ... works fine on all the 'classic' commands ... but when I ask to play 'JFS Radio' I get the following stream error and the program (loop) ends ... as in crashes out to prompt ...

ERROR DUMP:

Player State: State.Opening Player State: State.Playing Player State: State.Ended Ready to Record. Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 810, in bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 763, in run self.__target(_self.args, _self.__kwargs) File "main.py", line 265, in play_audio file = tuneinplaylist(file) File "main.py", line 256, in tuneinplaylist r = requests.get(req.content) File "/usr/lib/python2.7/dist-packages/requests/api.py", line 60, in get return request('get', url, _kwargs) File "/usr/lib/python2.7/dist-packages/requests/api.py", line 49, in request return session.request(method=method, url=url, *_kwargs) File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 443, in request prep = self.prepare_request(req) File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 374, in prepare_request hooks=merge_hooks(request.hooks, self.hooks), File "/usr/lib/python2.7/dist-packages/requests/models.py", line 304, in prepare self.prepare_url(url, params) File "/usr/lib/python2.7/dist-packages/requests/models.py", line 354, in prepare_url scheme, auth, host, port, path, query, fragment = parse_url(url) File "/usr/lib/python2.7/dist-packages/urllib3/util/url.py", line 143, in parse_url raise LocationParseError(url) LocationParseError: Failed to parse: st8.webradioworld.net:8008 http:

MY GUESS: "Failed to parse: st8.webradioworld.net:8008" ... because that is not the actual audio stream URL ...

It's close at playing the stream though ... that 'st8.webradioworld.net:8008' is the actual ShoutCast Admin page, which is correct ... but it's not the audio stream ... to stream the audio (to hear it) it must have http:// in front of that URL ... i.e. ... http://st8.webradioworld.net:8008 ...

If 'st8.webradioworld.net:8008' is put into VLC (on a PC) it errors out, like in AlexaPi ...

But if you put http://st8.webradioworld.net:8008 into VLC (or any media player for that matter) it does start streaming the audio ...

So it looks like the TuneIn audio stream URL (in my example) is being grabbed right but not parsing correctly because it's missing the vital bit at the beginning (http://) to tell Pi VLC it's actually audio ...

That's what I'm getting from my log above ... does that make sense? ... wish I knew where I could ammend the stream URL to add http:// at the beginning to see if that works ...

benwoodley commented 8 years ago

Hmm that could be the solution to my issue too :o

GemBro commented 8 years ago

@ben

It looks like it ... I just asked to play Radio One and get the same error as I did for my station ...

s30.streamerportal.com:8448 ... in VLC URL does not stream audio ...

but ... http://s30.streamerportal.com:8448 ... in VLC does stream the audio ...

I notice your error log (https://github.com/sammachin/AlexaPi/issues/68) is different to mine ...

ERROR DUMP:

Player State: State.Opening Player State: State.Playing Player State: State.Ended Ready to Record. Exception in thread Thread-2: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 810, in bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 763, in run self.__target(_self.args, _self.__kwargs) File "main.py", line 265, in play_audio file = tuneinplaylist(file) File "main.py", line 256, in tuneinplaylist r = requests.get(req.content) File "/usr/lib/python2.7/dist-packages/requests/api.py", line 60, in get return request('get', url, _kwargs) File "/usr/lib/python2.7/dist-packages/requests/api.py", line 49, in request return session.request(method=method, url=url, *_kwargs) File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 443, in request prep = self.prepare_request(req) File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 374, in prepare_request hooks=merge_hooks(request.hooks, self.hooks), File "/usr/lib/python2.7/dist-packages/requests/models.py", line 304, in prepare self.prepare_url(url, params) File "/usr/lib/python2.7/dist-packages/requests/models.py", line 354, in prepare_url scheme, auth, host, port, path, query, fragment = parse_url(url) File "/usr/lib/python2.7/dist-packages/urllib3/util/url.py", line 143, in parse_url raise LocationParseError(url) LocationParseError: Failed to parse: s30.streamerportal.com:8448 http:

benwoodley commented 8 years ago

Can you tell me the name of a radio station that worked for you so that I can compare? I don't know any American radio stations.

GemBro commented 8 years ago

@ben

Here's a list of USA Internet Radio Stations on TuneIn: http://tunein.com/radio/United-States-r100436/

I've only tried my UK station ... haven't tried any others but have now ... interesting ... still not working though ...

I tried one from New York ... asked to 'play WBGO' ... and now Alexa loops over and over ... keeps saying playback successful though ... but still no audio at all ... I let it loop 3 times ...

LOG DUMP:

pi@raspberrypi:~/AlexaPi1.1 $ sudo python main.py

Checking Internet Connection... Connection OK Play_Audio Request for: /home/pi/AlexaPi1.1/hello.mp3 Player State: State.Opening Player State: State.Playing Player State: State.Ended

Ready to Record. Recording... Recording Finished. Sending Speech Request... Processing Request Response...

JSON String Returned: {"messageBody": {"directives": [{"namespace": "SpeechSynthesizer", "name": "speak", "payload": {"contentIdentifier": "amzn1.as-ct.v1.Domain:Application:Music#ACRI#DeviceTTSRendererV4_3c67cfb7-f5ca-40e6-ab03-d5fe06939fec", "audioContent": "cid:DeviceTTSRendererV4_3c67cfb7-f5ca-40e6-ab03-d5fe06939fec_1744324029"}}, {"namespace": "AudioPlayer", "name": "play", "payload": {"playBehavior": "REPLACE_PREVIOUS", "audioItem": {"streams": [{"progressReport": {"progressReportDelayInMilliseconds": 0, "progressReportIntervalInMilliseconds": 900000}, "streamUrl": "https://opml.radiotime.com/Tune.ashx?serial=AFIHU5JRSUSO3FIXP5L7MSTDFWQQ&formats=aac,mp3&partnerId=!EALLOjB&id=s27437", "offsetInMilliseconds": 0, "expiryTime": "2016-05-02T12:22:53+0000", "streamId": "amzn1.as-ct.v1.Dee-Domain-Music#ACRI#url#ACRI#36150927-4ae0-46a8-a183-d73e06b0e29d:1", "progressReportRequired": true}], "audioItemId": "amzn1.as-ct.v1.Dee-Domain-Music#ACRI#url#ACRI#36150927-4ae0-46a8-a183-d73e06b0e29d:1"}, "navigationToken": "amzn1.as-ct.v1.Dee-Domain-Music#ACRI#url#ACRI#36150927-4ae0-46a8-a183-d73e06b0e29d:1"}}]}, "messageHeader": {}} Play_Audio Request for: /home/pi/AlexaPi1.1/tmpcontent/DeviceTTSRendererV4_3c67cfb7-f5ca-40e6-ab03-d5fe06939fec_1744324029.mp3 Player State: State.Opening Player State: State.Playing Player State: State.Ended Play_Audio Request for: https://opml.radiotime.com/Tune.ashx?serial=AFIHU5JRSUSO3FIXP5L7MSTDFWQQ&formats=aac,mp3&partnerId=!EALLOjB&id=s27437 Ready to Record. Player State: State.Opening Player State: State.Playing Sending Playback Progress Report Request... Player State: State.Ended Sending Playback Progress Report Request... Sending GetNextItem Request... Playback Progress Report was Successful! Playback Progress Report was Successful! Processing Request Response...

JSON String Returned: {"messageBody": {"audioItem": {"streams": [{"progressReport": {"progressReportDelayInMilliseconds": 0, "progressReportIntervalInMilliseconds": 900000}, "streamUrl": "https://opml.radiotime.com/Tune.ashx?serial=AFIHU5JRSUSO3FIXP5L7MSTDFWQQ&formats=aac,mp3&partnerId=!EALLOjB&id=s27437", "offsetInMilliseconds": 0, "expiryTime": "2016-05-02T12:22:59+0000", "streamId": "amzn1.as-ct.v1.Dee-Domain-Music#ACRI#url#ACRI#36150927-4ae0-46a8-a183-d73e06b0e29d:1", "progressReportRequired": true}], "audioItemId": "amzn1.as-ct.v1.Dee-Domain-Music#ACRI#url#ACRI#36150927-4ae0-46a8-a183-d73e06b0e29d:1"}, "navigationToken": "amzn1.as-ct.v1.Dee-Domain-Music#ACRI#url#ACRI#36150927-4ae0-46a8-a183-d73e06b0e29d:1"}, "messageHeader": {}} Play_Audio Request for: https://opml.radiotime.com/Tune.ashx?serial=AFIHU5JRSUSO3FIXP5L7MSTDFWQQ&formats=aac,mp3&partnerId=!EALLOjB&id=s27437 Player State: State.Opening Player State: State.Playing Sending Playback Progress Report Request... Player State: State.Ended Sending Playback Progress Report Request... Sending GetNextItem Request... Playback Progress Report was Successful! Playback Progress Report was Successful! Processing Request Response...

JSON String Returned: {"messageBody": {"audioItem": {"streams": [{"progressReport": {"progressReportDelayInMilliseconds": 0, "progressReportIntervalInMilliseconds": 900000}, "streamUrl": "https://opml.radiotime.com/Tune.ashx?serial=AFIHU5JRSUSO3FIXP5L7MSTDFWQQ&formats=aac,mp3&partnerId=!EALLOjB&id=s27437", "offsetInMilliseconds": 0, "expiryTime": "2016-05-02T12:23:01+0000", "streamId": "amzn1.as-ct.v1.Dee-Domain-Music#ACRI#url#ACRI#36150927-4ae0-46a8-a183-d73e06b0e29d:1", "progressReportRequired": true}], "audioItemId": "amzn1.as-ct.v1.Dee-Domain-Music#ACRI#url#ACRI#36150927-4ae0-46a8-a183-d73e06b0e29d:1"}, "navigationToken": "amzn1.as-ct.v1.Dee-Domain-Music#ACRI#url#ACRI#36150927-4ae0-46a8-a183-d73e06b0e29d:1"}, "messageHeader": {}} Play_Audio Request for: https://opml.radiotime.com/Tune.ashx?serial=AFIHU5JRSUSO3FIXP5L7MSTDFWQQ&formats=aac,mp3&partnerId=!EALLOjB&id=s27437 Player State: State.Opening Player State: State.Playing Sending Playback Progress Report Request... Player State: State.Ended Sending Playback Progress Report Request... Sending GetNextItem Request... Playback Progress Report was Successful! Playback Progress Report was Successful! Processing Request Response...

I exited out to prompt after 3 loops ...

sammachin commented 8 years ago

Thanks @GemBro it looks like TuneIn returns all sorts of nested URL's for different stations and VLC doesn't seem to easily parse those so I might have to write code for each type to extract the real audio streams, this is what I did for the BBC stuff in the UK.

@Hoki-gcav When you say Radio One are you talking about BBC Radio 1 in the UK, that works for me as it was my first test of TuneIn?

benwoodley commented 8 years ago

Do you have to specify that its BBC? I will try that.

benwoodley commented 8 years ago

That worked! Wow I'm incompetent. I didn't factor in that there might be a different radio 1 beside the BBC's... .-. This works brilliantly, I'm gonna need to get a proper sound card for this pi now cus I'm gonna be using this a lot ^-^

sammachin commented 8 years ago

No worries, the the BBC stuff should work but I'm not surprised other stations don't, I'll take a look at 'Radio One' whereever that is!

On Mon, May 2, 2016 at 5:10 PM, Hoki-gcav notifications@github.com wrote:

That worked! Wow I'm incompetent. I didn't factor in that there might be a different radio 1 beside the BBC's... .-. This works brilliantly, I'm gonna need to get a proper sound card for this pi now cus I'm gonna be using this a lot ^-^

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/sammachin/AlexaPi/issues/71#issuecomment-216279196

sammachin commented 8 years ago

Note for me to look into, theres a VLC plugin for TuneIn that might add some parsing capabilities to the urls that alexa sends back for Tune IN, no idea if it will work with the py bindings or the command line. http://addons.videolan.org/content/show.php/TuneIn+Radio?content=152788

benwoodley commented 8 years ago

Hmm, i'll give a shot if I get some time. I'm pretty happy with just Radio One, thats the only station I'd ever listen too. Waiting for someone to make a spotify control skill (which is possible through spotify's controller API) so I can have alexa play my playlists :)

GemBro commented 8 years ago

That works!!! ... BBC Radio 1, 2, 3 etc ... that's cool to actually get a station playing now on TuneIn ... didn't think to use BBC either ;) ...

Some (UK stations) that work: Play Kiss FM - works (plays on iHeart radio ... I'm not registered with iHeart!!!)

Play BBC Radio London - works (but has error) Error = ([71a22e40] mpgatofixed32 audio converter error: libmad error: bad main_data_begin pointer)

Play Capital FM - works (but has error) Error = [75e1cdf0] mpgatofixed32 audio converter error: libmad error: bad main_data_begin pointer

Gonna try some others ... here's a list of UK Internet Radio Stations: https://en.wikipedia.org/wiki/List_of_radio_stations_in_the_United_Kingdom

Cannot get the Android Alexa app to work though (downloaded APK) ... so cannot try iHeart or others ... wish there was a tutorial on how to use Alexa app with AlexaPi ...

Good work Sam ... appreciate all you're doing for this community ;) ... oh and "that" Radio One is a random channel :) ...

sammachin commented 8 years ago

@GemBro I struggled to signup for iHeart Radio I think you need to have a US ip address need to sort my VPN.

I don't think there's anything that the iOS/Android app can do that you can't do from the web, http://alexa.amazon.com

GemBro commented 8 years ago

Ok ... thanks for the tips Sam ...

The good news is, after the second attempt, I've now got approved for Amazon Music streaming through the AVS ... gonna tuck into this project properly and design some electronic addons ...

benwoodley commented 8 years ago

If you want to get the app for iOS or Android just make a chosen app store account on US store with no payment method linked. I did this for iOS and managed to get the Alexa App on my Nexus 7 tablet, iPad & iPhone.

By the way Gem, how long did it take to get your Amazon Music streaming to go from pending to accepted? And what did you put for the fields asking what cache and buffering mechanisms your device uses?

GemBro commented 8 years ago

Thanks for that USA hack Ben ... I'll give that a go ;) ...

I forgot about the Alexa page on Amazon, as Sam suggested above and that seems to give exactly the same setup as the Android app, I have already ...

As for the Amazon Music section (on the Dev application page - device’s buffering/caching mechanisms) my 2nd attempt for approval seem to take a bit longer (nearly 2 weeks I think) than the 1st (which took roughly 10 days) ...

I originally put in 'RaspberryEcho' (cannot remember where I saw that suggestion) ... obviously wasn't enough info for Amamzon, hence got rejected ...

On the 2nd attempt I just put in 'VLC Media Player' ... that's all I changed (then re-submitted) ... that seemed to work ...

I think Amazon just need to know that you don't intend to rip/copy/record the music ... so having an application that cannot do those things (intentionally) and does not void any copyright laws regarding the streamed audio from Amazon, is fair doo's ...

If I'm correct, I think the actual time (delay) for the max Amazon Audio stream length session is 10 seconds? ... then it dumps the cache and fills it up again ... I think, that's what's required by Amazon ... I read that somewhere too ...

GemBro commented 8 years ago

Gonna close this now issue ...

flooie commented 8 years ago

... I still don't have tune in working - I get the same weird DVD error that someone else was mentioning

GemBro commented 8 years ago

Flooie ... Sam's working on the URLs that cannot get parsed ... some of us in the UK can get some of our well known stations to play (see above) but none of the USA stations stream audio, because of the URL errors (I can't at the moment) ... I'm sure something will be sorted soon ;) ...

Have you tried the BBC stations above? ... if they work fine (stream) using TuneIn normally (via their web page) then they should work (stream) in AlexaPi ...

ProfessionalParanoid commented 8 years ago

So, I'm having the same problem where you press the button and ask for a TuneIn station and it says it's going to play the station (NPR news in my case) and then nothing. The -I'm talking- LED goes out and nada. It sounds more like the problem described in "TuneIn not working with Version 1.1 #68" question vice what's generally described above. I get some of the flash briefing stations to play, but not the ones with a TuneIn intro. hmmmm.... I followed the TuneIn Radio addons link instructions.

UPDATE: I see GemBro's response to Flooie now. Thanks folks, for doing what you do. I'll check back to see what comes of this.

flooie commented 8 years ago

@GemBro - thanks for the update. Totally works for BBC Radio London

flooie commented 8 years ago

@sammachin I think I have resolved the tunein- issues - hope to share my code soon

flooie commented 8 years ago

I've pushed code that fixes the tune in issue for the stations I use. And also lets you use podcasts from tune in - but only the most recent episode.

ProfessionalParanoid commented 8 years ago

flooie for president! You nailed it! couple of minor tweaks for me; had to add the vlc.py (http://git.videolan.org/?p=vlc/bindings/python.git;a=tree;f=generated;b=HEAD) to the directory with my 'main.py' and create a directory called tmpcontent to the AlexaPi directory. Then NPR Flash brief w/o the tunein intro. My talking mirror is almost complete. just got to figure out a motion or gesture trigger vice pressing the button. Thanks, your upload was very helpful. flooie's fix in action: http://other.bagpipez.com/Projects/

flooie commented 8 years ago

Big update coming. Thanks for the kind words

On May 12, 2016, at 7:07 PM, ProfessionalParanoid notifications@github.com wrote:

flooie for president! You nailed it! couple of minor tweaks for me; had to add the vlc.py (http://git.videolan.org/?p=vlc/bindings/python.git;a=tree;f=generated;b=HEAD) to the directory with my 'main.py' and create a directory called tmpcontent to the AlexaPi directory. Then NPR Flash brief w/o the tunein intro. My talking mirror is almost complete. just got to figure out a motion or gesture trigger vice pressing the button. Thanks, your upload was very helpful. flooie's fix in action: http://other.bagpipez.com/Projects/

— You are receiving this because you commented. Reply to this email directly or view it on GitHub

sammachin commented 8 years ago

@flooie Can you submit a PR with your changes soon I'd like to get them merged before i make any further changes to the branch.

Sam

GemBro commented 8 years ago

@flooie

Interesting ... I'll have a play when available ... thanks ...

GemBro commented 8 years ago

@ProfessionalParanoid

You could have a simple iR (infra red) proximity switch setup ... by either waving your hand, or placing your hand at/on the mirror, to replace the 'button' ... if you make the iR trigger a short distance (say a few inches) people standing in front of the mirror will not trigger it by mistake ... I see your mirror has a monitor behind it? so the 2 way light passage, for the iR, is possible ...

Something like this (already built and gives a digital output when enaged): http://i.imgur.com/yXAtDTt.jpg

GemBro commented 8 years ago

Closing this thread ...