Hi,
I’m developing a sort of radio application with WPF and C# and I want to be able to reproduce only the audio from a channel, but I can’t find any library that allows me to do that.
Is there a way to do it?
Hi,
I’m developing a sort of radio application with WPF and C# and I want to be able to reproduce only the audio from a channel, but I can’t find any library that allows me to do that.
Is there a way to do it?
This isn’t supported and I don’t think you’re supposed to, but here’s the steps:
curl 'https://api.twitch.tv/api/channels/{{channel name}}/access_token' \
-H "Client-ID: {{your client id}}"
This returns JSON like this:
{
"token": "long, JSON-escaped string of JSON",
"sig": "8d5f2df9ad2761f136eea27902a2fe34e12f6796",
"mobile_restricted": false
}
You need the “sig” and “token” for the next request. Use that data like this: (client ID optional)
curl 'https://usher.ttvnw.net/api/channel/hls/{{channel name}}.m3u8? \
allow_audio_only=true&sig=8d5f2df9ad2761f136eea27902a2fe34e12f6796 \
&token=long%20string%20of%20escaped%20JSON'
Critical bit there is “allow_audio_only=true” (otherwise it’s not included). This gives you an M3U8 manifest that you need to parse. You’ll see a group called “audio_only” in the list:
#EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="audio_only",NAME="audio_only",AUTOSELECT=NO,DEFAULT=NO
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=162806,CODECS="mp4a.40.2",VIDEO="audio_only"
https://...hls.ttvnw.net/.../index-live.m3u8
The “.m3u8” file at “index-live.m3u8” is a list of “.ts” files in the same /directory. These are the containers for the stream data itself. You can keep checking “index-live.m3u8” as it will continue to update. I don’t know what you’re going to use to play the audio, but it might accept the “index-live.m3u8” file rather than buffering the source yourself.
For instance, VLC or FFPlay will happily play this audio:
vlc "https://...hls.ttvnw.net/.../index-live.m3u8"
ffplay "https://...hls.ttvnw.net/.../index-live.m3u8"