@corti/dictation-web 0.0.0-test.562 → 0.0.0-test.571
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 +164 -112
- package/dist/bundle.js +1416 -546
- package/dist/components/audio-visualiser.d.ts +3 -2
- package/dist/components/audio-visualiser.js +15 -12
- package/dist/components/audio-visualiser.js.map +1 -1
- package/dist/components/corti-dictation.d.ts +26 -13
- package/dist/components/corti-dictation.js +70 -21
- package/dist/components/corti-dictation.js.map +1 -1
- package/dist/components/device-selector.d.ts +6 -16
- package/dist/components/device-selector.js +27 -58
- package/dist/components/device-selector.js.map +1 -1
- package/dist/components/keybinding-selector.d.ts +14 -0
- package/dist/components/keybinding-selector.js +81 -0
- package/dist/components/keybinding-selector.js.map +1 -0
- package/dist/components/language-selector.d.ts +8 -17
- package/dist/components/language-selector.js +26 -52
- package/dist/components/language-selector.js.map +1 -1
- package/dist/components/mode-selector.d.ts +14 -0
- package/dist/components/mode-selector.js +73 -0
- package/dist/components/mode-selector.js.map +1 -0
- package/dist/components/recording-button.d.ts +8 -14
- package/dist/components/recording-button.js +155 -96
- package/dist/components/recording-button.js.map +1 -1
- package/dist/components/settings-menu.d.ts +4 -2
- package/dist/components/settings-menu.js +34 -14
- package/dist/components/settings-menu.js.map +1 -1
- package/dist/constants.d.ts +5 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -1
- package/dist/contexts/dictation-context.d.ts +24 -14
- package/dist/contexts/dictation-context.js +128 -46
- package/dist/contexts/dictation-context.js.map +1 -1
- package/dist/controllers/devices-controller.d.ts +26 -0
- package/dist/controllers/devices-controller.js +99 -0
- package/dist/controllers/devices-controller.js.map +1 -0
- package/dist/controllers/dictation-controller.d.ts +29 -0
- package/dist/controllers/dictation-controller.js +179 -0
- package/dist/controllers/dictation-controller.js.map +1 -0
- package/dist/controllers/keybinding-controller.d.ts +17 -0
- package/dist/controllers/keybinding-controller.js +80 -0
- package/dist/controllers/keybinding-controller.js.map +1 -0
- package/dist/controllers/languages-controller.d.ts +26 -0
- package/dist/controllers/languages-controller.js +83 -0
- package/dist/controllers/languages-controller.js.map +1 -0
- package/dist/controllers/media-controller.d.ts +24 -0
- package/dist/controllers/media-controller.js +115 -0
- package/dist/controllers/media-controller.js.map +1 -0
- package/dist/index.d.ts +9 -7
- package/dist/index.js +30 -20
- package/dist/index.js.map +1 -1
- package/dist/src/components/audio-visualiser.d.ts +1 -0
- package/dist/src/components/audio-visualiser.js +6 -3
- package/dist/src/components/audio-visualiser.js.map +1 -1
- package/dist/src/components/corti-dictation.d.ts +21 -6
- package/dist/src/components/corti-dictation.js +25 -2
- package/dist/src/components/corti-dictation.js.map +1 -1
- package/dist/src/components/recording-button.d.ts +4 -0
- package/dist/src/components/recording-button.js +34 -10
- package/dist/src/components/recording-button.js.map +1 -1
- package/dist/src/components/settings-menu.js +1 -1
- package/dist/src/components/settings-menu.js.map +1 -1
- package/dist/src/constants.js +24 -6
- package/dist/src/constants.js.map +1 -1
- package/dist/src/contexts/dictation-context.d.ts +19 -5
- package/dist/src/contexts/dictation-context.js +32 -12
- package/dist/src/contexts/dictation-context.js.map +1 -1
- package/dist/src/controllers/DictationController.d.ts +5 -0
- package/dist/src/controllers/DictationController.js +27 -8
- package/dist/src/controllers/DictationController.js.map +1 -1
- package/dist/src/controllers/MediaController.d.ts +6 -0
- package/dist/src/controllers/MediaController.js +17 -1
- package/dist/src/controllers/MediaController.js.map +1 -1
- package/dist/src/styles/ComponentStyles.js +5 -5
- package/dist/src/styles/ComponentStyles.js.map +1 -1
- package/dist/src/styles/audio-visualiser.js +1 -1
- package/dist/src/styles/audio-visualiser.js.map +1 -1
- package/dist/src/styles/buttons.js +12 -12
- package/dist/src/styles/buttons.js.map +1 -1
- package/dist/src/styles/callout.js +7 -7
- package/dist/src/styles/callout.js.map +1 -1
- package/dist/src/styles/select.js +8 -8
- package/dist/src/styles/select.js.map +1 -1
- package/dist/src/styles/settings-menu.js +4 -4
- package/dist/src/styles/settings-menu.js.map +1 -1
- package/dist/src/types.d.ts +5 -0
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/converters.js +4 -1
- package/dist/src/utils/converters.js.map +1 -1
- package/dist/src/utils/events.d.ts +11 -4
- package/dist/src/utils/events.js.map +1 -1
- package/dist/src/utils/languages.js +2 -1
- package/dist/src/utils/languages.js.map +1 -1
- package/dist/src/utils/media.d.ts +1 -1
- package/dist/src/utils/media.js +13 -1
- package/dist/src/utils/media.js.map +1 -1
- package/dist/src/utils/token.d.ts +1 -1
- package/dist/src/utils/token.js +12 -11
- package/dist/src/utils/token.js.map +1 -1
- package/dist/styles/buttons.js +1 -2
- package/dist/styles/buttons.js.map +1 -1
- package/dist/styles/component-styles.d.ts +3 -0
- package/dist/styles/component-styles.js +32 -0
- package/dist/styles/component-styles.js.map +1 -0
- package/dist/styles/keybinding-selector.d.ts +2 -0
- package/dist/styles/keybinding-selector.js +72 -0
- package/dist/styles/keybinding-selector.js.map +1 -0
- package/dist/styles/mode-selector.d.ts +2 -0
- package/dist/styles/mode-selector.js +54 -0
- package/dist/styles/mode-selector.js.map +1 -0
- package/dist/styles/select.d.ts +1 -1
- package/dist/styles/select.js +6 -10
- package/dist/styles/select.js.map +1 -1
- package/dist/styles/settings-menu.js +9 -1
- package/dist/styles/settings-menu.js.map +1 -1
- package/dist/tsconfig.stories.tsbuildinfo +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/events.d.ts +12 -3
- package/dist/utils/events.js +14 -0
- package/dist/utils/events.js.map +1 -1
- package/dist/utils/keybinding.d.ts +49 -0
- package/dist/utils/keybinding.js +140 -0
- package/dist/utils/keybinding.js.map +1 -0
- package/dist/utils/languages.d.ts +4 -3
- package/dist/utils/languages.js.map +1 -1
- package/dist/utils/token.d.ts +1 -1
- package/dist/utils/token.js +12 -11
- package/dist/utils/token.js.map +1 -1
- package/package.json +9 -8
|
@@ -4,40 +4,50 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _DictationRecordingButton_instances, _DictationRecordingButton_mediaController, _DictationRecordingButton_dictationController, _DictationRecordingButton_keybindingController, _DictationRecordingButton_handleMouseDown, _DictationRecordingButton_handleMouseUp, _DictationRecordingButton_handleMouseLeave, _DictationRecordingButton_handleWebSocketMessage, _DictationRecordingButton_handleWebSocketError, _DictationRecordingButton_handleWebSocketClose, _DictationRecordingButton_handleStart, _DictationRecordingButton_handleStop;
|
|
7
13
|
import { consume } from "@lit/context";
|
|
8
14
|
import { html, LitElement } from "lit";
|
|
9
15
|
import { customElement, property, state } from "lit/decorators.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
16
|
+
import { AUDIO_CHUNK_INTERVAL_MS } from "../constants.js";
|
|
17
|
+
import { accessTokenContext, authConfigContext, debugDisplayAudioContext, dictationConfigContext, keybindingContext, modeContext, recordingStateContext, regionContext, selectedDeviceContext, socketProxyContext, socketUrlContext, tenantNameContext, } from "../contexts/dictation-context.js";
|
|
18
|
+
import { DictationController, } from "../controllers/dictation-controller.js";
|
|
19
|
+
import { KeybindingController } from "../controllers/keybinding-controller.js";
|
|
20
|
+
import { MediaController } from "../controllers/media-controller.js";
|
|
13
21
|
import ButtonStyles from "../styles/buttons.js";
|
|
14
22
|
import RecordingButtonStyles from "../styles/recording-button.js";
|
|
15
23
|
import { audioLevelChangedEvent, commandEvent, errorEvent, networkActivityEvent, recordingStateChangedEvent, streamClosedEvent, transcriptEvent, usageEvent, } from "../utils/events.js";
|
|
16
24
|
import "./audio-visualiser.js";
|
|
17
25
|
import "../icons/icons.js";
|
|
18
|
-
let
|
|
26
|
+
let DictationRecordingButton = class DictationRecordingButton extends LitElement {
|
|
19
27
|
constructor() {
|
|
20
28
|
super(...arguments);
|
|
29
|
+
_DictationRecordingButton_instances.add(this);
|
|
21
30
|
this._recordingState = "stopped";
|
|
22
|
-
this.
|
|
23
|
-
this
|
|
24
|
-
this
|
|
25
|
-
this
|
|
31
|
+
this.allowButtonFocus = false;
|
|
32
|
+
_DictationRecordingButton_mediaController.set(this, new MediaController(this));
|
|
33
|
+
_DictationRecordingButton_dictationController.set(this, new DictationController(this));
|
|
34
|
+
_DictationRecordingButton_keybindingController.set(this, new KeybindingController(this));
|
|
35
|
+
_DictationRecordingButton_handleWebSocketMessage.set(this, (message) => {
|
|
26
36
|
switch (message.type) {
|
|
27
37
|
case "CONFIG_ACCEPTED":
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
38
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").mediaRecorder?.start(AUDIO_CHUNK_INTERVAL_MS);
|
|
39
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").startAudioLevelMonitoring((level) => {
|
|
30
40
|
this.dispatchEvent(audioLevelChangedEvent(level));
|
|
31
41
|
});
|
|
32
42
|
this.dispatchEvent(recordingStateChangedEvent("recording"));
|
|
33
43
|
break;
|
|
34
44
|
case "CONFIG_DENIED":
|
|
35
45
|
this.dispatchEvent(errorEvent(`Config denied: ${message.reason ?? "Unknown reason"}`));
|
|
36
|
-
this.
|
|
46
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
37
47
|
break;
|
|
38
48
|
case "CONFIG_TIMEOUT":
|
|
39
49
|
this.dispatchEvent(errorEvent("Config timeout"));
|
|
40
|
-
this.
|
|
50
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
41
51
|
break;
|
|
42
52
|
case "transcript":
|
|
43
53
|
this.dispatchEvent(transcriptEvent(message));
|
|
@@ -50,81 +60,48 @@ let RecordingButton = class RecordingButton extends LitElement {
|
|
|
50
60
|
break;
|
|
51
61
|
case "error":
|
|
52
62
|
this.dispatchEvent(errorEvent(message.error));
|
|
53
|
-
this.
|
|
63
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
54
64
|
break;
|
|
55
65
|
}
|
|
56
|
-
};
|
|
57
|
-
this
|
|
66
|
+
});
|
|
67
|
+
_DictationRecordingButton_handleWebSocketError.set(this, (error) => {
|
|
58
68
|
this.dispatchEvent(errorEvent("Socket error: " + error.message));
|
|
59
|
-
this.
|
|
60
|
-
};
|
|
61
|
-
this
|
|
69
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
70
|
+
});
|
|
71
|
+
_DictationRecordingButton_handleWebSocketClose.set(this, (event) => {
|
|
62
72
|
this.dispatchEvent(streamClosedEvent(event));
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
_handleMouseDown(event) {
|
|
66
|
-
if (this.preventFocus) {
|
|
67
|
-
event.preventDefault();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async _handleStart() {
|
|
71
|
-
this.dispatchEvent(recordingStateChangedEvent("initializing"));
|
|
72
|
-
try {
|
|
73
|
-
await this._mediaController.initialize(() => {
|
|
74
|
-
if (this._recordingState === "recording") {
|
|
75
|
-
this.dispatchEvent(errorEvent("Microphone access was lost."));
|
|
76
|
-
this._handleStop();
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
await this._dictationController.connect(this._mediaController.mediaRecorder, this._dictationConfig, {
|
|
80
|
-
onClose: this._handleWebSocketClose,
|
|
81
|
-
onError: this._handleWebSocketError,
|
|
82
|
-
onMessage: this._handleWebSocketMessage,
|
|
83
|
-
onNetworkActivity: (direction, data) => {
|
|
84
|
-
this.dispatchEvent(networkActivityEvent(direction, data));
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
this.dispatchEvent(errorEvent(error));
|
|
90
|
-
await this._handleStop();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
async _handleStop() {
|
|
94
|
-
this.dispatchEvent(recordingStateChangedEvent("stopping"));
|
|
95
|
-
try {
|
|
96
|
-
this._mediaController.stopAudioLevelMonitoring();
|
|
97
|
-
await this._mediaController.stopRecording();
|
|
98
|
-
await this._dictationController.disconnect(this._handleWebSocketClose);
|
|
99
|
-
await this._mediaController.cleanup();
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
this.dispatchEvent(errorEvent(error));
|
|
103
|
-
}
|
|
104
|
-
this.dispatchEvent(recordingStateChangedEvent("stopped"));
|
|
105
|
-
}
|
|
106
|
-
_handleClick() {
|
|
107
|
-
if (this._recordingState === "stopped") {
|
|
108
|
-
this._handleStart();
|
|
109
|
-
}
|
|
110
|
-
else if (this._recordingState === "recording") {
|
|
111
|
-
this._handleStop();
|
|
112
|
-
}
|
|
73
|
+
});
|
|
113
74
|
}
|
|
114
75
|
startRecording() {
|
|
115
76
|
if (this._recordingState !== "stopped") {
|
|
116
77
|
return;
|
|
117
78
|
}
|
|
118
|
-
this.
|
|
79
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStart).call(this);
|
|
119
80
|
}
|
|
120
81
|
stopRecording() {
|
|
121
|
-
if (this._recordingState
|
|
82
|
+
if (this._recordingState === "stopped") {
|
|
122
83
|
return;
|
|
123
84
|
}
|
|
124
|
-
this.
|
|
85
|
+
if (this._recordingState === "initializing") {
|
|
86
|
+
this.addEventListener("recording-state-changed", (event) => {
|
|
87
|
+
if (event.detail
|
|
88
|
+
.state === "recording") {
|
|
89
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
90
|
+
}
|
|
91
|
+
}, {
|
|
92
|
+
once: true,
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
125
97
|
}
|
|
126
98
|
toggleRecording() {
|
|
127
|
-
this.
|
|
99
|
+
if (this._recordingState === "stopped") {
|
|
100
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStart).call(this);
|
|
101
|
+
}
|
|
102
|
+
else if (this._recordingState === "recording") {
|
|
103
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
104
|
+
}
|
|
128
105
|
}
|
|
129
106
|
render() {
|
|
130
107
|
const isLoading = this._recordingState === "initializing" ||
|
|
@@ -132,72 +109,154 @@ let RecordingButton = class RecordingButton extends LitElement {
|
|
|
132
109
|
const isRecording = this._recordingState === "recording";
|
|
133
110
|
return html `
|
|
134
111
|
<button
|
|
135
|
-
@mousedown=${this
|
|
136
|
-
@
|
|
112
|
+
@mousedown=${__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleMouseDown)}
|
|
113
|
+
@mouseup=${__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleMouseUp)}
|
|
114
|
+
@mouseleave=${__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleMouseLeave)}
|
|
137
115
|
?disabled=${isLoading}
|
|
138
116
|
class=${isRecording ? "red" : "accent"}
|
|
139
117
|
aria-label=${isRecording ? "Stop recording" : "Start recording"}
|
|
140
118
|
aria-pressed=${isRecording}
|
|
141
119
|
>
|
|
142
120
|
${isLoading
|
|
143
|
-
? html `<icon-loading-spinner
|
|
121
|
+
? html `<icon-loading-spinner />`
|
|
144
122
|
: isRecording
|
|
145
|
-
? html `<icon-recording
|
|
146
|
-
: html `<icon-mic-on
|
|
147
|
-
<audio-visualiser
|
|
148
|
-
.level=${this.
|
|
123
|
+
? html `<icon-recording />`
|
|
124
|
+
: html `<icon-mic-on />`}
|
|
125
|
+
<dictation-audio-visualiser
|
|
126
|
+
.level=${__classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").audioLevel}
|
|
149
127
|
?active=${isRecording}
|
|
150
|
-
|
|
128
|
+
/>
|
|
151
129
|
</button>
|
|
152
130
|
`;
|
|
153
131
|
}
|
|
154
132
|
};
|
|
155
|
-
|
|
133
|
+
_DictationRecordingButton_mediaController = new WeakMap();
|
|
134
|
+
_DictationRecordingButton_dictationController = new WeakMap();
|
|
135
|
+
_DictationRecordingButton_keybindingController = new WeakMap();
|
|
136
|
+
_DictationRecordingButton_handleWebSocketMessage = new WeakMap();
|
|
137
|
+
_DictationRecordingButton_handleWebSocketError = new WeakMap();
|
|
138
|
+
_DictationRecordingButton_handleWebSocketClose = new WeakMap();
|
|
139
|
+
_DictationRecordingButton_instances = new WeakSet();
|
|
140
|
+
_DictationRecordingButton_handleMouseDown = function _DictationRecordingButton_handleMouseDown(event) {
|
|
141
|
+
if (!this.allowButtonFocus) {
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
}
|
|
144
|
+
if (this._mode === "push-to-talk") {
|
|
145
|
+
this.startRecording();
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
_DictationRecordingButton_handleMouseUp = function _DictationRecordingButton_handleMouseUp() {
|
|
149
|
+
if (this._mode === "push-to-talk") {
|
|
150
|
+
this.stopRecording();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (this._mode === "toggle-to-talk") {
|
|
154
|
+
this.toggleRecording();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
_DictationRecordingButton_handleMouseLeave = function _DictationRecordingButton_handleMouseLeave() {
|
|
158
|
+
if (this._mode === "push-to-talk") {
|
|
159
|
+
this.stopRecording();
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
_DictationRecordingButton_handleStart = async function _DictationRecordingButton_handleStart() {
|
|
163
|
+
this.dispatchEvent(recordingStateChangedEvent("initializing"));
|
|
164
|
+
try {
|
|
165
|
+
await __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").initialize(() => {
|
|
166
|
+
if (this._recordingState === "recording") {
|
|
167
|
+
this.dispatchEvent(errorEvent("Recording device access was lost."));
|
|
168
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
const isNewConnection = await __classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").connect(__classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").mediaRecorder, this._dictationConfig, {
|
|
172
|
+
onClose: __classPrivateFieldGet(this, _DictationRecordingButton_handleWebSocketClose, "f"),
|
|
173
|
+
onError: __classPrivateFieldGet(this, _DictationRecordingButton_handleWebSocketError, "f"),
|
|
174
|
+
onMessage: __classPrivateFieldGet(this, _DictationRecordingButton_handleWebSocketMessage, "f"),
|
|
175
|
+
onNetworkActivity: (direction, data) => {
|
|
176
|
+
this.dispatchEvent(networkActivityEvent(direction, data));
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
// configuration has been accepted before
|
|
180
|
+
if (!isNewConnection) {
|
|
181
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").mediaRecorder?.start(AUDIO_CHUNK_INTERVAL_MS);
|
|
182
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").startAudioLevelMonitoring((level) => {
|
|
183
|
+
this.dispatchEvent(audioLevelChangedEvent(level));
|
|
184
|
+
});
|
|
185
|
+
this.dispatchEvent(recordingStateChangedEvent("recording"));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
this.dispatchEvent(errorEvent(error));
|
|
190
|
+
await __classPrivateFieldGet(this, _DictationRecordingButton_instances, "m", _DictationRecordingButton_handleStop).call(this);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
_DictationRecordingButton_handleStop = async function _DictationRecordingButton_handleStop() {
|
|
194
|
+
this.dispatchEvent(recordingStateChangedEvent("stopping"));
|
|
195
|
+
try {
|
|
196
|
+
__classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").stopAudioLevelMonitoring();
|
|
197
|
+
await __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").stopRecording();
|
|
198
|
+
await __classPrivateFieldGet(this, _DictationRecordingButton_dictationController, "f").disconnect(__classPrivateFieldGet(this, _DictationRecordingButton_handleWebSocketClose, "f"));
|
|
199
|
+
await __classPrivateFieldGet(this, _DictationRecordingButton_mediaController, "f").cleanup();
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
this.dispatchEvent(errorEvent(error));
|
|
203
|
+
}
|
|
204
|
+
this.dispatchEvent(recordingStateChangedEvent("stopped"));
|
|
205
|
+
};
|
|
206
|
+
DictationRecordingButton.styles = [RecordingButtonStyles, ButtonStyles];
|
|
156
207
|
__decorate([
|
|
157
208
|
consume({ context: recordingStateContext, subscribe: true }),
|
|
158
209
|
state()
|
|
159
|
-
],
|
|
210
|
+
], DictationRecordingButton.prototype, "_recordingState", void 0);
|
|
160
211
|
__decorate([
|
|
161
212
|
consume({ context: selectedDeviceContext, subscribe: true }),
|
|
162
213
|
state()
|
|
163
|
-
],
|
|
214
|
+
], DictationRecordingButton.prototype, "_selectedDevice", void 0);
|
|
164
215
|
__decorate([
|
|
165
216
|
consume({ context: accessTokenContext, subscribe: true }),
|
|
166
217
|
state()
|
|
167
|
-
],
|
|
218
|
+
], DictationRecordingButton.prototype, "_accessToken", void 0);
|
|
168
219
|
__decorate([
|
|
169
220
|
consume({ context: authConfigContext, subscribe: true }),
|
|
170
221
|
state()
|
|
171
|
-
],
|
|
222
|
+
], DictationRecordingButton.prototype, "_authConfig", void 0);
|
|
172
223
|
__decorate([
|
|
173
224
|
consume({ context: regionContext, subscribe: true }),
|
|
174
225
|
state()
|
|
175
|
-
],
|
|
226
|
+
], DictationRecordingButton.prototype, "_region", void 0);
|
|
176
227
|
__decorate([
|
|
177
228
|
consume({ context: tenantNameContext, subscribe: true }),
|
|
178
229
|
state()
|
|
179
|
-
],
|
|
230
|
+
], DictationRecordingButton.prototype, "_tenantName", void 0);
|
|
180
231
|
__decorate([
|
|
181
232
|
consume({ context: dictationConfigContext, subscribe: true }),
|
|
182
233
|
state()
|
|
183
|
-
],
|
|
234
|
+
], DictationRecordingButton.prototype, "_dictationConfig", void 0);
|
|
184
235
|
__decorate([
|
|
185
236
|
consume({ context: socketUrlContext, subscribe: true }),
|
|
186
237
|
state()
|
|
187
|
-
],
|
|
238
|
+
], DictationRecordingButton.prototype, "_socketUrl", void 0);
|
|
188
239
|
__decorate([
|
|
189
240
|
consume({ context: socketProxyContext, subscribe: true }),
|
|
190
241
|
state()
|
|
191
|
-
],
|
|
242
|
+
], DictationRecordingButton.prototype, "_socketProxy", void 0);
|
|
192
243
|
__decorate([
|
|
193
244
|
consume({ context: debugDisplayAudioContext, subscribe: true }),
|
|
194
245
|
state()
|
|
195
|
-
],
|
|
246
|
+
], DictationRecordingButton.prototype, "_debug_displayAudio", void 0);
|
|
247
|
+
__decorate([
|
|
248
|
+
consume({ context: keybindingContext, subscribe: true }),
|
|
249
|
+
state()
|
|
250
|
+
], DictationRecordingButton.prototype, "_keybinding", void 0);
|
|
251
|
+
__decorate([
|
|
252
|
+
consume({ context: modeContext, subscribe: true }),
|
|
253
|
+
state()
|
|
254
|
+
], DictationRecordingButton.prototype, "_mode", void 0);
|
|
196
255
|
__decorate([
|
|
197
256
|
property({ type: Boolean })
|
|
198
|
-
],
|
|
199
|
-
|
|
200
|
-
customElement("recording-button")
|
|
201
|
-
],
|
|
202
|
-
export {
|
|
257
|
+
], DictationRecordingButton.prototype, "allowButtonFocus", void 0);
|
|
258
|
+
DictationRecordingButton = __decorate([
|
|
259
|
+
customElement("dictation-recording-button")
|
|
260
|
+
], DictationRecordingButton);
|
|
261
|
+
export { DictationRecordingButton };
|
|
203
262
|
//# sourceMappingURL=recording-button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recording-button.js","sourceRoot":"","sources":["../../src/components/recording-button.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAuB,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,mBAAmB,GAEpB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,YAAY,MAAM,sBAAsB,CAAC;AAChD,OAAO,qBAAqB,MAAM,+BAA+B,CAAC;AAElE,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,0BAA0B,EAC1B,iBAAiB,EACjB,eAAe,EACf,UAAU,GACX,MAAM,oBAAoB,CAAC;AAE5B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,mBAAmB,CAAC;AAGpB,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,UAAU;IAAxC;;QAGG,oBAAe,GAAmB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SAAS,EAAE,IAAI,EAAE,CAAC;IACzD,KAAK,EAAE;qDACc;AAItB;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACxD,KAAK,EAAE;oDAC0B;AAIlC;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACpD,KAAK,EAAE;gDACS;AAIjB;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACxD,KAAK,EAAE;oDACa;AAIrB;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAC7D,KAAK,EAAE;yDACkC;AAI1C;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACvD,KAAK,EAAE;mDACY;AAIpB;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACzD,KAAK,EAAE;qDACoB;AAI5B;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAC/D,KAAK,EAAE;4DACsB;AAG9B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;qDACE;AA1CnB,eAAe;IAD3B,aAAa,CAAC,kBAAkB,CAAC;GACrB,eAAe,CAyM3B","sourcesContent":["import type { Corti } from \"@corti/sdk\";\nimport { consume } from \"@lit/context\";\nimport { type CSSResultGroup, html, LitElement } from \"lit\";\nimport { customElement, property, state } from \"lit/decorators.js\";\nimport {\n accessTokenContext,\n authConfigContext,\n debugDisplayAudioContext,\n dictationConfigContext,\n recordingStateContext,\n regionContext,\n selectedDeviceContext,\n socketProxyContext,\n socketUrlContext,\n tenantNameContext,\n} from \"../contexts/dictation-context.js\";\nimport {\n DictationController,\n type TranscribeMessage,\n} from \"../controllers/DictationController.js\";\nimport { MediaController } from \"../controllers/MediaController.js\";\nimport ButtonStyles from \"../styles/buttons.js\";\nimport RecordingButtonStyles from \"../styles/recording-button.js\";\nimport type { ProxyOptions, RecordingState } from \"../types.js\";\nimport {\n audioLevelChangedEvent,\n commandEvent,\n errorEvent,\n networkActivityEvent,\n recordingStateChangedEvent,\n streamClosedEvent,\n transcriptEvent,\n usageEvent,\n} from \"../utils/events.js\";\n\nimport \"./audio-visualiser.js\";\nimport \"../icons/icons.js\";\n\n@customElement(\"recording-button\")\nexport class RecordingButton extends LitElement {\n @consume({ context: recordingStateContext, subscribe: true })\n @state()\n private _recordingState: RecordingState = \"stopped\";\n\n @consume({ context: selectedDeviceContext, subscribe: true })\n @state()\n _selectedDevice?: MediaDeviceInfo;\n\n @consume({ context: accessTokenContext, subscribe: true })\n @state()\n _accessToken?: string;\n\n @consume({ context: authConfigContext, subscribe: true })\n @state()\n _authConfig?: Corti.BearerOptions;\n\n @consume({ context: regionContext, subscribe: true })\n @state()\n _region?: string;\n\n @consume({ context: tenantNameContext, subscribe: true })\n @state()\n _tenantName?: string;\n\n @consume({ context: dictationConfigContext, subscribe: true })\n @state()\n _dictationConfig?: Corti.TranscribeConfig;\n\n @consume({ context: socketUrlContext, subscribe: true })\n @state()\n _socketUrl?: string;\n\n @consume({ context: socketProxyContext, subscribe: true })\n @state()\n _socketProxy?: ProxyOptions;\n\n @consume({ context: debugDisplayAudioContext, subscribe: true })\n @state()\n _debug_displayAudio?: boolean;\n\n @property({ type: Boolean })\n preventFocus: boolean = false;\n\n private _mediaController = new MediaController(this);\n private _dictationController = new DictationController(this);\n\n static styles: CSSResultGroup = [RecordingButtonStyles, ButtonStyles];\n\n private _handleMouseDown(event: MouseEvent): void {\n if (this.preventFocus) {\n event.preventDefault();\n }\n }\n\n private _handleWebSocketMessage = (message: TranscribeMessage): void => {\n switch (message.type) {\n case \"CONFIG_ACCEPTED\":\n this._mediaController.mediaRecorder?.start(250);\n this._mediaController.startAudioLevelMonitoring((level) => {\n this.dispatchEvent(audioLevelChangedEvent(level));\n });\n this.dispatchEvent(recordingStateChangedEvent(\"recording\"));\n break;\n case \"CONFIG_DENIED\":\n this.dispatchEvent(\n errorEvent(`Config denied: ${message.reason ?? \"Unknown reason\"}`),\n );\n this._handleStop();\n break;\n case \"CONFIG_TIMEOUT\":\n this.dispatchEvent(errorEvent(\"Config timeout\"));\n this._handleStop();\n break;\n case \"transcript\":\n this.dispatchEvent(transcriptEvent(message));\n break;\n case \"command\":\n this.dispatchEvent(commandEvent(message));\n break;\n case \"usage\":\n this.dispatchEvent(usageEvent(message));\n break;\n case \"error\":\n this.dispatchEvent(errorEvent(message.error));\n this._handleStop();\n break;\n }\n };\n\n private _handleWebSocketError = (error: Error): void => {\n this.dispatchEvent(errorEvent(\"Socket error: \" + error.message));\n this._handleStop();\n };\n\n private _handleWebSocketClose = (event: unknown): void => {\n this.dispatchEvent(streamClosedEvent(event));\n };\n\n private async _handleStart(): Promise<void> {\n this.dispatchEvent(recordingStateChangedEvent(\"initializing\"));\n\n try {\n await this._mediaController.initialize(() => {\n if (this._recordingState === \"recording\") {\n this.dispatchEvent(errorEvent(\"Microphone access was lost.\"));\n this._handleStop();\n }\n });\n\n await this._dictationController.connect(\n this._mediaController.mediaRecorder,\n this._dictationConfig,\n {\n onClose: this._handleWebSocketClose,\n onError: this._handleWebSocketError,\n onMessage: this._handleWebSocketMessage,\n onNetworkActivity: (direction, data) => {\n this.dispatchEvent(networkActivityEvent(direction, data));\n },\n },\n );\n } catch (error) {\n this.dispatchEvent(errorEvent(error));\n await this._handleStop();\n }\n }\n\n private async _handleStop(): Promise<void> {\n this.dispatchEvent(recordingStateChangedEvent(\"stopping\"));\n\n try {\n this._mediaController.stopAudioLevelMonitoring();\n await this._mediaController.stopRecording();\n\n await this._dictationController.disconnect(this._handleWebSocketClose);\n await this._mediaController.cleanup();\n } catch (error) {\n this.dispatchEvent(errorEvent(error));\n }\n\n this.dispatchEvent(recordingStateChangedEvent(\"stopped\"));\n }\n\n private _handleClick(): void {\n if (this._recordingState === \"stopped\") {\n this._handleStart();\n } else if (this._recordingState === \"recording\") {\n this._handleStop();\n }\n }\n\n public startRecording(): void {\n if (this._recordingState !== \"stopped\") {\n return;\n }\n\n this._handleStart();\n }\n\n public stopRecording(): void {\n if (this._recordingState !== \"recording\") {\n return;\n }\n\n this._handleStop();\n }\n\n public toggleRecording(): void {\n this._handleClick();\n }\n\n render() {\n const isLoading =\n this._recordingState === \"initializing\" ||\n this._recordingState === \"stopping\";\n const isRecording = this._recordingState === \"recording\";\n\n return html`\n <button\n @mousedown=${this._handleMouseDown}\n @click=${this._handleClick}\n ?disabled=${isLoading}\n class=${isRecording ? \"red\" : \"accent\"}\n aria-label=${isRecording ? \"Stop recording\" : \"Start recording\"}\n aria-pressed=${isRecording}\n >\n ${\n isLoading\n ? html`<icon-loading-spinner></icon-loading-spinner>`\n : isRecording\n ? html`<icon-recording></icon-recording>`\n : html`<icon-mic-on></icon-mic-on>`\n }\n <audio-visualiser\n .level=${this._mediaController.audioLevel}\n ?active=${isRecording}\n ></audio-visualiser>\n </button>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"recording-button\": RecordingButton;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recording-button.js","sourceRoot":"","sources":["../../src/components/recording-button.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAuB,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACxB,sBAAsB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AK,EAAE;kEACkC;AAI1C;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACvD,KAAK,EAAE;4DACY;AAIpB;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACzD,KAAK,EAAE;8DACoB;AAI5B;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAC/D,KAAK,EAAE;qEACsB;AAI9B;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACxD,KAAK,EAAE;6DACoB;AAI5B;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAClD,KAAK,EAAE;uDACc;AAGtB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;kEACM;AAlDvB,wBAAwB;IADpC,aAAa,CAAC,4BAA4B,CAAC;GAC/B,wBAAwB,CA+PpC","sourcesContent":["import type { Corti } from \"@corti/sdk\";\nimport { consume } from \"@lit/context\";\nimport { type CSSResultGroup, html, LitElement } from \"lit\";\nimport { customElement, property, state } from \"lit/decorators.js\";\nimport { AUDIO_CHUNK_INTERVAL_MS } from \"../constants.js\";\nimport {\n accessTokenContext,\n authConfigContext,\n debugDisplayAudioContext,\n dictationConfigContext,\n keybindingContext,\n modeContext,\n recordingStateContext,\n regionContext,\n selectedDeviceContext,\n socketProxyContext,\n socketUrlContext,\n tenantNameContext,\n} from \"../contexts/dictation-context.js\";\nimport {\n DictationController,\n type TranscribeMessage,\n} from \"../controllers/dictation-controller.js\";\nimport { KeybindingController } from \"../controllers/keybinding-controller.js\";\nimport { MediaController } from \"../controllers/media-controller.js\";\nimport ButtonStyles from \"../styles/buttons.js\";\nimport RecordingButtonStyles from \"../styles/recording-button.js\";\nimport type { DictationMode, ProxyOptions, RecordingState } from \"../types.js\";\nimport {\n audioLevelChangedEvent,\n commandEvent,\n errorEvent,\n networkActivityEvent,\n type RecordingStateChangedEventDetail,\n recordingStateChangedEvent,\n streamClosedEvent,\n transcriptEvent,\n usageEvent,\n} from \"../utils/events.js\";\n\nimport \"./audio-visualiser.js\";\nimport \"../icons/icons.js\";\n\n@customElement(\"dictation-recording-button\")\nexport class DictationRecordingButton extends LitElement {\n @consume({ context: recordingStateContext, subscribe: true })\n @state()\n _recordingState: RecordingState = \"stopped\";\n\n @consume({ context: selectedDeviceContext, subscribe: true })\n @state()\n _selectedDevice?: MediaDeviceInfo;\n\n @consume({ context: accessTokenContext, subscribe: true })\n @state()\n _accessToken?: string;\n\n @consume({ context: authConfigContext, subscribe: true })\n @state()\n _authConfig?: Corti.BearerOptions;\n\n @consume({ context: regionContext, subscribe: true })\n @state()\n _region?: string;\n\n @consume({ context: tenantNameContext, subscribe: true })\n @state()\n _tenantName?: string;\n\n @consume({ context: dictationConfigContext, subscribe: true })\n @state()\n _dictationConfig?: Corti.TranscribeConfig;\n\n @consume({ context: socketUrlContext, subscribe: true })\n @state()\n _socketUrl?: string;\n\n @consume({ context: socketProxyContext, subscribe: true })\n @state()\n _socketProxy?: ProxyOptions;\n\n @consume({ context: debugDisplayAudioContext, subscribe: true })\n @state()\n _debug_displayAudio?: boolean;\n\n @consume({ context: keybindingContext, subscribe: true })\n @state()\n _keybinding?: string | null;\n\n @consume({ context: modeContext, subscribe: true })\n @state()\n _mode?: DictationMode;\n\n @property({ type: Boolean })\n allowButtonFocus: boolean = false;\n\n #mediaController = new MediaController(this);\n #dictationController = new DictationController(this);\n #keybindingController = new KeybindingController(this);\n\n static styles: CSSResultGroup = [RecordingButtonStyles, ButtonStyles];\n\n #handleMouseDown(event: MouseEvent): void {\n if (!this.allowButtonFocus) {\n event.preventDefault();\n }\n\n if (this._mode === \"push-to-talk\") {\n this.startRecording();\n }\n }\n\n #handleMouseUp(): void {\n if (this._mode === \"push-to-talk\") {\n this.stopRecording();\n return;\n }\n\n if (this._mode === \"toggle-to-talk\") {\n this.toggleRecording();\n }\n }\n\n #handleMouseLeave(): void {\n if (this._mode === \"push-to-talk\") {\n this.stopRecording();\n }\n }\n\n #handleWebSocketMessage = (message: TranscribeMessage): void => {\n switch (message.type) {\n case \"CONFIG_ACCEPTED\":\n this.#mediaController.mediaRecorder?.start(AUDIO_CHUNK_INTERVAL_MS);\n this.#mediaController.startAudioLevelMonitoring((level) => {\n this.dispatchEvent(audioLevelChangedEvent(level));\n });\n this.dispatchEvent(recordingStateChangedEvent(\"recording\"));\n break;\n case \"CONFIG_DENIED\":\n this.dispatchEvent(\n errorEvent(`Config denied: ${message.reason ?? \"Unknown reason\"}`),\n );\n this.#handleStop();\n break;\n case \"CONFIG_TIMEOUT\":\n this.dispatchEvent(errorEvent(\"Config timeout\"));\n this.#handleStop();\n break;\n case \"transcript\":\n this.dispatchEvent(transcriptEvent(message));\n break;\n case \"command\":\n this.dispatchEvent(commandEvent(message));\n break;\n case \"usage\":\n this.dispatchEvent(usageEvent(message));\n break;\n case \"error\":\n this.dispatchEvent(errorEvent(message.error));\n this.#handleStop();\n break;\n }\n };\n\n #handleWebSocketError = (error: Error): void => {\n this.dispatchEvent(errorEvent(\"Socket error: \" + error.message));\n this.#handleStop();\n };\n\n #handleWebSocketClose = (event: unknown): void => {\n this.dispatchEvent(streamClosedEvent(event));\n };\n\n async #handleStart(): Promise<void> {\n this.dispatchEvent(recordingStateChangedEvent(\"initializing\"));\n\n try {\n await this.#mediaController.initialize(() => {\n if (this._recordingState === \"recording\") {\n this.dispatchEvent(errorEvent(\"Recording device access was lost.\"));\n this.#handleStop();\n }\n });\n\n const isNewConnection = await this.#dictationController.connect(\n this.#mediaController.mediaRecorder,\n this._dictationConfig,\n {\n onClose: this.#handleWebSocketClose,\n onError: this.#handleWebSocketError,\n onMessage: this.#handleWebSocketMessage,\n onNetworkActivity: (direction, data) => {\n this.dispatchEvent(networkActivityEvent(direction, data));\n },\n },\n );\n\n // configuration has been accepted before\n if (!isNewConnection) {\n this.#mediaController.mediaRecorder?.start(AUDIO_CHUNK_INTERVAL_MS);\n this.#mediaController.startAudioLevelMonitoring((level) => {\n this.dispatchEvent(audioLevelChangedEvent(level));\n });\n this.dispatchEvent(recordingStateChangedEvent(\"recording\"));\n }\n } catch (error) {\n this.dispatchEvent(errorEvent(error));\n await this.#handleStop();\n }\n }\n\n async #handleStop(): Promise<void> {\n this.dispatchEvent(recordingStateChangedEvent(\"stopping\"));\n\n try {\n this.#mediaController.stopAudioLevelMonitoring();\n await this.#mediaController.stopRecording();\n\n await this.#dictationController.disconnect(this.#handleWebSocketClose);\n await this.#mediaController.cleanup();\n } catch (error) {\n this.dispatchEvent(errorEvent(error));\n }\n\n this.dispatchEvent(recordingStateChangedEvent(\"stopped\"));\n }\n\n public startRecording(): void {\n if (this._recordingState !== \"stopped\") {\n return;\n }\n\n this.#handleStart();\n }\n\n public stopRecording(): void {\n if (this._recordingState === \"stopped\") {\n return;\n }\n\n if (this._recordingState === \"initializing\") {\n this.addEventListener(\n \"recording-state-changed\",\n (event) => {\n if (\n (event as CustomEvent<RecordingStateChangedEventDetail>).detail\n .state === \"recording\"\n ) {\n this.#handleStop();\n }\n },\n {\n once: true,\n },\n );\n return;\n }\n\n this.#handleStop();\n }\n\n public toggleRecording(): void {\n if (this._recordingState === \"stopped\") {\n this.#handleStart();\n } else if (this._recordingState === \"recording\") {\n this.#handleStop();\n }\n }\n\n render() {\n const isLoading =\n this._recordingState === \"initializing\" ||\n this._recordingState === \"stopping\";\n const isRecording = this._recordingState === \"recording\";\n\n return html`\n <button\n @mousedown=${this.#handleMouseDown}\n @mouseup=${this.#handleMouseUp}\n @mouseleave=${this.#handleMouseLeave}\n ?disabled=${isLoading}\n class=${isRecording ? \"red\" : \"accent\"}\n aria-label=${isRecording ? \"Stop recording\" : \"Start recording\"}\n aria-pressed=${isRecording}\n >\n ${\n isLoading\n ? html`<icon-loading-spinner />`\n : isRecording\n ? html`<icon-recording />`\n : html`<icon-mic-on />`\n }\n <dictation-audio-visualiser\n .level=${this.#mediaController.audioLevel}\n ?active=${isRecording}\n />\n </button>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"dictation-recording-button\": DictationRecordingButton;\n }\n}\n"]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type CSSResultGroup, LitElement, nothing } from "lit";
|
|
2
2
|
import type { ConfigurableSettings, RecordingState } from "../types.js";
|
|
3
3
|
import "./device-selector.js";
|
|
4
|
+
import "./keybinding-selector.js";
|
|
4
5
|
import "./language-selector.js";
|
|
6
|
+
import "./mode-selector.js";
|
|
5
7
|
import "../icons/icons.js";
|
|
6
|
-
export declare class
|
|
8
|
+
export declare class DictationSettingsMenu extends LitElement {
|
|
7
9
|
_recordingState: RecordingState;
|
|
8
10
|
settingsEnabled: ConfigurableSettings[];
|
|
9
11
|
static styles: CSSResultGroup;
|
|
@@ -11,6 +13,6 @@ export declare class SettingsMenu extends LitElement {
|
|
|
11
13
|
}
|
|
12
14
|
declare global {
|
|
13
15
|
interface HTMLElementTagNameMap {
|
|
14
|
-
"settings-menu":
|
|
16
|
+
"dictation-settings-menu": DictationSettingsMenu;
|
|
15
17
|
}
|
|
16
18
|
}
|
|
@@ -13,25 +13,29 @@ import CalloutStyles from "../styles/callout.js";
|
|
|
13
13
|
import SettingsMenuStyles from "../styles/settings-menu.js";
|
|
14
14
|
import { commaSeparatedConverter } from "../utils/converters.js";
|
|
15
15
|
import "./device-selector.js";
|
|
16
|
+
import "./keybinding-selector.js";
|
|
16
17
|
import "./language-selector.js";
|
|
18
|
+
import "./mode-selector.js";
|
|
17
19
|
import "../icons/icons.js";
|
|
18
|
-
let
|
|
20
|
+
let DictationSettingsMenu = class DictationSettingsMenu extends LitElement {
|
|
19
21
|
constructor() {
|
|
20
22
|
super(...arguments);
|
|
21
23
|
this._recordingState = "stopped";
|
|
22
24
|
this.settingsEnabled = ["device", "language"];
|
|
23
25
|
}
|
|
24
26
|
render() {
|
|
25
|
-
if (
|
|
27
|
+
if (this.settingsEnabled?.length === 0) {
|
|
26
28
|
return nothing;
|
|
27
29
|
}
|
|
28
30
|
const isRecording = this._recordingState === "recording";
|
|
29
31
|
const showDeviceSelector = this.settingsEnabled.includes("device");
|
|
30
32
|
const showLanguageSelector = this.settingsEnabled.includes("language");
|
|
33
|
+
const showModeSelector = this.settingsEnabled.includes("mode");
|
|
34
|
+
const showKeybinding = this.settingsEnabled.includes("keybinding");
|
|
31
35
|
return html `
|
|
32
36
|
<div class="mic-selector">
|
|
33
37
|
<button id="settings-popover-button" popovertarget="settings-popover">
|
|
34
|
-
<icon-settings
|
|
38
|
+
<icon-settings />
|
|
35
39
|
</button>
|
|
36
40
|
<div id="settings-popover" popover>
|
|
37
41
|
<div class="settings-wrapper">
|
|
@@ -43,14 +47,30 @@ let SettingsMenu = class SettingsMenu extends LitElement {
|
|
|
43
47
|
`
|
|
44
48
|
: nothing}
|
|
45
49
|
${showDeviceSelector
|
|
46
|
-
? html `<device-selector
|
|
50
|
+
? html `<dictation-device-selector
|
|
47
51
|
?disabled=${isRecording}
|
|
48
|
-
|
|
52
|
+
/>`
|
|
49
53
|
: nothing}
|
|
50
54
|
${showLanguageSelector
|
|
51
|
-
? html `<language-selector
|
|
55
|
+
? html `<dictation-language-selector
|
|
52
56
|
?disabled=${isRecording}
|
|
53
|
-
|
|
57
|
+
/>`
|
|
58
|
+
: nothing}
|
|
59
|
+
${showModeSelector || showKeybinding
|
|
60
|
+
? html `
|
|
61
|
+
<div class="settings-group">
|
|
62
|
+
${showModeSelector
|
|
63
|
+
? html `<dictation-mode-selector
|
|
64
|
+
?disabled=${isRecording}
|
|
65
|
+
/>`
|
|
66
|
+
: nothing}
|
|
67
|
+
${showKeybinding
|
|
68
|
+
? html `<dictation-keybinding-selector
|
|
69
|
+
?disabled=${isRecording}
|
|
70
|
+
/>`
|
|
71
|
+
: nothing}
|
|
72
|
+
</div>
|
|
73
|
+
`
|
|
54
74
|
: nothing}
|
|
55
75
|
</div>
|
|
56
76
|
</div>
|
|
@@ -58,7 +78,7 @@ let SettingsMenu = class SettingsMenu extends LitElement {
|
|
|
58
78
|
`;
|
|
59
79
|
}
|
|
60
80
|
};
|
|
61
|
-
|
|
81
|
+
DictationSettingsMenu.styles = [
|
|
62
82
|
SettingsMenuStyles,
|
|
63
83
|
ButtonStyles,
|
|
64
84
|
CalloutStyles,
|
|
@@ -66,15 +86,15 @@ SettingsMenu.styles = [
|
|
|
66
86
|
__decorate([
|
|
67
87
|
consume({ context: recordingStateContext, subscribe: true }),
|
|
68
88
|
state()
|
|
69
|
-
],
|
|
89
|
+
], DictationSettingsMenu.prototype, "_recordingState", void 0);
|
|
70
90
|
__decorate([
|
|
71
91
|
property({
|
|
72
92
|
converter: commaSeparatedConverter,
|
|
73
93
|
type: Array,
|
|
74
94
|
})
|
|
75
|
-
],
|
|
76
|
-
|
|
77
|
-
customElement("settings-menu")
|
|
78
|
-
],
|
|
79
|
-
export {
|
|
95
|
+
], DictationSettingsMenu.prototype, "settingsEnabled", void 0);
|
|
96
|
+
DictationSettingsMenu = __decorate([
|
|
97
|
+
customElement("dictation-settings-menu")
|
|
98
|
+
], DictationSettingsMenu);
|
|
99
|
+
export { DictationSettingsMenu };
|
|
80
100
|
//# sourceMappingURL=settings-menu.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings-menu.js","sourceRoot":"","sources":["../../src/components/settings-menu.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAuB,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACz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a,CAAC,yBAAyB,CAAC;GAC5B,qBAAqB,CAqFjC","sourcesContent":["import { consume } from \"@lit/context\";\nimport { type CSSResultGroup, html, LitElement, nothing } from \"lit\";\nimport { customElement, property, state } from \"lit/decorators.js\";\nimport { recordingStateContext } from \"../contexts/dictation-context.js\";\nimport ButtonStyles from \"../styles/buttons.js\";\nimport CalloutStyles from \"../styles/callout.js\";\nimport SettingsMenuStyles from \"../styles/settings-menu.js\";\nimport type { ConfigurableSettings, RecordingState } from \"../types.js\";\nimport { commaSeparatedConverter } from \"../utils/converters.js\";\n\nimport \"./device-selector.js\";\nimport \"./keybinding-selector.js\";\nimport \"./language-selector.js\";\nimport \"./mode-selector.js\";\nimport \"../icons/icons.js\";\n\n@customElement(\"dictation-settings-menu\")\nexport class DictationSettingsMenu extends LitElement {\n @consume({ context: recordingStateContext, subscribe: true })\n @state()\n _recordingState: RecordingState = \"stopped\";\n\n @property({\n converter: commaSeparatedConverter,\n type: Array,\n })\n settingsEnabled: ConfigurableSettings[] = [\"device\", \"language\"];\n\n static styles: CSSResultGroup = [\n SettingsMenuStyles,\n ButtonStyles,\n CalloutStyles,\n ];\n\n render() {\n if (this.settingsEnabled?.length === 0) {\n return nothing;\n }\n\n const isRecording = this._recordingState === \"recording\";\n const showDeviceSelector = this.settingsEnabled.includes(\"device\");\n const showLanguageSelector = this.settingsEnabled.includes(\"language\");\n const showModeSelector = this.settingsEnabled.includes(\"mode\");\n const showKeybinding = this.settingsEnabled.includes(\"keybinding\");\n\n return html`\n <div class=\"mic-selector\">\n <button id=\"settings-popover-button\" popovertarget=\"settings-popover\">\n <icon-settings />\n </button>\n <div id=\"settings-popover\" popover>\n <div class=\"settings-wrapper\">\n ${\n isRecording\n ? html`\n <div class=\"callout warn\">\n Recording is in progress. Stop recording to change settings.\n </div>\n `\n : nothing\n }\n ${\n showDeviceSelector\n ? html`<dictation-device-selector\n ?disabled=${isRecording}\n />`\n : nothing\n }\n ${\n showLanguageSelector\n ? html`<dictation-language-selector\n ?disabled=${isRecording}\n />`\n : nothing\n }\n ${\n showModeSelector || showKeybinding\n ? html`\n <div class=\"settings-group\">\n ${\n showModeSelector\n ? html`<dictation-mode-selector\n ?disabled=${isRecording}\n />`\n : nothing\n }\n ${\n showKeybinding\n ? html`<dictation-keybinding-selector\n ?disabled=${isRecording}\n />`\n : nothing\n }\n </div>\n `\n : nothing\n }\n </div>\n </div>\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"dictation-settings-menu\": DictationSettingsMenu;\n }\n}\n"]}
|
package/dist/constants.d.ts
CHANGED
|
@@ -2,3 +2,8 @@ import type { Corti } from "@corti/sdk";
|
|
|
2
2
|
export declare const LANGUAGES_SUPPORTED_EU: Corti.TranscribeSupportedLanguage[];
|
|
3
3
|
export declare const LANGUAGES_SUPPORTED_US: Corti.TranscribeSupportedLanguage[];
|
|
4
4
|
export declare const DEFAULT_DICTATION_CONFIG: Corti.TranscribeConfig;
|
|
5
|
+
/**
|
|
6
|
+
* Interval in milliseconds at which MediaRecorder fires dataavailable events.
|
|
7
|
+
* This controls how often audio chunks are sent to the WebSocket.
|
|
8
|
+
*/
|
|
9
|
+
export declare const AUDIO_CHUNK_INTERVAL_MS = 250;
|
package/dist/constants.js
CHANGED
|
@@ -34,4 +34,9 @@ export const DEFAULT_DICTATION_CONFIG = {
|
|
|
34
34
|
primaryLanguage: "en",
|
|
35
35
|
spokenPunctuation: true,
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Interval in milliseconds at which MediaRecorder fires dataavailable events.
|
|
39
|
+
* This controls how often audio chunks are sent to the WebSocket.
|
|
40
|
+
*/
|
|
41
|
+
export const AUDIO_CHUNK_INTERVAL_MS = 250;
|
|
37
42
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,sBAAsB,GAAwC;IACzE,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,QAAQ;CACT,CAAC,IAAI,EAAE,CAAC;AACT,MAAM,CAAC,MAAM,sBAAsB,GAAwC;IACzE,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;CACL,CAAC,IAAI,EAAE,CAAC;AACT,MAAM,CAAC,MAAM,wBAAwB,GAA2B;IAC9D,oBAAoB,EAAE,KAAK;IAC3B,eAAe,EAAE,IAAI;IACrB,iBAAiB,EAAE,IAAI;CACxB,CAAC","sourcesContent":["import type { Corti } from \"@corti/sdk\";\n\nexport const LANGUAGES_SUPPORTED_EU: Corti.TranscribeSupportedLanguage[] = [\n \"da\",\n \"de\",\n \"de-CH\",\n \"en\",\n \"en-GB\",\n \"es\",\n \"fr\",\n \"hu\",\n \"it\",\n \"nl\",\n \"no\",\n \"pt\",\n \"sv\",\n \"gsw-CH\",\n].sort();\nexport const LANGUAGES_SUPPORTED_US: Corti.TranscribeSupportedLanguage[] = [\n \"da\",\n \"de\",\n \"de-CH\",\n \"en\",\n \"en-GB\",\n \"es\",\n \"fr\",\n \"hu\",\n \"it\",\n \"nl\",\n \"no\",\n \"pt\",\n \"sv\",\n].sort();\nexport const DEFAULT_DICTATION_CONFIG: Corti.TranscribeConfig = {\n automaticPunctuation: false,\n primaryLanguage: \"en\",\n spokenPunctuation: true,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,sBAAsB,GAAwC;IACzE,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,QAAQ;CACT,CAAC,IAAI,EAAE,CAAC;AACT,MAAM,CAAC,MAAM,sBAAsB,GAAwC;IACzE,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;CACL,CAAC,IAAI,EAAE,CAAC;AACT,MAAM,CAAC,MAAM,wBAAwB,GAA2B;IAC9D,oBAAoB,EAAE,KAAK;IAC3B,eAAe,EAAE,IAAI;IACrB,iBAAiB,EAAE,IAAI;CACxB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC","sourcesContent":["import type { Corti } from \"@corti/sdk\";\n\nexport const LANGUAGES_SUPPORTED_EU: Corti.TranscribeSupportedLanguage[] = [\n \"da\",\n \"de\",\n \"de-CH\",\n \"en\",\n \"en-GB\",\n \"es\",\n \"fr\",\n \"hu\",\n \"it\",\n \"nl\",\n \"no\",\n \"pt\",\n \"sv\",\n \"gsw-CH\",\n].sort();\nexport const LANGUAGES_SUPPORTED_US: Corti.TranscribeSupportedLanguage[] = [\n \"da\",\n \"de\",\n \"de-CH\",\n \"en\",\n \"en-GB\",\n \"es\",\n \"fr\",\n \"hu\",\n \"it\",\n \"nl\",\n \"no\",\n \"pt\",\n \"sv\",\n].sort();\nexport const DEFAULT_DICTATION_CONFIG: Corti.TranscribeConfig = {\n automaticPunctuation: false,\n primaryLanguage: \"en\",\n spokenPunctuation: true,\n};\n\n/**\n * Interval in milliseconds at which MediaRecorder fires dataavailable events.\n * This controls how often audio chunks are sent to the WebSocket.\n */\nexport const AUDIO_CHUNK_INTERVAL_MS = 250;\n"]}
|