Skip to content

Commit

Permalink
add ability to send audio via WS
Browse files Browse the repository at this point in the history
  • Loading branch information
vapormusic committed Feb 11, 2023
1 parent b5ec441 commit 0f3e745
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
13 changes: 11 additions & 2 deletions example_execlient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion examples/play_stdin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 6 additions & 1 deletion exe_api.md
Original file line number Diff line number Diff line change
@@ -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"```**

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0f3e745

Please sign in to comment.