@corti/dictation-web 0.0.1
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/.editorconfig +29 -0
- package/.eslintrc.json +16 -0
- package/.husky/pre-commit +1 -0
- package/.storybook/main.js +8 -0
- package/README.md +120 -0
- package/demo/index.html +98 -0
- package/dist/src/CortiDictation.d.ts +19 -0
- package/dist/src/CortiDictation.js +137 -0
- package/dist/src/CortiDictation.js.map +1 -0
- package/dist/src/DictationService.d.ts +13 -0
- package/dist/src/DictationService.js +70 -0
- package/dist/src/DictationService.js.map +1 -0
- package/dist/src/RecorderManager.d.ts +20 -0
- package/dist/src/RecorderManager.js +85 -0
- package/dist/src/RecorderManager.js.map +1 -0
- package/dist/src/audioRecorderManager.d.ts +17 -0
- package/dist/src/audioRecorderManager.js +78 -0
- package/dist/src/audioRecorderManager.js.map +1 -0
- package/dist/src/audioService.d.ts +6 -0
- package/dist/src/audioService.js +21 -0
- package/dist/src/audioService.js.map +1 -0
- package/dist/src/componentStyles.d.ts +1 -0
- package/dist/src/componentStyles.js +51 -0
- package/dist/src/componentStyles.js.map +1 -0
- package/dist/src/components/audio-visualiser.d.ts +12 -0
- package/dist/src/components/audio-visualiser.js +60 -0
- package/dist/src/components/audio-visualiser.js.map +1 -0
- package/dist/src/components/settings-menu.d.ts +15 -0
- package/dist/src/components/settings-menu.js +148 -0
- package/dist/src/components/settings-menu.js.map +1 -0
- package/dist/src/components/visualiser.d.ts +7 -0
- package/dist/src/components/visualiser.js +62 -0
- package/dist/src/components/visualiser.js.map +1 -0
- package/dist/src/constants.d.ts +3 -0
- package/dist/src/constants.js +9 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/corti-dictation.d.ts +1 -0
- package/dist/src/corti-dictation.js +3 -0
- package/dist/src/corti-dictation.js.map +1 -0
- package/dist/src/dictationService.d.ts +13 -0
- package/dist/src/dictationService.js +70 -0
- package/dist/src/dictationService.js.map +1 -0
- package/dist/src/icons/icons.d.ts +17 -0
- package/dist/src/icons/icons.js +153 -0
- package/dist/src/icons/icons.js.map +1 -0
- package/dist/src/icons/index.d.ts +0 -0
- package/dist/src/icons/index.js +2 -0
- package/dist/src/icons/index.js.map +1 -0
- package/dist/src/icons/micOn.d.ts +7 -0
- package/dist/src/icons/micOn.js +25 -0
- package/dist/src/icons/micOn.js.map +1 -0
- package/dist/src/index.d.ts +20 -0
- package/dist/src/index.js +147 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mediaRecorderService.d.ts +6 -0
- package/dist/src/mediaRecorderService.js +31 -0
- package/dist/src/mediaRecorderService.js.map +1 -0
- package/dist/src/mic-selector.d.ts +18 -0
- package/dist/src/mic-selector.js +131 -0
- package/dist/src/mic-selector.js.map +1 -0
- package/dist/src/settings-menu.d.ts +18 -0
- package/dist/src/settings-menu.js +131 -0
- package/dist/src/settings-menu.js.map +1 -0
- package/dist/src/settings-popover.d.ts +18 -0
- package/dist/src/settings-popover.js +131 -0
- package/dist/src/settings-popover.js.map +1 -0
- package/dist/src/settings.d.ts +18 -0
- package/dist/src/settings.js +131 -0
- package/dist/src/settings.js.map +1 -0
- package/dist/src/styles/ComponentStyles.d.ts +2 -0
- package/dist/src/styles/ComponentStyles.js +52 -0
- package/dist/src/styles/ComponentStyles.js.map +1 -0
- package/dist/src/styles/buttons.d.ts +2 -0
- package/dist/src/styles/buttons.js +58 -0
- package/dist/src/styles/buttons.js.map +1 -0
- package/dist/src/styles/callout.d.ts +2 -0
- package/dist/src/styles/callout.js +26 -0
- package/dist/src/styles/callout.js.map +1 -0
- package/dist/src/styles/select.d.ts +2 -0
- package/dist/src/styles/select.js +36 -0
- package/dist/src/styles/select.js.map +1 -0
- package/dist/src/styles/theme.d.ts +2 -0
- package/dist/src/styles/theme.js +74 -0
- package/dist/src/styles/theme.js.map +1 -0
- package/dist/src/types.d.ts +20 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +31 -0
- package/dist/src/utils.js +77 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/stories/index.stories.d.ts +33 -0
- package/dist/stories/index.stories.js +37 -0
- package/dist/stories/index.stories.js.map +1 -0
- package/dist/test/corti-dictation.test.d.ts +1 -0
- package/dist/test/corti-dictation.test.js +100 -0
- package/dist/test/corti-dictation.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/DEV_README.md +80 -0
- package/package.json +92 -0
- package/src/DictationService.ts +99 -0
- package/src/RecorderManager.ts +114 -0
- package/src/audioService.ts +25 -0
- package/src/components/audio-visualiser.ts +56 -0
- package/src/components/settings-menu.ts +152 -0
- package/src/constants.ts +10 -0
- package/src/corti-dictation.ts +3 -0
- package/src/icons/icons.ts +141 -0
- package/src/icons/index.ts +0 -0
- package/src/index.ts +154 -0
- package/src/styles/ComponentStyles.ts +53 -0
- package/src/styles/buttons.ts +59 -0
- package/src/styles/callout.ts +27 -0
- package/src/styles/select.ts +37 -0
- package/src/styles/theme.ts +75 -0
- package/src/types.ts +28 -0
- package/src/utils.ts +83 -0
- package/stories/index.stories.ts +60 -0
- package/test/corti-dictation.test.ts +124 -0
- package/tsconfig.json +22 -0
- package/web-dev-server.config.js +27 -0
- package/web-test-runner.config.js +41 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export class DictationService extends EventTarget {
|
|
2
|
+
constructor(mediaStream, { dictationConfig, serverConfig }) {
|
|
3
|
+
super();
|
|
4
|
+
this.mediaRecorder = new MediaRecorder(mediaStream);
|
|
5
|
+
this.serverConfig = serverConfig;
|
|
6
|
+
this.dictationConfig = dictationConfig;
|
|
7
|
+
this.mediaRecorder.ondataavailable = event => {
|
|
8
|
+
// if (event.data && event.data.size > 0) {
|
|
9
|
+
// this.dispatchEvent(
|
|
10
|
+
// new CustomEvent('audio-packet', {
|
|
11
|
+
// detail: event.data,
|
|
12
|
+
// bubbles: true,
|
|
13
|
+
// composed: true,
|
|
14
|
+
// }),
|
|
15
|
+
// );
|
|
16
|
+
// }
|
|
17
|
+
// if webSocket is open, send the data
|
|
18
|
+
if (this.webSocket?.readyState === WebSocket.OPEN) {
|
|
19
|
+
this.webSocket.send(event.data);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
startRecording() {
|
|
24
|
+
const url = `wss://api.${this.serverConfig.environment}.corti.app/audio-bridge/v2/transcribe?tenant-name=${this.serverConfig.tenant}&token=Bearer%20${this.serverConfig.token}`;
|
|
25
|
+
this.webSocket = new WebSocket(url);
|
|
26
|
+
this.webSocket.onopen = () => {
|
|
27
|
+
this.webSocket.send(JSON.stringify({
|
|
28
|
+
type: 'config',
|
|
29
|
+
configuration: this.dictationConfig,
|
|
30
|
+
}));
|
|
31
|
+
};
|
|
32
|
+
this.webSocket.onmessage = event => {
|
|
33
|
+
const message = JSON.parse(event.data);
|
|
34
|
+
if (message.type === 'config') {
|
|
35
|
+
this.mediaRecorder.start(250);
|
|
36
|
+
}
|
|
37
|
+
else if (message.type === 'transcript') {
|
|
38
|
+
this.dispatchEvent(new CustomEvent('transcript', {
|
|
39
|
+
detail: message,
|
|
40
|
+
bubbles: true,
|
|
41
|
+
composed: true,
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async stopRecording() {
|
|
47
|
+
let timeOut;
|
|
48
|
+
this.mediaRecorder.stop();
|
|
49
|
+
if (this.webSocket?.readyState === WebSocket.OPEN) {
|
|
50
|
+
this.webSocket.send(JSON.stringify({
|
|
51
|
+
type: 'end',
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
this.webSocket.onmessage = (e) => {
|
|
55
|
+
};
|
|
56
|
+
// this implementation should be replaced by handling a proper 'ended' message from the server
|
|
57
|
+
this.webSocket.onclose = async () => {
|
|
58
|
+
this.webSocket.close();
|
|
59
|
+
clearTimeout(timeOut);
|
|
60
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
61
|
+
return;
|
|
62
|
+
};
|
|
63
|
+
timeOut = setTimeout(() => {
|
|
64
|
+
if (this.webSocket?.readyState === WebSocket.OPEN) {
|
|
65
|
+
this.webSocket.close();
|
|
66
|
+
}
|
|
67
|
+
}, 10000);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=dictationService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictationService.js","sourceRoot":"","sources":["../../src/dictationService.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,gBAAiB,SAAQ,WAAW;IAM/C,YAAY,WAAwB,EAAE,EAAC,eAAe,EAAE,YAAY,EAAiE;QACnI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,aAAa,CAAC,eAAe,GAAG,KAAK,CAAC,EAAE;YAC3C,2CAA2C;YAC3C,wBAAwB;YACxB,wCAAwC;YACxC,4BAA4B;YAC5B,uBAAuB;YACvB,wBAAwB;YACxB,UAAU;YACV,OAAO;YACP,IAAI;YAEJ,sCAAsC;YACtC,IAAI,IAAI,CAAC,SAAS,EAAE,UAAU,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;gBAClD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAC7B,CAAC;YACJ,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;IAEM,cAAc;QACnB,MAAM,GAAG,GAAG,aAAa,IAAI,CAAC,YAAY,CAAC,WAAW,qDAAqD,IAAI,CAAC,YAAY,CAAC,MAAM,mBAAmB,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;QAC/K,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,SAAS,CAAC,MAA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,CAAC,OAAO,CAAC,CAAC;YACtB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;YACzD,OAAM;QACR,CAAC,CAAC;QACF,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YACxB,IAAI,IAAI,CAAC,SAAS,EAAE,UAAU,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;gBAClD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;YACzB,CAAC;QACH,CAAC,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC;CACF","sourcesContent":["import { DictationConfig, ServerConfig } from \"./types\";\n\n\nexport class DictationService extends EventTarget {\n private mediaRecorder: MediaRecorder;\n private webSocket!: WebSocket;\n private serverConfig!: ServerConfig;\n private dictationConfig!: DictationConfig;\n\n constructor(mediaStream: MediaStream, {dictationConfig, serverConfig}: {dictationConfig: DictationConfig, serverConfig: ServerConfig}) {\n super();\n this.mediaRecorder = new MediaRecorder(mediaStream);\n this.serverConfig = serverConfig;\n this.dictationConfig = dictationConfig;\n this.mediaRecorder.ondataavailable = event => {\n // if (event.data && event.data.size > 0) {\n // this.dispatchEvent(\n // new CustomEvent('audio-packet', {\n // detail: event.data,\n // bubbles: true,\n // composed: true,\n // }),\n // );\n // }\n\n // if webSocket is open, send the data\n if (this.webSocket?.readyState === WebSocket.OPEN) {\n this.webSocket.send(event.data\n );\n }\n };\n }\n\n public startRecording() {\n const url = `wss://api.${this.serverConfig.environment}.corti.app/audio-bridge/v2/transcribe?tenant-name=${this.serverConfig.tenant}&token=Bearer%20${this.serverConfig.token}`\n this.webSocket = new WebSocket(url);\n this.webSocket.onopen = () => {\n this.webSocket.send(\n JSON.stringify({\n type: 'config',\n configuration: this.dictationConfig,\n }),\n );\n };\n this.webSocket.onmessage = event => {\n const message = JSON.parse(event.data);\n if (message.type === 'config') {\n this.mediaRecorder.start(250);\n } else if (message.type === 'transcript') {\n this.dispatchEvent(\n new CustomEvent('transcript', {\n detail: message,\n bubbles: true,\n composed: true,\n }),\n );\n }\n };\n }\n\n public async stopRecording() {\n let timeOut: any;\n this.mediaRecorder.stop();\n if (this.webSocket?.readyState === WebSocket.OPEN) {\n this.webSocket.send(\n JSON.stringify({\n type: 'end',\n }),\n );\n }\n this.webSocket.onmessage = (e) => {\n\n };\n // this implementation should be replaced by handling a proper 'ended' message from the server\n this.webSocket.onclose = async() => {\n this.webSocket.close();\n clearTimeout(timeOut);\n await new Promise((resolve) => setTimeout(resolve, 100));\n return\n };\n timeOut = setTimeout(() => {\n if (this.webSocket?.readyState === WebSocket.OPEN) {\n this.webSocket.close();\n }\n }, 10000);\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
export declare class IconMicOn extends LitElement {
|
|
3
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
4
|
+
}
|
|
5
|
+
export declare class IconMicOff extends LitElement {
|
|
6
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
7
|
+
}
|
|
8
|
+
export declare class IconRecording extends LitElement {
|
|
9
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
10
|
+
}
|
|
11
|
+
export declare class IconSettings extends LitElement {
|
|
12
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
13
|
+
}
|
|
14
|
+
export declare class IconLoadingSpinner extends LitElement {
|
|
15
|
+
static styles: import("lit").CSSResult;
|
|
16
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
/* eslint-disable max-classes-per-file */
|
|
3
|
+
import { LitElement, css, html } from 'lit';
|
|
4
|
+
import { customElement } from 'lit/decorators.js';
|
|
5
|
+
let IconMicOn = class IconMicOn extends LitElement {
|
|
6
|
+
render() {
|
|
7
|
+
return html `
|
|
8
|
+
<div style="display: flex">
|
|
9
|
+
<svg
|
|
10
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
11
|
+
width="20"
|
|
12
|
+
height="20"
|
|
13
|
+
viewBox="0 0 24 24"
|
|
14
|
+
fill="none"
|
|
15
|
+
stroke="currentColor"
|
|
16
|
+
stroke-width="2"
|
|
17
|
+
stroke-linecap="round"
|
|
18
|
+
stroke-linejoin="round"
|
|
19
|
+
class="lucide lucide-mic"
|
|
20
|
+
>
|
|
21
|
+
<path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z" />
|
|
22
|
+
<path d="M19 10v2a7 7 0 0 1-14 0v-2" />
|
|
23
|
+
<line x1="12" x2="12" y1="19" y2="22" />
|
|
24
|
+
</svg>
|
|
25
|
+
</div>
|
|
26
|
+
`;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
IconMicOn = __decorate([
|
|
30
|
+
customElement('icon-mic-on')
|
|
31
|
+
], IconMicOn);
|
|
32
|
+
export { IconMicOn };
|
|
33
|
+
let IconMicOff = class IconMicOff extends LitElement {
|
|
34
|
+
render() {
|
|
35
|
+
return html ` <div style="display: flex">
|
|
36
|
+
<svg
|
|
37
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
38
|
+
width="20"
|
|
39
|
+
height="20"
|
|
40
|
+
viewBox="0 0 24 24"
|
|
41
|
+
fill="none"
|
|
42
|
+
stroke="currentColor"
|
|
43
|
+
stroke-width="2"
|
|
44
|
+
stroke-linecap="round"
|
|
45
|
+
stroke-linejoin="round"
|
|
46
|
+
class="lucide lucide-mic-off"
|
|
47
|
+
>
|
|
48
|
+
<line x1="2" x2="22" y1="2" y2="22" />
|
|
49
|
+
<path d="M18.89 13.23A7.12 7.12 0 0 0 19 12v-2" />
|
|
50
|
+
<path d="M5 10v2a7 7 0 0 0 12 5" />
|
|
51
|
+
<path d="M15 9.34V5a3 3 0 0 0-5.68-1.33" />
|
|
52
|
+
<path d="M9 9v3a3 3 0 0 0 5.12 2.12" />
|
|
53
|
+
<line x1="12" x2="12" y1="19" y2="22" />
|
|
54
|
+
</svg>
|
|
55
|
+
</div>`;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
IconMicOff = __decorate([
|
|
59
|
+
customElement('icon-mic-off')
|
|
60
|
+
], IconMicOff);
|
|
61
|
+
export { IconMicOff };
|
|
62
|
+
let IconRecording = class IconRecording extends LitElement {
|
|
63
|
+
render() {
|
|
64
|
+
return html `
|
|
65
|
+
<div style="display: flex;">
|
|
66
|
+
<svg
|
|
67
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
68
|
+
width="20"
|
|
69
|
+
height="20"
|
|
70
|
+
viewBox="0 0 24 24"
|
|
71
|
+
fill="none"
|
|
72
|
+
stroke="currentColor"
|
|
73
|
+
stroke-width="2"
|
|
74
|
+
stroke-linecap="round"
|
|
75
|
+
stroke-linejoin="round"
|
|
76
|
+
class="lucide lucide-circle-stop"
|
|
77
|
+
>
|
|
78
|
+
<circle cx="12" cy="12" r="10" />
|
|
79
|
+
<rect x="9" y="9" width="6" height="6" rx="1" fill="currentColor" />
|
|
80
|
+
</svg>
|
|
81
|
+
</div>
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
IconRecording = __decorate([
|
|
86
|
+
customElement('icon-recording')
|
|
87
|
+
], IconRecording);
|
|
88
|
+
export { IconRecording };
|
|
89
|
+
let IconSettings = class IconSettings extends LitElement {
|
|
90
|
+
render() {
|
|
91
|
+
return html `<div style="display: flex">
|
|
92
|
+
<svg
|
|
93
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
94
|
+
width="20"
|
|
95
|
+
height="20"
|
|
96
|
+
viewBox="0 0 24 24"
|
|
97
|
+
fill="none"
|
|
98
|
+
stroke="currentColor"
|
|
99
|
+
stroke-width="2"
|
|
100
|
+
stroke-linecap="round"
|
|
101
|
+
stroke-linejoin="round"
|
|
102
|
+
class="lucide lucide-settings-2"
|
|
103
|
+
>
|
|
104
|
+
<path d="M20 7h-9" />
|
|
105
|
+
<path d="M14 17H5" />
|
|
106
|
+
<circle cx="17" cy="17" r="3" />
|
|
107
|
+
<circle cx="7" cy="7" r="3" />
|
|
108
|
+
</svg>
|
|
109
|
+
</div>`;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
IconSettings = __decorate([
|
|
113
|
+
customElement('icon-settings')
|
|
114
|
+
], IconSettings);
|
|
115
|
+
export { IconSettings };
|
|
116
|
+
let IconLoadingSpinner = class IconLoadingSpinner extends LitElement {
|
|
117
|
+
render() {
|
|
118
|
+
return html `<div style="display: flex">
|
|
119
|
+
<svg
|
|
120
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
121
|
+
width="20"
|
|
122
|
+
height="20"
|
|
123
|
+
viewBox="0 0 24 24"
|
|
124
|
+
fill="none"
|
|
125
|
+
stroke="currentColor"
|
|
126
|
+
stroke-width="2"
|
|
127
|
+
stroke-linecap="round"
|
|
128
|
+
stroke-linejoin="round"
|
|
129
|
+
class="lucide lucide-loader-circle spin"
|
|
130
|
+
>
|
|
131
|
+
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
|
|
132
|
+
</svg>
|
|
133
|
+
</div>`;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
IconLoadingSpinner.styles = css `
|
|
137
|
+
@keyframes spin {
|
|
138
|
+
0% {
|
|
139
|
+
transform: rotate(0deg);
|
|
140
|
+
}
|
|
141
|
+
100% {
|
|
142
|
+
transform: rotate(360deg);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
.spin {
|
|
146
|
+
animation: spin 1s linear infinite;
|
|
147
|
+
}
|
|
148
|
+
`;
|
|
149
|
+
IconLoadingSpinner = __decorate([
|
|
150
|
+
customElement('icon-loading-spinner')
|
|
151
|
+
], IconLoadingSpinner);
|
|
152
|
+
export { IconLoadingSpinner };
|
|
153
|
+
//# sourceMappingURL=icons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icons.js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kBAAkB;IAD9B,aAAa,CAAC,sBAAsB,CAAC;GACzB,kBAAkB,CAiC9B","sourcesContent":["/* eslint-disable max-classes-per-file */\nimport { LitElement, css, html } from 'lit';\nimport { customElement } from 'lit/decorators.js';\n\n@customElement('icon-mic-on')\nexport class IconMicOn extends LitElement {\n render() {\n return html`\n <div style=\"display: flex\">\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n class=\"lucide lucide-mic\"\n >\n <path d=\"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z\" />\n <path d=\"M19 10v2a7 7 0 0 1-14 0v-2\" />\n <line x1=\"12\" x2=\"12\" y1=\"19\" y2=\"22\" />\n </svg>\n </div>\n `;\n }\n}\n\n@customElement('icon-mic-off')\nexport class IconMicOff extends LitElement {\n render() {\n return html` <div style=\"display: flex\">\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n class=\"lucide lucide-mic-off\"\n >\n <line x1=\"2\" x2=\"22\" y1=\"2\" y2=\"22\" />\n <path d=\"M18.89 13.23A7.12 7.12 0 0 0 19 12v-2\" />\n <path d=\"M5 10v2a7 7 0 0 0 12 5\" />\n <path d=\"M15 9.34V5a3 3 0 0 0-5.68-1.33\" />\n <path d=\"M9 9v3a3 3 0 0 0 5.12 2.12\" />\n <line x1=\"12\" x2=\"12\" y1=\"19\" y2=\"22\" />\n </svg>\n </div>`;\n }\n}\n\n@customElement('icon-recording')\nexport class IconRecording extends LitElement {\n render() {\n return html`\n <div style=\"display: flex;\">\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n class=\"lucide lucide-circle-stop\"\n >\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <rect x=\"9\" y=\"9\" width=\"6\" height=\"6\" rx=\"1\" fill=\"currentColor\" />\n </svg>\n </div>\n `;\n }\n}\n@customElement('icon-settings')\nexport class IconSettings extends LitElement {\n render() {\n return html`<div style=\"display: flex\">\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n class=\"lucide lucide-settings-2\"\n >\n <path d=\"M20 7h-9\" />\n <path d=\"M14 17H5\" />\n <circle cx=\"17\" cy=\"17\" r=\"3\" />\n <circle cx=\"7\" cy=\"7\" r=\"3\" />\n </svg>\n </div>`;\n }\n}\n\n@customElement('icon-loading-spinner')\nexport class IconLoadingSpinner extends LitElement {\n static styles = css`\n @keyframes spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n }\n .spin {\n animation: spin 1s linear infinite;\n }\n `;\n\n render() {\n return html`<div style=\"display: flex\">\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n class=\"lucide lucide-loader-circle spin\"\n >\n <path d=\"M21 12a9 9 0 1 1-6.219-8.56\" />\n </svg>\n </div>`;\n }\n}\n"]}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/icons/index.ts"],"names":[],"mappings":"","sourcesContent":[""]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { LitElement, svg } from 'lit';
|
|
3
|
+
import { customElement } from 'lit/decorators.js';
|
|
4
|
+
let IconMicOn = class IconMicOn extends LitElement {
|
|
5
|
+
render() {
|
|
6
|
+
return svg `
|
|
7
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-mic"><path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/><line x1="12" x2="12" y1="19" y2="22"/></svg>
|
|
8
|
+
`;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
IconMicOn = __decorate([
|
|
12
|
+
customElement('icon-mic-on')
|
|
13
|
+
], IconMicOn);
|
|
14
|
+
export { IconMicOn };
|
|
15
|
+
let IconMicOff = class IconMicOff extends LitElement {
|
|
16
|
+
render() {
|
|
17
|
+
return svg `
|
|
18
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-mic-off"><line x1="2" x2="22" y1="2" y2="22"/><path d="M18.89 13.23A7.12 7.12 0 0 0 19 12v-2"/><path d="M5 10v2a7 7 0 0 0 12 5"/><path d="M15 9.34V5a3 3 0 0 0-5.68-1.33"/><path d="M9 9v3a3 3 0 0 0 5.12 2.12"/><line x1="12" x2="12" y1="19" y2="22"/></svg> `;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
IconMicOff = __decorate([
|
|
22
|
+
customElement('icon-mic-off')
|
|
23
|
+
], IconMicOff);
|
|
24
|
+
export { IconMicOff };
|
|
25
|
+
//# sourceMappingURL=micOn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"micOn.js","sourceRoot":"","sources":["../../../src/icons/micOn.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAG3C,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,UAAU;IACvC,MAAM;QACJ,OAAO,GAAG,CAAA;;OAEP,CAAC;IACN,CAAC;CACF,CAAA;AANY,SAAS;IADrB,aAAa,CAAC,aAAa,CAAC;GAChB,SAAS,CAMrB;;AAGM,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,UAAU;IACxC,MAAM;QACJ,OAAO,GAAG,CAAA;mdACqc,CAAC;IACld,CAAC;CACF,CAAA;AALY,UAAU;IADtB,aAAa,CAAC,cAAc,CAAC;GACjB,UAAU,CAKtB","sourcesContent":["import { LitElement, svg } from 'lit';\nimport { customElement } from 'lit/decorators.js';\n\n@customElement('icon-mic-on')\nexport class IconMicOn extends LitElement {\n render() {\n return svg`\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"lucide lucide-mic\"><path d=\"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z\"/><path d=\"M19 10v2a7 7 0 0 1-14 0v-2\"/><line x1=\"12\" x2=\"12\" y1=\"19\" y2=\"22\"/></svg>\n `;\n }\n}\n\n@customElement('icon-mic-off')\nexport class IconMicOff extends LitElement {\n render() {\n return svg`\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"lucide lucide-mic-off\"><line x1=\"2\" x2=\"22\" y1=\"2\" y2=\"22\"/><path d=\"M18.89 13.23A7.12 7.12 0 0 0 19 12v-2\"/><path d=\"M5 10v2a7 7 0 0 0 12 5\"/><path d=\"M15 9.34V5a3 3 0 0 0-5.68-1.33\"/><path d=\"M9 9v3a3 3 0 0 0 5.12 2.12\"/><line x1=\"12\" x2=\"12\" y1=\"19\" y2=\"22\"/></svg> `;\n }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import './components/settings-menu';
|
|
3
|
+
import './components/audio-visualiser';
|
|
4
|
+
import './icons/icons';
|
|
5
|
+
import { DictationConfig, ServerConfig } from './types';
|
|
6
|
+
export declare class CortiDictation extends LitElement {
|
|
7
|
+
static styles: import("lit").CSSResult[];
|
|
8
|
+
devices: MediaDeviceInfo[];
|
|
9
|
+
recordingState: string;
|
|
10
|
+
dictationConfig: DictationConfig;
|
|
11
|
+
serverConfig: ServerConfig;
|
|
12
|
+
private _audioLevel;
|
|
13
|
+
private recorderManager;
|
|
14
|
+
connectedCallback(): Promise<void>;
|
|
15
|
+
toggleRecording(): void;
|
|
16
|
+
_toggleRecording(): void;
|
|
17
|
+
_onRecordingDeviceChanged(event: Event): Promise<void>;
|
|
18
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
19
|
+
}
|
|
20
|
+
export default CortiDictation;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
// corti-dictation.ts
|
|
3
|
+
import { html, LitElement } from 'lit';
|
|
4
|
+
import { property, state } from 'lit/decorators.js';
|
|
5
|
+
import { RecorderManager } from './RecorderManager';
|
|
6
|
+
import './components/settings-menu';
|
|
7
|
+
import './components/audio-visualiser';
|
|
8
|
+
import './icons/icons';
|
|
9
|
+
import ThemeStyles from './styles/theme';
|
|
10
|
+
import ButtonStyles from './styles/buttons';
|
|
11
|
+
import ComponentStyles from './styles/ComponentStyles';
|
|
12
|
+
import { DEFAULT_DICTATION_CONFIG } from './constants';
|
|
13
|
+
import CalloutStyles from './styles/callout';
|
|
14
|
+
export class CortiDictation extends LitElement {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
this.devices = [];
|
|
18
|
+
this.recordingState = 'stopped';
|
|
19
|
+
this.dictationConfig = DEFAULT_DICTATION_CONFIG;
|
|
20
|
+
this.serverConfig = {};
|
|
21
|
+
this._audioLevel = 0;
|
|
22
|
+
this.recorderManager = new RecorderManager();
|
|
23
|
+
}
|
|
24
|
+
async connectedCallback() {
|
|
25
|
+
super.connectedCallback();
|
|
26
|
+
await this.recorderManager.initialize();
|
|
27
|
+
this.devices = this.recorderManager.devices;
|
|
28
|
+
// Map event names to any extra handling logic
|
|
29
|
+
const eventHandlers = {
|
|
30
|
+
'recording-state-changed': e => {
|
|
31
|
+
this.recordingState = e.detail.state;
|
|
32
|
+
},
|
|
33
|
+
'audio-level-changed': e => {
|
|
34
|
+
this._audioLevel = e.detail.audioLevel;
|
|
35
|
+
this.requestUpdate();
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
const eventsToRelay = [
|
|
39
|
+
'recording-state-changed',
|
|
40
|
+
'audio-level-changed',
|
|
41
|
+
'error',
|
|
42
|
+
'transcript',
|
|
43
|
+
];
|
|
44
|
+
eventsToRelay.forEach(eventName => {
|
|
45
|
+
this.recorderManager.addEventListener(eventName, (e) => {
|
|
46
|
+
const customEvent = e;
|
|
47
|
+
// Perform any additional handling if defined
|
|
48
|
+
if (eventHandlers[eventName]) {
|
|
49
|
+
eventHandlers[eventName](customEvent);
|
|
50
|
+
}
|
|
51
|
+
// Re-dispatch the event from the component
|
|
52
|
+
this.dispatchEvent(new CustomEvent(eventName, {
|
|
53
|
+
detail: customEvent.detail,
|
|
54
|
+
bubbles: true,
|
|
55
|
+
composed: true,
|
|
56
|
+
}));
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
toggleRecording() {
|
|
61
|
+
this._toggleRecording();
|
|
62
|
+
}
|
|
63
|
+
_toggleRecording() {
|
|
64
|
+
if (this.recordingState === 'recording') {
|
|
65
|
+
this.recorderManager.stopRecording();
|
|
66
|
+
}
|
|
67
|
+
else if (this.recordingState === 'stopped') {
|
|
68
|
+
this.recorderManager.startRecording({
|
|
69
|
+
dictationConfig: this.dictationConfig,
|
|
70
|
+
serverConfig: this.serverConfig,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Handle device change events if needed
|
|
75
|
+
async _onRecordingDeviceChanged(event) {
|
|
76
|
+
const customEvent = event;
|
|
77
|
+
this.recorderManager.selectedDevice = customEvent.detail.deviceId;
|
|
78
|
+
if (this.recordingState === 'recording') {
|
|
79
|
+
await this.recorderManager.stopRecording();
|
|
80
|
+
await this.recorderManager.startRecording({
|
|
81
|
+
dictationConfig: this.dictationConfig,
|
|
82
|
+
serverConfig: this.serverConfig,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
render() {
|
|
87
|
+
const isConfigured = this.serverConfig &&
|
|
88
|
+
this.serverConfig.token &&
|
|
89
|
+
this.serverConfig.environment &&
|
|
90
|
+
this.serverConfig.tenant;
|
|
91
|
+
if (!isConfigured) {
|
|
92
|
+
return html `
|
|
93
|
+
<div class="wrapper">
|
|
94
|
+
<div class="callout red tiny">
|
|
95
|
+
Please configure the server settings in the parent component.
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
`;
|
|
99
|
+
}
|
|
100
|
+
const isLoading = this.recordingState === 'initializing' ||
|
|
101
|
+
this.recordingState === 'stopping';
|
|
102
|
+
const isRecording = this.recordingState === 'recording';
|
|
103
|
+
return html `
|
|
104
|
+
<div class="wrapper">
|
|
105
|
+
<button
|
|
106
|
+
@click=${this._toggleRecording}
|
|
107
|
+
class=${isRecording ? 'red' : 'accent'}
|
|
108
|
+
>
|
|
109
|
+
${isLoading
|
|
110
|
+
? html `<icon-loading-spinner></icon-loading-spinner>`
|
|
111
|
+
: isRecording
|
|
112
|
+
? html `<icon-recording></icon-recording>`
|
|
113
|
+
: html `<icon-mic-on></icon-mic-on>`}
|
|
114
|
+
<audio-visualiser
|
|
115
|
+
.level=${this._audioLevel}
|
|
116
|
+
.active=${isRecording}
|
|
117
|
+
></audio-visualiser>
|
|
118
|
+
</button>
|
|
119
|
+
|
|
120
|
+
<settings-menu
|
|
121
|
+
.devices=${this.devices}
|
|
122
|
+
.selectedDevice=${this.recorderManager.selectedDevice}
|
|
123
|
+
?settingsDisabled=${this.recordingState !== 'stopped'}
|
|
124
|
+
@recording-device-changed=${this._onRecordingDeviceChanged}
|
|
125
|
+
></settings-menu>
|
|
126
|
+
</div>
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
CortiDictation.styles = [ButtonStyles, ThemeStyles, ComponentStyles, CalloutStyles];
|
|
131
|
+
__decorate([
|
|
132
|
+
property({ type: Array })
|
|
133
|
+
], CortiDictation.prototype, "devices", void 0);
|
|
134
|
+
__decorate([
|
|
135
|
+
property({ type: String, reflect: true })
|
|
136
|
+
], CortiDictation.prototype, "recordingState", void 0);
|
|
137
|
+
__decorate([
|
|
138
|
+
property({ type: Object })
|
|
139
|
+
], CortiDictation.prototype, "dictationConfig", void 0);
|
|
140
|
+
__decorate([
|
|
141
|
+
property({ type: Object })
|
|
142
|
+
], CortiDictation.prototype, "serverConfig", void 0);
|
|
143
|
+
__decorate([
|
|
144
|
+
state()
|
|
145
|
+
], CortiDictation.prototype, "_audioLevel", void 0);
|
|
146
|
+
export default CortiDictation;
|
|
147
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,qBAAqB;AACrB,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mB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AE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;sDACf;AAG3B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uDACiC;AAG5D;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oDACK;AAGxB;IADP,KAAK,EAAE;mDACgB;AA0H1B,eAAe,cAAc,CAAC","sourcesContent":["// corti-dictation.ts\nimport { html, LitElement } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { RecorderManager } from './RecorderManager';\nimport './components/settings-menu';\nimport './components/audio-visualiser';\nimport './icons/icons';\nimport ThemeStyles from './styles/theme';\nimport ButtonStyles from './styles/buttons';\nimport ComponentStyles from './styles/ComponentStyles';\n\nimport { DictationConfig, ServerConfig } from './types';\nimport { DEFAULT_DICTATION_CONFIG } from './constants';\nimport CalloutStyles from './styles/callout';\n\nexport class CortiDictation extends LitElement {\n static styles = [ButtonStyles, ThemeStyles, ComponentStyles, CalloutStyles];\n\n @property({ type: Array })\n devices: MediaDeviceInfo[] = [];\n\n @property({ type: String, reflect: true })\n recordingState = 'stopped';\n\n @property({ type: Object })\n dictationConfig: DictationConfig = DEFAULT_DICTATION_CONFIG;\n\n @property({ type: Object })\n serverConfig: ServerConfig = {};\n\n @state()\n private _audioLevel = 0;\n\n private recorderManager = new RecorderManager();\n\n async connectedCallback() {\n super.connectedCallback();\n await this.recorderManager.initialize();\n this.devices = this.recorderManager.devices;\n\n // Map event names to any extra handling logic\n const eventHandlers: Record<string, (e: CustomEvent) => void> = {\n 'recording-state-changed': e => {\n this.recordingState = e.detail.state;\n },\n 'audio-level-changed': e => {\n this._audioLevel = e.detail.audioLevel;\n this.requestUpdate();\n },\n };\n\n const eventsToRelay = [\n 'recording-state-changed',\n 'audio-level-changed',\n 'error',\n 'transcript',\n ];\n\n eventsToRelay.forEach(eventName => {\n this.recorderManager.addEventListener(eventName, (e: Event) => {\n const customEvent = e as CustomEvent;\n // Perform any additional handling if defined\n if (eventHandlers[eventName]) {\n eventHandlers[eventName](customEvent);\n }\n // Re-dispatch the event from the component\n this.dispatchEvent(\n new CustomEvent(eventName, {\n detail: customEvent.detail,\n bubbles: true,\n composed: true,\n }),\n );\n });\n });\n }\n\n public toggleRecording() {\n this._toggleRecording();\n }\n\n _toggleRecording() {\n if (this.recordingState === 'recording') {\n this.recorderManager.stopRecording();\n } else if (this.recordingState === 'stopped') {\n this.recorderManager.startRecording({\n dictationConfig: this.dictationConfig,\n serverConfig: this.serverConfig,\n });\n }\n }\n\n // Handle device change events if needed\n async _onRecordingDeviceChanged(event: Event) {\n const customEvent = event as CustomEvent;\n this.recorderManager.selectedDevice = customEvent.detail.deviceId;\n if (this.recordingState === 'recording') {\n await this.recorderManager.stopRecording();\n await this.recorderManager.startRecording({\n dictationConfig: this.dictationConfig,\n serverConfig: this.serverConfig,\n });\n }\n }\n\n render() {\n const isConfigured =\n this.serverConfig &&\n this.serverConfig.token &&\n this.serverConfig.environment &&\n this.serverConfig.tenant;\n if (!isConfigured) {\n return html`\n <div class=\"wrapper\">\n <div class=\"callout red tiny\">\n Please configure the server settings in the parent component.\n </div>\n </div>\n `;\n }\n\n const isLoading =\n this.recordingState === 'initializing' ||\n this.recordingState === 'stopping';\n const isRecording = this.recordingState === 'recording';\n return html`\n <div class=\"wrapper\">\n <button\n @click=${this._toggleRecording}\n class=${isRecording ? 'red' : 'accent'}\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 <audio-visualiser\n .level=${this._audioLevel}\n .active=${isRecording}\n ></audio-visualiser>\n </button>\n\n <settings-menu\n .devices=${this.devices}\n .selectedDevice=${this.recorderManager.selectedDevice}\n ?settingsDisabled=${this.recordingState !== 'stopped'}\n @recording-device-changed=${this._onRecordingDeviceChanged}\n ></settings-menu>\n </div>\n `;\n }\n}\n\nexport default CortiDictation;\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export class MediaRecorderService extends EventTarget {
|
|
2
|
+
constructor(mediaStream) {
|
|
3
|
+
super();
|
|
4
|
+
this.mediaRecorder = new MediaRecorder(mediaStream);
|
|
5
|
+
this.mediaRecorder.ondataavailable = (event) => {
|
|
6
|
+
if (event.data && event.data.size > 0) {
|
|
7
|
+
this.dispatchEvent(new CustomEvent('audio-packet', {
|
|
8
|
+
detail: event.data,
|
|
9
|
+
bubbles: true,
|
|
10
|
+
composed: true
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
this.mediaRecorder.onstop = () => {
|
|
15
|
+
// Stub: dispatch a transcript event
|
|
16
|
+
this.dispatchEvent(new CustomEvent('transcript', {
|
|
17
|
+
detail: 'Transcript text here',
|
|
18
|
+
bubbles: true,
|
|
19
|
+
composed: true
|
|
20
|
+
}));
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
startRecording() {
|
|
24
|
+
// Capture audio chunks every 200ms
|
|
25
|
+
this.mediaRecorder.start(200);
|
|
26
|
+
}
|
|
27
|
+
stopRecording() {
|
|
28
|
+
this.mediaRecorder.stop();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=mediaRecorderService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaRecorderService.js","sourceRoot":"","sources":["../../src/mediaRecorderService.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,oBAAqB,SAAQ,WAAW;IAGjD,YAAY,WAAwB;QAClC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,CAAC,aAAa,CAAC,eAAe,GAAG,CAAC,KAAK,EAAE,EAAE;YAC7C,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;gBACtC,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,cAAc,EAAE;oBACjD,MAAM,EAAE,KAAK,CAAC,IAAI;oBAClB,OAAO,EAAE,IAAI;oBACb,QAAQ,EAAE,IAAI;iBACf,CAAC,CAAC,CAAC;YACN,CAAC;QACH,CAAC,CAAC;QACF,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,GAAG,EAAE;YAC/B,oCAAoC;YACpC,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,YAAY,EAAE;gBAC/C,MAAM,EAAE,sBAAsB;gBAC9B,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC,CAAC;QACN,CAAC,CAAC;IACJ,CAAC;IAEM,cAAc;QACnB,mCAAmC;QACnC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAEM,aAAa;QAClB,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["export class MediaRecorderService extends EventTarget {\n private mediaRecorder: MediaRecorder;\n \n constructor(mediaStream: MediaStream) {\n super();\n this.mediaRecorder = new MediaRecorder(mediaStream);\n this.mediaRecorder.ondataavailable = (event) => {\n if (event.data && event.data.size > 0) {\n this.dispatchEvent(new CustomEvent('audio-packet', {\n detail: event.data,\n bubbles: true,\n composed: true\n }));\n }\n };\n this.mediaRecorder.onstop = () => {\n // Stub: dispatch a transcript event\n this.dispatchEvent(new CustomEvent('transcript', {\n detail: 'Transcript text here',\n bubbles: true,\n composed: true\n }));\n };\n }\n \n public startRecording() {\n // Capture audio chunks every 200ms\n this.mediaRecorder.start(200);\n }\n \n public stopRecording() {\n this.mediaRecorder.stop();\n }\n }\n "]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LitElement, TemplateResult, CSSResultGroup } from 'lit';
|
|
2
|
+
interface Device {
|
|
3
|
+
deviceId: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class MicSelector extends LitElement {
|
|
7
|
+
devices: Device[];
|
|
8
|
+
selectedDevice: string;
|
|
9
|
+
static styles: CSSResultGroup;
|
|
10
|
+
private _selectDevice;
|
|
11
|
+
render(): TemplateResult;
|
|
12
|
+
}
|
|
13
|
+
declare global {
|
|
14
|
+
interface HTMLElementTagNameMap {
|
|
15
|
+
'mic-selector': MicSelector;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {};
|