@recappi/sdk 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -25
- package/index.cjs +323 -526
- package/package.json +54 -65
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@recappi/sdk`
|
|
2
2
|
|
|
3
|
-
](https://github.com/Recappi/sdk/actions/workflows/CI.yml)
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
@@ -8,60 +8,94 @@
|
|
|
8
8
|
|
|
9
9
|
Both input and output devices are recording, mixed into a single audio stream.
|
|
10
10
|
|
|
11
|
-
```
|
|
12
|
-
import { writeFile } from
|
|
13
|
-
import { setTimeout } from
|
|
11
|
+
```typescript
|
|
12
|
+
import { writeFile } from 'node:fs/promises'
|
|
13
|
+
import { setTimeout } from 'node:timers/promises'
|
|
14
14
|
|
|
15
|
-
import { ShareableContent } from
|
|
16
|
-
import { createWavBuffer } from
|
|
15
|
+
import { ShareableContent } from '@recappi/sdk'
|
|
16
|
+
import { createWavBuffer } from '@recappi/sdk/encode-wav'
|
|
17
17
|
|
|
18
|
-
const WavBuffers = []
|
|
18
|
+
const WavBuffers = []
|
|
19
19
|
|
|
20
|
-
let totalLength = 0
|
|
20
|
+
let totalLength = 0
|
|
21
21
|
|
|
22
22
|
const session = ShareableContent.tapGlobalAudio([], (err, samples) => {
|
|
23
23
|
if (err) {
|
|
24
|
-
console.error(
|
|
25
|
-
return
|
|
24
|
+
console.error('Error capturing audio:', err)
|
|
25
|
+
return
|
|
26
26
|
}
|
|
27
|
-
WavBuffers.push(samples)
|
|
28
|
-
totalLength += samples.length
|
|
29
|
-
})
|
|
27
|
+
WavBuffers.push(samples)
|
|
28
|
+
totalLength += samples.length
|
|
29
|
+
})
|
|
30
30
|
|
|
31
|
-
console.info(
|
|
31
|
+
console.info('Recording audio for 5 seconds...')
|
|
32
32
|
|
|
33
|
-
await setTimeout(5000)
|
|
33
|
+
await setTimeout(5000) // Record for 5 seconds
|
|
34
34
|
|
|
35
|
-
session.stop()
|
|
35
|
+
session.stop()
|
|
36
36
|
|
|
37
|
-
console.info(
|
|
38
|
-
`Recording stopped. Writing ${totalLength} samples to output.wav...`,
|
|
39
|
-
);
|
|
37
|
+
console.info(`Recording stopped. Writing ${totalLength} samples to output.wav...`)
|
|
40
38
|
|
|
41
39
|
const { buf: contactedBuffer } = WavBuffers.reduce(
|
|
42
40
|
({ buf, offset }, cur) => {
|
|
43
|
-
buf.set(cur, offset)
|
|
41
|
+
buf.set(cur, offset)
|
|
44
42
|
return {
|
|
45
43
|
buf,
|
|
46
44
|
offset: offset + cur.length,
|
|
47
|
-
}
|
|
45
|
+
}
|
|
48
46
|
},
|
|
49
47
|
{
|
|
50
48
|
buf: new Float32Array(totalLength),
|
|
51
49
|
offset: 0,
|
|
52
50
|
},
|
|
53
|
-
)
|
|
51
|
+
)
|
|
54
52
|
|
|
55
|
-
console.log(`Creating WAV buffer ...`)
|
|
53
|
+
console.log(`Creating WAV buffer ...`)
|
|
56
54
|
|
|
57
55
|
const wavBuffer = Buffer.from(
|
|
58
56
|
createWavBuffer(contactedBuffer, {
|
|
59
57
|
sampleRate: session.sampleRate,
|
|
60
58
|
numChannels: session.channels,
|
|
61
59
|
}),
|
|
62
|
-
)
|
|
60
|
+
)
|
|
63
61
|
|
|
64
|
-
await writeFile(
|
|
62
|
+
await writeFile('output.wav', wavBuffer)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Listing running applications
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { ShareableContent } from '@recappi/sdk'
|
|
69
|
+
|
|
70
|
+
const apps = ShareableContent.applications()
|
|
71
|
+
|
|
72
|
+
for (const app of apps) {
|
|
73
|
+
console.log(`Name: ${app.name}, PID: ${app.processId}`)
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Recording specific application
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { ShareableContent } from '@recappi/sdk'
|
|
81
|
+
|
|
82
|
+
const apps = ShareableContent.applications()
|
|
83
|
+
const musicApp = apps.find((app) => app.name === 'Music')
|
|
84
|
+
|
|
85
|
+
if (musicApp) {
|
|
86
|
+
const session = ShareableContent.tapAudio(musicApp.processId, (err, samples) => {
|
|
87
|
+
if (err) {
|
|
88
|
+
console.error('Error capturing audio:', err)
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
// Process samples...
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
// Stop recording after 5 seconds
|
|
95
|
+
setTimeout(() => {
|
|
96
|
+
session.stop()
|
|
97
|
+
}, 5000)
|
|
98
|
+
}
|
|
65
99
|
```
|
|
66
100
|
|
|
67
101
|
## Playground
|