@stellarshenson/jupyterlab-audio-extension 1.0.2 → 1.0.42
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 +7 -5
- package/lib/cards.d.ts +12 -0
- package/lib/cards.js +34 -0
- package/lib/index.js +28 -5
- package/lib/settings.d.ts +20 -0
- package/lib/settings.js +57 -0
- package/lib/status.d.ts +23 -2
- package/lib/status.js +142 -4
- package/package.json +3 -1
- package/schema/cards.json +47 -0
- package/schema/plugin.json +76 -1
- package/src/__tests__/player.spec.ts +13 -0
- package/src/__tests__/settings.spec.ts +408 -0
- package/src/__tests__/status-slot.spec.ts +179 -0
- package/src/__tests__/status.spec.ts +7 -1
- package/src/cards.ts +52 -0
- package/src/index.ts +49 -5
- package/src/settings.ts +65 -0
- package/src/status.ts +161 -4
- package/style/base.css +113 -7
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ Chain: browser mic → AudioWorklet (16 kHz mono s16le) → websocket → server
|
|
|
24
24
|
Speaker chain: program in the container → (PulseAudio `voiceout`, out of scope) → `speaker.fifo` (48 kHz stereo s16le) → server reader → websocket → AudioWorklet → tab audio output.
|
|
25
25
|
|
|
26
26
|
> [!IMPORTANT]
|
|
27
|
-
> Out of scope - the extension does not manage PulseAudio, invoke SoX or any recorder, or perform speech-to-text; its responsibility ends at delivering correct PCM to the FIFO, and for playback it begins at reading `speaker.fifo` or playing the file
|
|
27
|
+
> Out of scope - the extension does not manage PulseAudio, invoke SoX or any recorder, or perform speech-to-text; its responsibility ends at delivering correct PCM to the FIFO, and for playback it begins at reading `speaker.fifo` or playing the file a client names to the player. The `jupyterlab_audio player` subcommands are HTTP clients of the extension's authenticated player route; the server process owns every playback process.
|
|
28
28
|
|
|
29
29
|
## Requirements
|
|
30
30
|
|
|
@@ -72,17 +72,19 @@ See [docs/jupyterlab-enable-claude-voice.md](docs/jupyterlab-enable-claude-voice
|
|
|
72
72
|
- Click again to stop - capture tracks are released and the browser indicator clears
|
|
73
73
|
- In the Error state (blinking icon) a click disconnects and returns the control to Disconnected, shown in the tooltip; click once more to start capture again
|
|
74
74
|
- Only one tab streams at a time: starting capture in a second tab takes over and stops the first
|
|
75
|
-
- Playback is always on, with no on/off control and no setting: every tab starts it when JupyterLab loads, and sound
|
|
75
|
+
- Playback is always on, with no on/off control and no setting: every tab starts it when JupyterLab loads, and sound played to the default PulseAudio sink is heard in the tab, whether from `paplay <file>` or from the player queue. `jupyterlab_audio player play <file>` queues the file behind any playing file and `jupyterlab_audio player play <file> --now` plays it at once, mixed with every playing file
|
|
76
76
|
- Sound plays as soon as it arrives in a browser that allows sound without a gesture (Chrome with the autoplay policy no-user-gesture-required), and in any browser after any click or key press anywhere in the tab, panels and frames included. In a browser that blocks autoplay, a tab nobody has clicked or typed in since it loaded may stay silent; sound sent more than 0.5 s before the first click or key press is dropped
|
|
77
77
|
- Every open JupyterLab browser tab plays the sound; opening another tab stops none of them
|
|
78
78
|
- The status bar pill leads with a small audio lamp, then the microphone toggle, a play/stop control and a pause control: the lamp is a filled grey disc when the audio output is ready, green while the microphone streams or a file plays, and a hollow grey ring when the audio output is deliberately shut down; a paused file leaves the lamp grey; hovering the lamp states whether the audio system is ready, in use, shut down or unavailable; while a file plays both controls are enabled and the first shows stop; while paused the first shows play and resumes; with nothing playing both are disabled and greyed
|
|
79
79
|
- When the audio output is unavailable, the lamp blinks amber for 30 seconds and the player tooltip says audio output is unavailable; the controls follow the player mode during the blink, and after 30 seconds the lamp settles to the hollow grey ring and both player controls read as disabled with the same message left in the tooltip; a deliberate shutdown shows the hollow grey ring at once, disables both player controls and leaves the tooltip saying audio output is shut down; the microphone toggle stays enabled whatever the lamp shows
|
|
80
|
-
- The
|
|
81
|
-
-
|
|
80
|
+
- The gear at the right end of the pill opens a settings panel above it; a second click on the gear, Escape or a click outside the panel closes it. The **Audio** card of the panel states whether the microphone captures, whether playback runs and the FIFO that receives captured audio; the card holds no settings
|
|
81
|
+
- Another extension adds its own card below the **Audio** card: an entry `{"name": "<card>", "rank": <number>}` under `"jupyter.lab.toolbars"` → `"AudioSettings"` in its settings schema, and `IToolbarWidgetRegistry.addFactory('AudioSettings', '<card>', factory)`, where `factory` returns the card widget. Cards show in rank order, and the card of a disabled or uninstalled extension is absent
|
|
82
|
+
- The command `audio:player` drives the container player and returns its state: `play` with a `path` relative to the Jupyter root queues an mp3 or wav file and starts it when nothing plays, `mode: "now"` starts it at once, mixed with every file already playing, `pause` and `resume` stop and continue every playing file at its position, `stop` ends every playing file and keeps the queue, `clear` removes the queue, and `status` reports `paused`, `stopped`, `playing` with ids and positions, and `queue`. A missing or undecodable file, a path outside the root or an unknown action is refused with the reason and changes nothing. The palette entry **Stop All Audio** in category **Audio** runs the command with `{"action": "stop"}`. From a terminal: `jupyterlab_audio player play <file>` queues the file, `jupyterlab_audio player play <file> --now` plays it mixed with every playing file, `jupyterlab_audio player status` reports the state, and `jupyterlab_audio player pause`, `resume`, `stop` and `clear` control it. Every player command works without a tab, but sound is heard only while a JupyterLab tab is open. `jupyterlab_audio player stop` ends playback and leaves the PulseAudio daemon; the top-level `jupyterlab_audio stop` kills the daemon
|
|
83
|
+
- The commands `audio:enable` (label **Enable Audio Capture**) and `audio:disable` (label **Disable Audio Capture**) start capture in the tab that runs `audio:enable` and stop capture in every open tab, for terminal programs such as Claude Code `/voice`. `audio:enable` returns once capture streams, fails with the error message (for example `Microphone permission denied.`) when capture turns to Error, and does nothing when capture already streams; `audio:disable` does nothing when capture is already off. From a terminal: `jupyterlab-commands execute audio:enable`, which runs only after the command is added to the `allowedCommands` setting
|
|
82
84
|
|
|
83
85
|
## Agent skill
|
|
84
86
|
|
|
85
|
-
The skill in `.agents/skills/jupyterlab-audio-extension` tells an AI agent how to play a sound in the JupyterLab browser tab and where the help of `jupyterlab_audio` is. `pip install` puts a copy in `<sys.prefix>/share/jupyter/agents/skills/jupyterlab-audio-extension`.
|
|
87
|
+
The skill in `.agents/skills/jupyterlab-audio-extension` tells an AI agent how to play a sound in the JupyterLab browser tab through the `jupyterlab_audio player` CLI, including the queue and mixed play, and where the help of `jupyterlab_audio` is. `pip install` puts a copy in `<sys.prefix>/share/jupyter/agents/skills/jupyterlab-audio-extension`.
|
|
86
88
|
|
|
87
89
|
## Configuration
|
|
88
90
|
|
package/lib/cards.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IToolbarWidgetRegistry } from '@jupyterlab/apputils';
|
|
2
|
+
import { ISettingRegistry } from '@jupyterlab/settingregistry';
|
|
3
|
+
import { Widget } from '@lumino/widgets';
|
|
4
|
+
/**
|
|
5
|
+
* The extension point of the settings panel (ACC-CTRL-101). Another extension adds a card
|
|
6
|
+
* with "jupyter.lab.toolbars" -> "AudioSettings": [{ "name": <name>, "rank": <rank> }] in its
|
|
7
|
+
* own settings schema and IToolbarWidgetRegistry.addFactory('AudioSettings', <name>, factory),
|
|
8
|
+
* where the factory returns a new card widget. A disabled or uninstalled extension has no
|
|
9
|
+
* schema entry, so its card is absent. The returned function makes the cards anew, in rank
|
|
10
|
+
* order, for one opening of the panel.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createCards(toolbarRegistry: IToolbarWidgetRegistry, settingRegistry: ISettingRegistry): () => Widget;
|
package/lib/cards.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createToolbarFactory } from '@jupyterlab/apputils';
|
|
2
|
+
import { nullTranslator } from '@jupyterlab/translation';
|
|
3
|
+
import { Panel } from '@lumino/widgets';
|
|
4
|
+
/** The settings schema that holds the list of cards (schema/cards.json). */
|
|
5
|
+
const CARDS_PLUGIN_ID = '@stellarshenson/jupyterlab-audio-extension:cards';
|
|
6
|
+
/**
|
|
7
|
+
* The extension point of the settings panel (ACC-CTRL-101). Another extension adds a card
|
|
8
|
+
* with "jupyter.lab.toolbars" -> "AudioSettings": [{ "name": <name>, "rank": <rank> }] in its
|
|
9
|
+
* own settings schema and IToolbarWidgetRegistry.addFactory('AudioSettings', <name>, factory),
|
|
10
|
+
* where the factory returns a new card widget. A disabled or uninstalled extension has no
|
|
11
|
+
* schema entry, so its card is absent. The returned function makes the cards anew, in rank
|
|
12
|
+
* order, for one opening of the panel.
|
|
13
|
+
*/
|
|
14
|
+
export function createCards(toolbarRegistry, settingRegistry) {
|
|
15
|
+
const factory = createToolbarFactory(toolbarRegistry, settingRegistry, 'AudioSettings', CARDS_PLUGIN_ID, nullTranslator);
|
|
16
|
+
return () => {
|
|
17
|
+
// A plain panel, not a Toolbar: the toolbar element takes the arrow keys and the tab
|
|
18
|
+
// stops of the controls inside it.
|
|
19
|
+
const cards = new Panel();
|
|
20
|
+
const items = factory(cards);
|
|
21
|
+
const fill = () => {
|
|
22
|
+
for (const item of items) {
|
|
23
|
+
cards.addWidget(item.widget);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
// The list changes when the settings load after the panel opened.
|
|
27
|
+
items.changed.connect((_, change) => {
|
|
28
|
+
change.oldValues.forEach(item => (item.widget.parent = null));
|
|
29
|
+
fill();
|
|
30
|
+
});
|
|
31
|
+
fill();
|
|
32
|
+
return cards;
|
|
33
|
+
};
|
|
34
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { ICommandPalette } from '@jupyterlab/apputils';
|
|
1
|
+
import { ICommandPalette, IToolbarWidgetRegistry, createToolbarFactory, setToolbar } from '@jupyterlab/apputils';
|
|
2
2
|
import { URLExt } from '@jupyterlab/coreutils';
|
|
3
3
|
import { ServerConnection } from '@jupyterlab/services';
|
|
4
4
|
import { ISettingRegistry } from '@jupyterlab/settingregistry';
|
|
5
5
|
import { IStatusBar } from '@jupyterlab/statusbar';
|
|
6
|
+
import { nullTranslator } from '@jupyterlab/translation';
|
|
7
|
+
import { Toolbar } from '@jupyterlab/ui-components';
|
|
6
8
|
// eslint-disable-next-line jupyter/prefer-lazy-imports -- activate() creates the model at once; AudioCapture is needed for the status item
|
|
7
9
|
import { CONNECT_TIMEOUT_MS, AudioCapture } from './audio-capture';
|
|
10
|
+
import { createCards } from './cards';
|
|
8
11
|
// eslint-disable-next-line jupyter/prefer-lazy-imports -- activate() registers the status item at once
|
|
9
12
|
import { VoiceStatus } from './status';
|
|
10
13
|
const PLUGIN_ID = '@stellarshenson/jupyterlab-audio-extension:plugin';
|
|
@@ -20,8 +23,13 @@ const plugin = {
|
|
|
20
23
|
id: PLUGIN_ID,
|
|
21
24
|
description: "JupyterLab extension that captures microphone audio in the browser and streams it to a server-side bridge, exposing it as a virtual audio source so terminal applications running in the container (such as Claude Code voice mode) can record from the user's microphone",
|
|
22
25
|
autoStart: true,
|
|
23
|
-
optional: [
|
|
24
|
-
|
|
26
|
+
optional: [
|
|
27
|
+
ICommandPalette,
|
|
28
|
+
IStatusBar,
|
|
29
|
+
ISettingRegistry,
|
|
30
|
+
IToolbarWidgetRegistry
|
|
31
|
+
],
|
|
32
|
+
activate: (app, palette, statusBar, settingRegistry, toolbarRegistry) => {
|
|
25
33
|
console.log('JupyterLab extension @stellarshenson/jupyterlab-audio-extension is activated!');
|
|
26
34
|
// Playback is always on: this tab plays the container's default PulseAudio sink.
|
|
27
35
|
const speaker = import('./speaker').then(async ({ Speaker }) => {
|
|
@@ -64,7 +72,8 @@ const plugin = {
|
|
|
64
72
|
execute: async (args) => {
|
|
65
73
|
const settings = app.serviceManager.serverSettings;
|
|
66
74
|
const response = await ServerConnection.makeRequest(URLExt.join(settings.baseUrl, 'jupyterlab-audio-extension', 'player'), { method: 'POST', body: JSON.stringify(args) }, settings);
|
|
67
|
-
|
|
75
|
+
// An error from outside the route (extension disabled, a proxy) has no JSON body.
|
|
76
|
+
const state = await response.json().catch(() => ({}));
|
|
68
77
|
if (!response.ok) {
|
|
69
78
|
throw new Error(state.message || `audio:player failed: HTTP ${response.status}`);
|
|
70
79
|
}
|
|
@@ -132,9 +141,23 @@ const plugin = {
|
|
|
132
141
|
category: 'Audio'
|
|
133
142
|
});
|
|
134
143
|
}
|
|
144
|
+
// Other extensions fill the pill's slot through "jupyter.lab.toolbars" -> "AudioStatus".
|
|
145
|
+
// The factory registers the settings transform without which the load below fails.
|
|
146
|
+
const slotFactory = toolbarRegistry && settingRegistry
|
|
147
|
+
? createToolbarFactory(toolbarRegistry, settingRegistry, 'AudioStatus', PLUGIN_ID, nullTranslator)
|
|
148
|
+
: null;
|
|
135
149
|
if (statusBar) {
|
|
150
|
+
const slot = slotFactory ? new Toolbar() : undefined;
|
|
151
|
+
const status = new VoiceStatus(model, app.serviceManager.serverSettings, slot,
|
|
152
|
+
// Other extensions add cards to the gear's panel through "AudioSettings".
|
|
153
|
+
toolbarRegistry && settingRegistry
|
|
154
|
+
? createCards(toolbarRegistry, settingRegistry)
|
|
155
|
+
: undefined);
|
|
156
|
+
if (slotFactory) {
|
|
157
|
+
setToolbar(status, slotFactory, slot);
|
|
158
|
+
}
|
|
136
159
|
statusBar.registerStatusItem('jupyterlab_audio_extension:status', {
|
|
137
|
-
item:
|
|
160
|
+
item: status,
|
|
138
161
|
align: 'left',
|
|
139
162
|
rank: 100
|
|
140
163
|
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Widget } from '@lumino/widgets';
|
|
2
|
+
/** The audio card's rows: what each value states. */
|
|
3
|
+
declare const ROWS: {
|
|
4
|
+
microphone: string;
|
|
5
|
+
playback: string;
|
|
6
|
+
delivery: string;
|
|
7
|
+
};
|
|
8
|
+
/** The audio extension's state, one plain phrase per row of the audio card. */
|
|
9
|
+
export type AudioSummary = Record<keyof typeof ROWS, string>;
|
|
10
|
+
/**
|
|
11
|
+
* The body of the panel the pill's gear opens (ACC-CTRL-99): the audio card, which states the
|
|
12
|
+
* audio extension's state and holds no settings (ACC-CTRL-100), then the cards other
|
|
13
|
+
* extensions add (ACC-CTRL-101).
|
|
14
|
+
*/
|
|
15
|
+
export declare class AudioSettings extends Widget {
|
|
16
|
+
constructor(cards?: Widget);
|
|
17
|
+
/** Writes the audio card's values. */
|
|
18
|
+
summarise(summary: AudioSummary): void;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
package/lib/settings.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { PanelLayout, Widget } from '@lumino/widgets';
|
|
2
|
+
/** The audio card's rows: what each value states. */
|
|
3
|
+
const ROWS = {
|
|
4
|
+
microphone: 'Microphone',
|
|
5
|
+
playback: 'Playback',
|
|
6
|
+
delivery: 'Captured audio goes to'
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The body of the panel the pill's gear opens (ACC-CTRL-99): the audio card, which states the
|
|
10
|
+
* audio extension's state and holds no settings (ACC-CTRL-100), then the cards other
|
|
11
|
+
* extensions add (ACC-CTRL-101).
|
|
12
|
+
*/
|
|
13
|
+
export class AudioSettings extends Widget {
|
|
14
|
+
constructor(cards) {
|
|
15
|
+
super();
|
|
16
|
+
this.addClass('jp-AudioSettings');
|
|
17
|
+
this.node.setAttribute('role', 'dialog');
|
|
18
|
+
// eslint-disable-next-line jupyter/no-untranslated-string -- no translator, as in index.ts
|
|
19
|
+
this.node.setAttribute('aria-label', 'Audio settings');
|
|
20
|
+
// Takes the focus when the panel opens, so Escape reaches the panel.
|
|
21
|
+
this.node.tabIndex = -1;
|
|
22
|
+
const card = document.createElement('section');
|
|
23
|
+
card.className = 'jp-AudioSettings-card';
|
|
24
|
+
const header = document.createElement('header');
|
|
25
|
+
header.className = 'jp-AudioSettings-cardHeader';
|
|
26
|
+
// eslint-disable-next-line jupyter/no-untranslated-string -- no translator, as in index.ts
|
|
27
|
+
header.textContent = 'Audio';
|
|
28
|
+
card.appendChild(header);
|
|
29
|
+
for (const [key, text] of Object.entries(ROWS)) {
|
|
30
|
+
const row = document.createElement('div');
|
|
31
|
+
row.className = 'jp-AudioSettings-row';
|
|
32
|
+
const label = document.createElement('span');
|
|
33
|
+
label.className = 'jp-AudioSettings-label';
|
|
34
|
+
label.textContent = text;
|
|
35
|
+
const value = document.createElement('span');
|
|
36
|
+
value.className = 'jp-AudioSettings-value';
|
|
37
|
+
value.dataset.vcSummary = key;
|
|
38
|
+
row.append(label, value);
|
|
39
|
+
card.appendChild(row);
|
|
40
|
+
}
|
|
41
|
+
if (cards) {
|
|
42
|
+
cards.addClass('jp-AudioSettings-cards');
|
|
43
|
+
// The layout delivers the attach messages the cards render on.
|
|
44
|
+
const layout = new PanelLayout();
|
|
45
|
+
this.layout = layout;
|
|
46
|
+
layout.addWidget(cards);
|
|
47
|
+
}
|
|
48
|
+
// The audio card is the first card: the layout put the others at the start of the node.
|
|
49
|
+
this.node.prepend(card);
|
|
50
|
+
}
|
|
51
|
+
/** Writes the audio card's values. */
|
|
52
|
+
summarise(summary) {
|
|
53
|
+
for (const [key, text] of Object.entries(summary)) {
|
|
54
|
+
this.node.querySelector(`[data-vc-summary="${key}"]`).textContent = text;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
package/lib/status.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare const micIcon: LabIcon;
|
|
|
6
6
|
export declare const playIcon: LabIcon;
|
|
7
7
|
export declare const pauseIcon: LabIcon;
|
|
8
8
|
export declare const stopIcon: LabIcon;
|
|
9
|
+
export declare const gearIcon: LabIcon;
|
|
9
10
|
/**
|
|
10
11
|
* Status-bar pill: an audio-system lamp, the microphone toggle, a play/stop control and a
|
|
11
12
|
* pause control between hairline dividers. The lamp is the leading child and reports the
|
|
@@ -14,15 +15,29 @@ export declare const stopIcon: LabIcon;
|
|
|
14
15
|
* guide in its tooltip. The player state is polled every 2 s; a click applies the response
|
|
15
16
|
* at once so the faces change without waiting. A missing sink blinks the lamp amber for
|
|
16
17
|
* 30 s, then settles it to the off ring with both controls disabled and the plain message
|
|
17
|
-
* left in the play tooltip; a deliberate shutdown shows the ring at once.
|
|
18
|
+
* left in the play tooltip; a deliberate shutdown shows the ring at once. An optional slot,
|
|
19
|
+
* the AudioStatus toolbar that other extensions fill, sits right of the microphone. The gear
|
|
20
|
+
* is the last control: it opens the settings panel above itself, and a second click, Escape
|
|
21
|
+
* or a click outside the panel closes it (ACC-CTRL-99).
|
|
18
22
|
*/
|
|
19
23
|
export declare class VoiceStatus extends Widget {
|
|
20
|
-
constructor(model: AudioCapture, settings: ServerConnection.ISettings);
|
|
24
|
+
constructor(model: AudioCapture, settings: ServerConnection.ISettings, slot?: Widget, cards?: () => Widget);
|
|
21
25
|
dispose(): void;
|
|
22
26
|
private _createMic;
|
|
23
27
|
private _createControl;
|
|
28
|
+
/** The gear is a widget because the status bar popup anchors to one. */
|
|
29
|
+
private _createGear;
|
|
24
30
|
private _divider;
|
|
31
|
+
/**
|
|
32
|
+
* Puts the slot right of the microphone (ACC-CTRL-96). The slot and its divider show only
|
|
33
|
+
* while an item shows: an item with an unregistered command is hidden by the platform.
|
|
34
|
+
*/
|
|
35
|
+
private _addSlot;
|
|
25
36
|
private _onMic;
|
|
37
|
+
/** Opens the settings panel above the gear, or closes the open one (ACC-CTRL-99). */
|
|
38
|
+
private _onGear;
|
|
39
|
+
/** Writes the audio extension's state into the open panel's audio card (ACC-CTRL-100). */
|
|
40
|
+
private _summarise;
|
|
26
41
|
private _refresh;
|
|
27
42
|
private _render;
|
|
28
43
|
/** Paints the leading lamp: amber fault during the blink, then the off ring; green while active. */
|
|
@@ -40,6 +55,12 @@ export declare class VoiceStatus extends Widget {
|
|
|
40
55
|
private _mic;
|
|
41
56
|
private _play;
|
|
42
57
|
private _pause;
|
|
58
|
+
private _gear;
|
|
59
|
+
private _cards?;
|
|
60
|
+
private _popup;
|
|
61
|
+
private _panel;
|
|
62
|
+
private _capture?;
|
|
63
|
+
private _slotObserver;
|
|
43
64
|
private _mode;
|
|
44
65
|
private _sink;
|
|
45
66
|
private _timer;
|
package/lib/status.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { URLExt } from '@jupyterlab/coreutils';
|
|
2
2
|
import { ServerConnection } from '@jupyterlab/services';
|
|
3
|
+
import { showPopup } from '@jupyterlab/statusbar';
|
|
3
4
|
import { LabIcon } from '@jupyterlab/ui-components';
|
|
4
|
-
import { Widget } from '@lumino/widgets';
|
|
5
|
+
import { PanelLayout, Widget } from '@lumino/widgets';
|
|
6
|
+
import { AudioSettings } from './settings';
|
|
5
7
|
const STATUS_POLL_MS = 2000;
|
|
6
8
|
// The missing-sink episode blinks for this long, then the lamp settles to the off ring.
|
|
7
9
|
const BLINK_MS = 30000;
|
|
@@ -20,6 +22,9 @@ const PAUSE_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" f
|
|
|
20
22
|
const STOP_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
|
21
23
|
<path d="M6 6h12v12H6z"/>
|
|
22
24
|
</svg>`;
|
|
25
|
+
const GEAR_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
|
26
|
+
<path d="M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"/>
|
|
27
|
+
</svg>`;
|
|
23
28
|
export const micIcon = new LabIcon({
|
|
24
29
|
name: 'audio:mic',
|
|
25
30
|
svgstr: MIC_SVG
|
|
@@ -36,6 +41,10 @@ export const stopIcon = new LabIcon({
|
|
|
36
41
|
name: 'audio:stop',
|
|
37
42
|
svgstr: STOP_SVG
|
|
38
43
|
});
|
|
44
|
+
export const gearIcon = new LabIcon({
|
|
45
|
+
name: 'audio:gear',
|
|
46
|
+
svgstr: GEAR_SVG
|
|
47
|
+
});
|
|
39
48
|
const LABELS = {
|
|
40
49
|
idle: 'Disconnected',
|
|
41
50
|
connecting: 'Connecting',
|
|
@@ -54,6 +63,19 @@ const PLAY_LABELS = {
|
|
|
54
63
|
idle: 'Play'
|
|
55
64
|
};
|
|
56
65
|
const PAUSE_LABEL = 'Pause';
|
|
66
|
+
const GEAR_LABEL = 'Audio settings';
|
|
67
|
+
/** The audio card's words for the microphone and for playback (ACC-CTRL-100). */
|
|
68
|
+
const CAPTURE_WORDS = {
|
|
69
|
+
idle: 'Not capturing',
|
|
70
|
+
connecting: 'Connecting',
|
|
71
|
+
streaming: 'Capturing',
|
|
72
|
+
error: 'Error'
|
|
73
|
+
};
|
|
74
|
+
const PLAYER_WORDS = {
|
|
75
|
+
playing: 'Playing',
|
|
76
|
+
paused: 'Paused',
|
|
77
|
+
idle: 'Nothing playing'
|
|
78
|
+
};
|
|
57
79
|
/**
|
|
58
80
|
* Status-bar pill: an audio-system lamp, the microphone toggle, a play/stop control and a
|
|
59
81
|
* pause control between hairline dividers. The lamp is the leading child and reports the
|
|
@@ -62,26 +84,65 @@ const PAUSE_LABEL = 'Pause';
|
|
|
62
84
|
* guide in its tooltip. The player state is polled every 2 s; a click applies the response
|
|
63
85
|
* at once so the faces change without waiting. A missing sink blinks the lamp amber for
|
|
64
86
|
* 30 s, then settles it to the off ring with both controls disabled and the plain message
|
|
65
|
-
* left in the play tooltip; a deliberate shutdown shows the ring at once.
|
|
87
|
+
* left in the play tooltip; a deliberate shutdown shows the ring at once. An optional slot,
|
|
88
|
+
* the AudioStatus toolbar that other extensions fill, sits right of the microphone. The gear
|
|
89
|
+
* is the last control: it opens the settings panel above itself, and a second click, Escape
|
|
90
|
+
* or a click outside the panel closes it (ACC-CTRL-99).
|
|
66
91
|
*/
|
|
67
92
|
export class VoiceStatus extends Widget {
|
|
68
|
-
constructor(model, settings) {
|
|
93
|
+
constructor(model, settings, slot, cards) {
|
|
69
94
|
super();
|
|
70
95
|
this._onMic = () => {
|
|
71
96
|
this._model.toggle();
|
|
72
97
|
};
|
|
98
|
+
/** Opens the settings panel above the gear, or closes the open one (ACC-CTRL-99). */
|
|
99
|
+
this._onGear = () => {
|
|
100
|
+
var _a;
|
|
101
|
+
if (this._popup) {
|
|
102
|
+
this._popup.dispose();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const gear = this._gear.node;
|
|
106
|
+
const panel = new AudioSettings((_a = this._cards) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
107
|
+
this._panel = panel;
|
|
108
|
+
this._summarise();
|
|
109
|
+
// The popup closes itself on Escape and on a click outside the panel and the gear.
|
|
110
|
+
const popup = showPopup({
|
|
111
|
+
body: panel,
|
|
112
|
+
anchor: this._gear,
|
|
113
|
+
align: 'left',
|
|
114
|
+
// A card that loads its content after the panel opened makes the panel taller.
|
|
115
|
+
hasDynamicSize: true
|
|
116
|
+
});
|
|
117
|
+
this._popup = popup;
|
|
118
|
+
gear.setAttribute('aria-expanded', 'true');
|
|
119
|
+
popup.disposed.connect(() => {
|
|
120
|
+
// Escape closes the panel that holds the focus: the gear takes the focus back.
|
|
121
|
+
if (popup.node.contains(document.activeElement)) {
|
|
122
|
+
gear.focus();
|
|
123
|
+
}
|
|
124
|
+
gear.setAttribute('aria-expanded', 'false');
|
|
125
|
+
this._popup = null;
|
|
126
|
+
this._panel = null;
|
|
127
|
+
});
|
|
128
|
+
panel.node.focus();
|
|
129
|
+
};
|
|
73
130
|
this._onPlay = () => {
|
|
74
131
|
void this._request(this._mode === 'paused' ? 'resume' : 'stop');
|
|
75
132
|
};
|
|
76
133
|
this._onPause = () => {
|
|
77
134
|
void this._request('pause');
|
|
78
135
|
};
|
|
136
|
+
this._popup = null;
|
|
137
|
+
this._panel = null;
|
|
138
|
+
this._slotObserver = null;
|
|
79
139
|
this._mode = 'idle';
|
|
80
140
|
this._sink = 'ready';
|
|
81
141
|
this._blinkTimer = null;
|
|
82
142
|
this._blinkDone = false;
|
|
83
143
|
this._model = model;
|
|
84
144
|
this._settings = settings;
|
|
145
|
+
this._cards = cards;
|
|
85
146
|
this.addClass('jp-Audio-status');
|
|
86
147
|
this.addClass('jp-Audio-pill');
|
|
87
148
|
this._lamp = document.createElement('span');
|
|
@@ -90,6 +151,7 @@ export class VoiceStatus extends Widget {
|
|
|
90
151
|
this._mic = this._createMic();
|
|
91
152
|
this._play = this._createControl('play');
|
|
92
153
|
this._pause = this._createControl('pause');
|
|
154
|
+
this._gear = this._createGear();
|
|
93
155
|
this.node.appendChild(this._lamp);
|
|
94
156
|
this.node.appendChild(this._divider());
|
|
95
157
|
this.node.appendChild(this._mic);
|
|
@@ -97,6 +159,11 @@ export class VoiceStatus extends Widget {
|
|
|
97
159
|
this.node.appendChild(this._play);
|
|
98
160
|
this.node.appendChild(this._divider());
|
|
99
161
|
this.node.appendChild(this._pause);
|
|
162
|
+
this.node.appendChild(this._divider());
|
|
163
|
+
this.node.appendChild(this._gear.node);
|
|
164
|
+
if (slot) {
|
|
165
|
+
this._addSlot(slot);
|
|
166
|
+
}
|
|
100
167
|
model.stateChanged.connect(this._refresh, this);
|
|
101
168
|
this._refresh();
|
|
102
169
|
this._render('idle');
|
|
@@ -104,7 +171,10 @@ export class VoiceStatus extends Widget {
|
|
|
104
171
|
this._timer = window.setInterval(() => void this._request('status'), STATUS_POLL_MS);
|
|
105
172
|
}
|
|
106
173
|
dispose() {
|
|
174
|
+
var _a, _b;
|
|
107
175
|
window.clearInterval(this._timer);
|
|
176
|
+
(_a = this._popup) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
177
|
+
(_b = this._slotObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
|
|
108
178
|
this._stopBlink();
|
|
109
179
|
this._model.stateChanged.disconnect(this._refresh, this);
|
|
110
180
|
super.dispose();
|
|
@@ -137,11 +207,74 @@ export class VoiceStatus extends Widget {
|
|
|
137
207
|
}
|
|
138
208
|
return button;
|
|
139
209
|
}
|
|
210
|
+
/** The gear is a widget because the status bar popup anchors to one. */
|
|
211
|
+
_createGear() {
|
|
212
|
+
const button = document.createElement('button');
|
|
213
|
+
button.type = 'button';
|
|
214
|
+
button.className = 'jp-Audio-control jp-Audio-gear';
|
|
215
|
+
button.dataset.vcControl = 'gear';
|
|
216
|
+
button.title = GEAR_LABEL;
|
|
217
|
+
button.setAttribute('aria-label', GEAR_LABEL);
|
|
218
|
+
button.setAttribute('aria-haspopup', 'dialog');
|
|
219
|
+
button.setAttribute('aria-expanded', 'false');
|
|
220
|
+
const icon = document.createElement('span');
|
|
221
|
+
icon.className = 'jp-Audio-icon';
|
|
222
|
+
button.appendChild(icon);
|
|
223
|
+
gearIcon.element({ container: icon });
|
|
224
|
+
button.addEventListener('click', this._onGear);
|
|
225
|
+
return new Widget({ node: button });
|
|
226
|
+
}
|
|
140
227
|
_divider() {
|
|
141
228
|
const divider = document.createElement('span');
|
|
142
229
|
divider.className = 'jp-Audio-divider';
|
|
143
230
|
return divider;
|
|
144
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Puts the slot right of the microphone (ACC-CTRL-96). The slot and its divider show only
|
|
234
|
+
* while an item shows: an item with an unregistered command is hidden by the platform.
|
|
235
|
+
*/
|
|
236
|
+
_addSlot(slot) {
|
|
237
|
+
const divider = this._divider();
|
|
238
|
+
slot.addClass('jp-Audio-slot');
|
|
239
|
+
// The layout delivers the attach messages on which toolbar buttons render.
|
|
240
|
+
const layout = new PanelLayout();
|
|
241
|
+
this.layout = layout;
|
|
242
|
+
layout.addWidget(slot);
|
|
243
|
+
this._mic.after(slot.node);
|
|
244
|
+
const sync = () => {
|
|
245
|
+
const shown = Array.from(slot.children()).some(item => !item.isHidden && !item.hasClass('lm-mod-hidden'));
|
|
246
|
+
if (shown) {
|
|
247
|
+
this._mic.after(divider);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
divider.remove();
|
|
251
|
+
}
|
|
252
|
+
slot.setHidden(!shown);
|
|
253
|
+
};
|
|
254
|
+
this._slotObserver = new MutationObserver(sync);
|
|
255
|
+
this._slotObserver.observe(slot.node, {
|
|
256
|
+
childList: true,
|
|
257
|
+
subtree: true,
|
|
258
|
+
attributeFilter: ['class']
|
|
259
|
+
});
|
|
260
|
+
sync();
|
|
261
|
+
}
|
|
262
|
+
/** Writes the audio extension's state into the open panel's audio card (ACC-CTRL-100). */
|
|
263
|
+
_summarise() {
|
|
264
|
+
var _a;
|
|
265
|
+
const state = this._model.state;
|
|
266
|
+
(_a = this._panel) === null || _a === void 0 ? void 0 : _a.summarise({
|
|
267
|
+
microphone: state === 'error'
|
|
268
|
+
? this._model.message || CAPTURE_WORDS.error
|
|
269
|
+
: CAPTURE_WORDS[state],
|
|
270
|
+
playback: this._sink === 'missing'
|
|
271
|
+
? SINK_UNAVAILABLE
|
|
272
|
+
: this._sink === 'off'
|
|
273
|
+
? SINK_SHUT_DOWN
|
|
274
|
+
: PLAYER_WORDS[this._mode],
|
|
275
|
+
delivery: this._capture || 'Unknown'
|
|
276
|
+
});
|
|
277
|
+
}
|
|
145
278
|
_refresh() {
|
|
146
279
|
const state = this._model.state;
|
|
147
280
|
this.removeClass('jp-mod-idle');
|
|
@@ -156,6 +289,7 @@ export class VoiceStatus extends Widget {
|
|
|
156
289
|
this._mic.title = tooltip;
|
|
157
290
|
this._mic.setAttribute('aria-label', tooltip);
|
|
158
291
|
this._paintLamp();
|
|
292
|
+
this._summarise();
|
|
159
293
|
}
|
|
160
294
|
_render(mode, sink) {
|
|
161
295
|
this._mode = mode;
|
|
@@ -191,6 +325,7 @@ export class VoiceStatus extends Widget {
|
|
|
191
325
|
this._paintLamp();
|
|
192
326
|
this._applyControls();
|
|
193
327
|
this.node.dataset.vcPlayer = mode;
|
|
328
|
+
this._summarise();
|
|
194
329
|
}
|
|
195
330
|
/** Paints the leading lamp: amber fault during the blink, then the off ring; green while active. */
|
|
196
331
|
_paintLamp() {
|
|
@@ -237,11 +372,14 @@ export class VoiceStatus extends Widget {
|
|
|
237
372
|
}
|
|
238
373
|
async _request(action) {
|
|
239
374
|
try {
|
|
240
|
-
const response = await ServerConnection.makeRequest(URLExt.join(this._settings.baseUrl, 'jupyterlab-audio-extension', 'player'
|
|
375
|
+
const response = await ServerConnection.makeRequest(URLExt.join(this._settings.baseUrl, 'jupyterlab-audio-extension', 'player'
|
|
376
|
+
// A poll is not user activity: it must not hold off the server's idle shutdown.
|
|
377
|
+
) + (action === 'status' ? '?no_track_activity=1' : ''), { method: 'POST', body: JSON.stringify({ action }) }, this._settings);
|
|
241
378
|
if (!response.ok) {
|
|
242
379
|
return; // a failed poll keeps the last state; the next poll retries
|
|
243
380
|
}
|
|
244
381
|
const state = (await response.json());
|
|
382
|
+
this._capture = state.capture;
|
|
245
383
|
this._render(state.paused ? 'paused' : state.playing.length > 0 ? 'playing' : 'idle', state.sink);
|
|
246
384
|
}
|
|
247
385
|
catch (_a) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stellarshenson/jupyterlab-audio-extension",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.42",
|
|
4
4
|
"description": "JupyterLab extension that captures microphone audio in the browser and streams it to a server-side bridge, exposing it as a virtual audio source so terminal applications running in the container (such as Claude Code voice mode) can record from the user's microphone",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jupyter",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"@jupyterlab/services": "^7.6.0",
|
|
64
64
|
"@jupyterlab/settingregistry": "^4.6.0",
|
|
65
65
|
"@jupyterlab/statusbar": "^4.6.0",
|
|
66
|
+
"@jupyterlab/translation": "^4.6.5",
|
|
66
67
|
"@jupyterlab/ui-components": "^4.6.0",
|
|
67
68
|
"@lumino/signaling": "^2.1.0",
|
|
68
69
|
"@lumino/widgets": "^2.10.0"
|
|
@@ -151,6 +152,7 @@
|
|
|
151
152
|
],
|
|
152
153
|
"rules": {
|
|
153
154
|
"csstree/validator": true,
|
|
155
|
+
"custom-property-pattern": "^([a-z][A-z\\d]*)(-[A-z\\d]+)*$",
|
|
154
156
|
"property-no-vendor-prefix": null,
|
|
155
157
|
"selector-class-pattern": "^([a-z][A-z\\d]*)(-[A-z\\d]+)*$",
|
|
156
158
|
"selector-no-vendor-prefix": null,
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"jupyter.lab.setting-icon": "audio:mic",
|
|
3
|
+
"jupyter.lab.setting-icon-label": "Audio Settings Panel",
|
|
4
|
+
"title": "Audio Settings Panel",
|
|
5
|
+
"description": "Cards in the panel that the gear of the status-bar audio pill opens.",
|
|
6
|
+
"jupyter.lab.toolbars": {
|
|
7
|
+
"AudioSettings": []
|
|
8
|
+
},
|
|
9
|
+
"jupyter.lab.transform": true,
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"toolbar": {
|
|
13
|
+
"title": "Audio settings panel cards",
|
|
14
|
+
"description": "Cards in the audio settings panel, after the audio card, in rank order. Other extensions add them through \"jupyter.lab.toolbars\" -> \"AudioSettings\" in their own settings schema. To hide a card, copy it to User Preferences and add \"disabled\": true.",
|
|
15
|
+
"items": {
|
|
16
|
+
"$ref": "#/definitions/card"
|
|
17
|
+
},
|
|
18
|
+
"type": "array",
|
|
19
|
+
"default": []
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"additionalProperties": false,
|
|
23
|
+
"definitions": {
|
|
24
|
+
"card": {
|
|
25
|
+
"properties": {
|
|
26
|
+
"name": {
|
|
27
|
+
"title": "Unique name",
|
|
28
|
+
"type": "string"
|
|
29
|
+
},
|
|
30
|
+
"disabled": {
|
|
31
|
+
"title": "Whether the card is ignored or not",
|
|
32
|
+
"type": "boolean",
|
|
33
|
+
"default": false
|
|
34
|
+
},
|
|
35
|
+
"rank": {
|
|
36
|
+
"title": "Card rank",
|
|
37
|
+
"type": "number",
|
|
38
|
+
"minimum": 0,
|
|
39
|
+
"default": 50
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"required": ["name"],
|
|
43
|
+
"additionalProperties": true,
|
|
44
|
+
"type": "object"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|