forked from novaspirit/Alpine_xfce4_noVNC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudify.js
47 lines (41 loc) · 1.48 KB
/
audify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//Audify audio : https://almoghamdani.github.io/audify/index.html
const WebSocket = require('ws')
var wss = new WebSocket.Server({
port: 56780
});
console.log('Server ready...')
wss.on('connection', function connection(ws) {
console.log('Socket connected. sending data...')
})
const {
RtAudio,
RtAudioFormat,
} = require("audify")
// Init RtAudio instance using default sound API
const rtAudio = new RtAudio()
rtAudio.outputVolume = 0
// Open the input/output stream
rtAudio.openStream({
deviceId: rtAudio.getDefaultOutputDevice(), // Output device id (Get all devices using `getDevices`)
nChannels: 2, // Number of channels
firstChannel: 0 // First channel index on device (default = 0).
}, {
deviceId: rtAudio.getDefaultInputDevice(), // Input device id (Get all devices using `getDevices`)
nChannels: 2, // Number of channels
firstChannel: 0 // First channel index on device (default = 0).
},
RtAudioFormat.RTAUDIO_SINT16, // PCM Format - Signed 16-bit integer
48000, // Sampling rate is 44.1kHz
480, // Frame size is 1920 (40ms)
"MyStream", // The name of the stream (used for JACK Api)
pcm => {
wss.clients.forEach(function each(client) {
if (client.readyState === WebSocket.OPEN) {
client.send(pcm)
}
})
rtAudio.write(pcm)
} // Input callback function, write every input pcm data to the output buffer
)
// Start the stream
rtAudio.start()