Skip to content

Commit 0f3e745

Browse files
add ability to send audio via WS
1 parent b5ec441 commit 0f3e745

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

example_execlient.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ var ffmpeg = spawn('C:\\ffmpeg\\bin\\ffmpeg.exe', [
1212
]);
1313

1414
// pipe data to AirTunes
15-
ffmpeg.stdout.pipe(airtunes.stdin);
15+
// ffmpeg.stdout.pipe(airtunes.stdin);
16+
17+
1618

1719
// detect if ffmpeg was not spawned correctly
1820
ffmpeg.stderr.setEncoding('utf8');
@@ -36,9 +38,16 @@ ws.on('open', function open() {
3638
"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"],
3739
//"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"],
3840
"debug":true,
39-
"forceAlac":false}}))
41+
"forceAlac":false}}))
4042
});
4143

44+
ffmpeg.stdout.on('data', function(data) {
45+
try{
46+
ws.send(JSON.stringify({"type":"sendAudio",
47+
"data": data.toString('binary')}))
48+
}catch(err){}
49+
})
50+
4251

4352
ws.on('message', function message(data) {
4453
console.log('received: %s', data);

examples/play_stdin.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ worker.on("message", (result) => {
133133
// Sample data for stopping all:
134134
// {"type":"stopAll"}
135135
airtunes.stopAll();
136-
}
136+
} else if (parsed_data.type == "sendAudio"){
137+
// Sample data for playing:
138+
// {"type":"sendAudio",
139+
// "data": "hex data"}
140+
airtunes.write(Buffer.from(parsed_data.data,"binary"));
141+
}
137142
});
138143

139144
function getAvailableDevices() {

exe_api.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# How airtunes2.exe works
22

3-
## **Audio : Pipe PCM 16bit 44100Hz 2ch to airtunes2.exe stdin's**
3+
## **Audio : Pipe PCM 16bit 44100Hz 2ch to airtunes2.exe stdin's or via the WS API**
44

55
## **WS API: Connect to ```"ws://localhost:8980"```**
66

@@ -67,6 +67,11 @@
6767

6868
{"type":"stopAll"}
6969

70+
9. Send raw audio:
71+
72+
{"type":"sendAudio",
73+
"data": "binary string data"} // 16bit 44100Hz 2ch (s16le), data.toString('binary')
74+
7075
### **Available response: JSON string**
7176

7277
1. Available AirPlay devices:

0 commit comments

Comments
 (0)