From 0f3e74579d8a05ac69b4d1d5df1e0d0bb6f18363 Mon Sep 17 00:00:00 2001 From: vapormusic Date: Sat, 11 Feb 2023 13:23:10 +0700 Subject: [PATCH] add ability to send audio via WS --- example_execlient.js | 13 +++++++++++-- examples/play_stdin.js | 7 ++++++- exe_api.md | 7 ++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/example_execlient.js b/example_execlient.js index 925cde8..9929fec 100644 --- a/example_execlient.js +++ b/example_execlient.js @@ -12,7 +12,9 @@ var ffmpeg = spawn('C:\\ffmpeg\\bin\\ffmpeg.exe', [ ]); // pipe data to AirTunes -ffmpeg.stdout.pipe(airtunes.stdin); +// ffmpeg.stdout.pipe(airtunes.stdin); + + // detect if ffmpeg was not spawned correctly ffmpeg.stderr.setEncoding('utf8'); @@ -36,9 +38,16 @@ ws.on('open', function open() { "txt":["cn=0,1,2,3","da=true","et=0,3,5","ft=0x4A7FCA00,0xBC354BD0","sf=0xa0404","md=0,1,2","am=AudioAccessory5,1","pk=lolno","tp=UDP","vn=65537","vs=670.6.2","ov=16.2","vv=2"], //"txt":["cn=0,1,2,3","da=true","et=0,3,5","ft=0x4A7FCA00,0xBC354BD0","sf=0x80484","md=0,1,2","am=AudioAccessory5,1","pk=lol","tp=UDP","vn=65537","vs=670.6.2","ov=16.2","vv=2"], "debug":true, - "forceAlac":false}})) + "forceAlac":false}})) }); +ffmpeg.stdout.on('data', function(data) { + try{ + ws.send(JSON.stringify({"type":"sendAudio", + "data": data.toString('binary')})) + }catch(err){} +}) + ws.on('message', function message(data) { console.log('received: %s', data); diff --git a/examples/play_stdin.js b/examples/play_stdin.js index e147cf8..709e962 100644 --- a/examples/play_stdin.js +++ b/examples/play_stdin.js @@ -133,7 +133,12 @@ worker.on("message", (result) => { // Sample data for stopping all: // {"type":"stopAll"} airtunes.stopAll(); - } + } else if (parsed_data.type == "sendAudio"){ + // Sample data for playing: + // {"type":"sendAudio", + // "data": "hex data"} + airtunes.write(Buffer.from(parsed_data.data,"binary")); + } }); function getAvailableDevices() { diff --git a/exe_api.md b/exe_api.md index cff827a..20cbe17 100644 --- a/exe_api.md +++ b/exe_api.md @@ -1,6 +1,6 @@ # How airtunes2.exe works -## **Audio : Pipe PCM 16bit 44100Hz 2ch to airtunes2.exe stdin's** +## **Audio : Pipe PCM 16bit 44100Hz 2ch to airtunes2.exe stdin's or via the WS API** ## **WS API: Connect to ```"ws://localhost:8980"```** @@ -67,6 +67,11 @@ {"type":"stopAll"} +9. Send raw audio: + + {"type":"sendAudio", + "data": "binary string data"} // 16bit 44100Hz 2ch (s16le), data.toString('binary') + ### **Available response: JSON string** 1. Available AirPlay devices: