@clarionhq/core 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/lib/emitter.d.ts +9 -0
- package/lib/emitter.d.ts.map +1 -0
- package/lib/emitter.js +26 -0
- package/lib/emitter.js.map +1 -0
- package/lib/engine.d.ts +39 -0
- package/lib/engine.d.ts.map +1 -0
- package/lib/engine.js +2 -0
- package/lib/engine.js.map +1 -0
- package/lib/errors.d.ts +15 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +15 -0
- package/lib/errors.js.map +1 -0
- package/lib/events.d.ts +33 -0
- package/lib/events.d.ts.map +1 -0
- package/lib/events.js +2 -0
- package/lib/events.js.map +1 -0
- package/lib/format.d.ts +10 -0
- package/lib/format.d.ts.map +1 -0
- package/lib/format.js +6 -0
- package/lib/format.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/permissions.d.ts +6 -0
- package/lib/permissions.d.ts.map +1 -0
- package/lib/permissions.js +2 -0
- package/lib/permissions.js.map +1 -0
- package/lib/results.d.ts +22 -0
- package/lib/results.d.ts.map +1 -0
- package/lib/results.js +2 -0
- package/lib/results.js.map +1 -0
- package/lib/state.d.ts +3 -0
- package/lib/state.d.ts.map +1 -0
- package/lib/state.js +2 -0
- package/lib/state.js.map +1 -0
- package/lib/transitions.d.ts +4 -0
- package/lib/transitions.d.ts.map +1 -0
- package/lib/transitions.js +22 -0
- package/lib/transitions.js.map +1 -0
- package/package.json +33 -8
- package/src/emitter.ts +30 -0
- package/src/engine.ts +45 -0
- package/src/errors.ts +41 -0
- package/src/events.ts +17 -0
- package/src/format.ts +15 -0
- package/src/index.ts +11 -0
- package/src/permissions.ts +11 -0
- package/src/results.ts +24 -0
- package/src/state.ts +16 -0
- package/src/transitions.ts +26 -0
- package/index.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Clarion
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/emitter.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ClarionEvent, Listener, Unsubscribe } from './events';
|
|
2
|
+
export declare class ClarionEmitter {
|
|
3
|
+
private listeners;
|
|
4
|
+
on(listener: Listener<ClarionEvent>): Unsubscribe;
|
|
5
|
+
emit(event: ClarionEvent): void;
|
|
6
|
+
removeAll(): void;
|
|
7
|
+
get listenerCount(): number;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter.d.ts","sourceRoot":"","sources":["../src/emitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEpE,qBAAa,cAAc;IACzB,OAAO,CAAC,SAAS,CAAqC;IAEtD,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,WAAW;IAOjD,IAAI,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAU/B,SAAS,IAAI,IAAI;IAIjB,IAAI,aAAa,IAAI,MAAM,CAE1B;CACF"}
|
package/lib/emitter.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class ClarionEmitter {
|
|
2
|
+
listeners = new Set();
|
|
3
|
+
on(listener) {
|
|
4
|
+
this.listeners.add(listener);
|
|
5
|
+
return () => {
|
|
6
|
+
this.listeners.delete(listener);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
emit(event) {
|
|
10
|
+
for (const listener of this.listeners) {
|
|
11
|
+
try {
|
|
12
|
+
listener(event);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// Listener errors must not break the emit loop or other listeners.
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
removeAll() {
|
|
20
|
+
this.listeners.clear();
|
|
21
|
+
}
|
|
22
|
+
get listenerCount() {
|
|
23
|
+
return this.listeners.size;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter.js","sourceRoot":"","sources":["../src/emitter.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,cAAc;IACjB,SAAS,GAAG,IAAI,GAAG,EAA0B,CAAC;IAEtD,EAAE,CAAC,QAAgC;QACjC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,KAAmB;QACtB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,IAAI,CAAC;gBACH,QAAQ,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC;YAAC,MAAM,CAAC;gBACP,mEAAmE;YACrE,CAAC;QACH,CAAC;IACH,CAAC;IAED,SAAS;QACP,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;IAED,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;IAC7B,CAAC;CACF"}
|
package/lib/engine.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ClarionEvent, Listener, Unsubscribe } from './events';
|
|
2
|
+
import type { EngineKind, EngineState } from './state';
|
|
3
|
+
export interface ClarionEngine {
|
|
4
|
+
readonly kind: EngineKind;
|
|
5
|
+
readonly state: EngineState;
|
|
6
|
+
prepare(): Promise<void>;
|
|
7
|
+
start(): Promise<void>;
|
|
8
|
+
pause(): Promise<void>;
|
|
9
|
+
resume(): Promise<void>;
|
|
10
|
+
stop(): Promise<void>;
|
|
11
|
+
discard(): Promise<void>;
|
|
12
|
+
release(): Promise<void>;
|
|
13
|
+
on(listener: Listener<ClarionEvent>): Unsubscribe;
|
|
14
|
+
}
|
|
15
|
+
export interface RecorderEngineConfig {
|
|
16
|
+
outputDirectory?: string;
|
|
17
|
+
filenamePrefix?: string;
|
|
18
|
+
rotateAfterMs?: number;
|
|
19
|
+
emitAudioLevel?: boolean;
|
|
20
|
+
audioLevelIntervalMs?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface RecognizerEngineConfig {
|
|
23
|
+
language: string;
|
|
24
|
+
emitPartials?: boolean;
|
|
25
|
+
maxAlternatives?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface AzureEngineConfig extends RecognizerEngineConfig {
|
|
28
|
+
subscriptionKey?: string;
|
|
29
|
+
region?: string;
|
|
30
|
+
authToken?: string;
|
|
31
|
+
endpoint?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface HybridEngineConfig {
|
|
34
|
+
online: AzureEngineConfig;
|
|
35
|
+
offline: RecorderEngineConfig;
|
|
36
|
+
preferAzureWhen: 'always-if-online' | 'on-good-network';
|
|
37
|
+
retainOfflineCopy?: boolean;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEvD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAE5B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,WAAW,CAAC;CACnD;AAED,MAAM,WAAW,oBAAoB;IACnC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAkB,SAAQ,sBAAsB;IAC/D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,OAAO,EAAE,oBAAoB,CAAC;IAC9B,eAAe,EAAE,kBAAkB,GAAG,iBAAiB,CAAC;IACxD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B"}
|
package/lib/engine.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":""}
|
package/lib/errors.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type ErrorCode = 'PERMISSION_DENIED' | 'AUDIO_BUSY' | 'NETWORK_UNAVAILABLE' | 'NETWORK_TIMEOUT' | 'AUTH_FAILED' | 'QUOTA_EXCEEDED' | 'UNSUPPORTED_LANGUAGE' | 'UNSUPPORTED_FORMAT' | 'NO_SPEECH' | 'INTERRUPTED' | 'CANCELLED' | 'ENGINE_NOT_READY' | 'INVALID_STATE' | 'IO_ERROR' | 'INTERNAL_ERROR' | 'UNKNOWN';
|
|
2
|
+
export interface ClarionErrorOptions {
|
|
3
|
+
code: ErrorCode;
|
|
4
|
+
message: string;
|
|
5
|
+
cause?: unknown;
|
|
6
|
+
recoverable?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class ClarionError extends Error {
|
|
9
|
+
readonly code: ErrorCode;
|
|
10
|
+
readonly recoverable: boolean;
|
|
11
|
+
readonly cause?: unknown;
|
|
12
|
+
constructor(opts: ClarionErrorOptions);
|
|
13
|
+
}
|
|
14
|
+
export declare const isClarionError: (e: unknown) => e is ClarionError;
|
|
15
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,mBAAmB,GACnB,YAAY,GACZ,qBAAqB,GACrB,iBAAiB,GACjB,aAAa,GACb,gBAAgB,GAChB,sBAAsB,GACtB,oBAAoB,GACpB,WAAW,GACX,aAAa,GACb,WAAW,GACX,kBAAkB,GAClB,eAAe,GACf,UAAU,GACV,gBAAgB,GAChB,SAAS,CAAC;AAEd,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,SAAkB,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEtB,IAAI,EAAE,mBAAmB;CAOtC;AAED,eAAO,MAAM,cAAc,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,YACtB,CAAC"}
|
package/lib/errors.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class ClarionError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
recoverable;
|
|
4
|
+
cause;
|
|
5
|
+
constructor(opts) {
|
|
6
|
+
super(opts.message);
|
|
7
|
+
this.name = 'ClarionError';
|
|
8
|
+
this.code = opts.code;
|
|
9
|
+
this.recoverable = opts.recoverable ?? false;
|
|
10
|
+
if (opts.cause !== undefined)
|
|
11
|
+
this.cause = opts.cause;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export const isClarionError = (e) => e instanceof ClarionError;
|
|
15
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAyBA,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,CAAY;IAChB,WAAW,CAAU;IACZ,KAAK,CAAW;IAElC,YAAY,IAAyB;QACnC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,KAAK,CAAC;QAC7C,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IACxD,CAAC;CACF;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAU,EAAqB,EAAE,CAC9D,CAAC,YAAY,YAAY,CAAC"}
|
package/lib/events.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ClarionError } from './errors';
|
|
2
|
+
import type { RecorderResult, TranscriptResult } from './results';
|
|
3
|
+
import type { EngineState } from './state';
|
|
4
|
+
export type ClarionEvent = {
|
|
5
|
+
type: 'state';
|
|
6
|
+
state: EngineState;
|
|
7
|
+
} | {
|
|
8
|
+
type: 'audio-level';
|
|
9
|
+
rms: number;
|
|
10
|
+
peak: number;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'partial';
|
|
13
|
+
result: TranscriptResult;
|
|
14
|
+
} | {
|
|
15
|
+
type: 'final';
|
|
16
|
+
result: TranscriptResult;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'chunk';
|
|
19
|
+
uri: string;
|
|
20
|
+
startMs: number;
|
|
21
|
+
endMs: number;
|
|
22
|
+
sizeBytes: number;
|
|
23
|
+
} | {
|
|
24
|
+
type: 'recording-complete';
|
|
25
|
+
result: RecorderResult;
|
|
26
|
+
} | {
|
|
27
|
+
type: 'error';
|
|
28
|
+
error: ClarionError;
|
|
29
|
+
};
|
|
30
|
+
export type ClarionEventType = ClarionEvent['type'];
|
|
31
|
+
export type Listener<T> = (event: T) => void;
|
|
32
|
+
export type Unsubscribe = () => void;
|
|
33
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACjF;IAAE,IAAI,EAAE,oBAAoB,CAAC;IAAC,MAAM,EAAE,cAAc,CAAA;CAAE,GACtD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,CAAC;AAE3C,MAAM,MAAM,gBAAgB,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;AAEpD,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAC7C,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC"}
|
package/lib/events.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":""}
|
package/lib/format.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type SampleRate = 8000 | 16000 | 22050 | 44100 | 48000;
|
|
2
|
+
export type ChannelCount = 1 | 2;
|
|
3
|
+
export type BitDepth = 16 | 24 | 32;
|
|
4
|
+
export interface AudioFormat {
|
|
5
|
+
sampleRate: SampleRate;
|
|
6
|
+
channels: ChannelCount;
|
|
7
|
+
bitDepth: BitDepth;
|
|
8
|
+
}
|
|
9
|
+
export declare const DEFAULT_AUDIO_FORMAT: AudioFormat;
|
|
10
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAC9D,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,CAAC,CAAC;AACjC,MAAM,MAAM,QAAQ,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAEpC,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,YAAY,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,eAAO,MAAM,oBAAoB,EAAE,WAIlC,CAAC"}
|
package/lib/format.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,oBAAoB,GAAgB;IAC/C,UAAU,EAAE,KAAK;IACjB,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,EAAE;CACb,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './state';
|
|
2
|
+
export * from './format';
|
|
3
|
+
export * from './results';
|
|
4
|
+
export * from './errors';
|
|
5
|
+
export * from './events';
|
|
6
|
+
export * from './permissions';
|
|
7
|
+
export * from './engine';
|
|
8
|
+
export * from './emitter';
|
|
9
|
+
export * from './transitions';
|
|
10
|
+
export declare const CLARION_CORE_VERSION = "0.0.1";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAE9B,eAAO,MAAM,oBAAoB,UAAU,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './state';
|
|
2
|
+
export * from './format';
|
|
3
|
+
export * from './results';
|
|
4
|
+
export * from './errors';
|
|
5
|
+
export * from './events';
|
|
6
|
+
export * from './permissions';
|
|
7
|
+
export * from './engine';
|
|
8
|
+
export * from './emitter';
|
|
9
|
+
export * from './transitions';
|
|
10
|
+
export const CLARION_CORE_VERSION = '0.0.1';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAE9B,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,QAAQ,GACR,cAAc,GACd,YAAY,GACZ,SAAS,CAAC;AAEd,MAAM,WAAW,cAAc;IAC7B,KAAK,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACnC,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":""}
|
package/lib/results.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AudioFormat } from './format';
|
|
2
|
+
export interface RecorderResult {
|
|
3
|
+
uri: string;
|
|
4
|
+
durationMs: number;
|
|
5
|
+
sizeBytes: number;
|
|
6
|
+
container: 'm4a';
|
|
7
|
+
audioFormat: AudioFormat;
|
|
8
|
+
}
|
|
9
|
+
export interface TranscriptAlternative {
|
|
10
|
+
text: string;
|
|
11
|
+
confidence: number;
|
|
12
|
+
}
|
|
13
|
+
export interface TranscriptResult {
|
|
14
|
+
text: string;
|
|
15
|
+
isFinal: boolean;
|
|
16
|
+
confidence?: number;
|
|
17
|
+
language?: string;
|
|
18
|
+
alternatives?: TranscriptAlternative[];
|
|
19
|
+
offsetMs?: number;
|
|
20
|
+
durationMs?: number;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=results.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,qBAAqB,EAAE,CAAC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
package/lib/results.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.js","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":""}
|
package/lib/state.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,WAAW,GACX,OAAO,GACP,UAAU,GACV,WAAW,GACX,QAAQ,GACR,UAAU,GACV,OAAO,GACP,UAAU,CAAC;AAEf,MAAM,MAAM,UAAU,GAClB,UAAU,GACV,mBAAmB,GACnB,kBAAkB,GAClB,QAAQ,CAAC"}
|
package/lib/state.js
ADDED
package/lib/state.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transitions.d.ts","sourceRoot":"","sources":["../src/transitions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAc3C,eAAO,MAAM,aAAa,GAAI,MAAM,WAAW,EAAE,IAAI,WAAW,KAAG,OACnC,CAAC;AAEjC,eAAO,MAAM,gBAAgB,GAAI,MAAM,WAAW,EAAE,IAAI,WAAW,KAAG,IAOrE,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ClarionError } from './errors';
|
|
2
|
+
const TRANSITIONS = {
|
|
3
|
+
idle: ['preparing', 'released'],
|
|
4
|
+
preparing: ['ready', 'error', 'released'],
|
|
5
|
+
ready: ['starting', 'released', 'error'],
|
|
6
|
+
starting: ['recording', 'error', 'released'],
|
|
7
|
+
recording: ['paused', 'stopping', 'error', 'released'],
|
|
8
|
+
paused: ['recording', 'stopping', 'error', 'released'],
|
|
9
|
+
stopping: ['ready', 'idle', 'error', 'released'],
|
|
10
|
+
error: ['idle', 'released'],
|
|
11
|
+
released: [],
|
|
12
|
+
};
|
|
13
|
+
export const canTransition = (from, to) => TRANSITIONS[from].includes(to);
|
|
14
|
+
export const assertTransition = (from, to) => {
|
|
15
|
+
if (!canTransition(from, to)) {
|
|
16
|
+
throw new ClarionError({
|
|
17
|
+
code: 'INVALID_STATE',
|
|
18
|
+
message: `Illegal state transition: ${from} → ${to}`,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=transitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transitions.js","sourceRoot":"","sources":["../src/transitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGxC,MAAM,WAAW,GAAgD;IAC/D,IAAI,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC;IAC/B,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC;IACzC,KAAK,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC;IACxC,QAAQ,EAAE,CAAC,WAAW,EAAE,OAAO,EAAE,UAAU,CAAC;IAC5C,SAAS,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC;IACtD,MAAM,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC;IACtD,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC;IAChD,KAAK,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC;IAC3B,QAAQ,EAAE,EAAE;CACb,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAiB,EAAE,EAAe,EAAW,EAAE,CAC3E,WAAW,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAEjC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAiB,EAAE,EAAe,EAAQ,EAAE;IAC3E,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,YAAY,CAAC;YACrB,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE,6BAA6B,IAAI,MAAM,EAAE,EAAE;SACrD,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clarionhq/core",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "Clarion core —
|
|
5
|
-
"main": "index.js",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Clarion core — shared types, interfaces, errors, and state machine",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"source": "src/index.ts",
|
|
8
|
+
"react-native": "src/index.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"lib",
|
|
11
|
+
"src",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"react-native",
|
|
17
|
+
"audio",
|
|
18
|
+
"speech",
|
|
19
|
+
"voice",
|
|
20
|
+
"types"
|
|
21
|
+
],
|
|
6
22
|
"license": "MIT",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/Th4nderG0d/clarion",
|
|
29
|
+
"directory": "packages/core"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -p tsconfig.json",
|
|
33
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
34
|
+
"clean": "rm -rf lib"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/emitter.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ClarionEvent, Listener, Unsubscribe } from './events';
|
|
2
|
+
|
|
3
|
+
export class ClarionEmitter {
|
|
4
|
+
private listeners = new Set<Listener<ClarionEvent>>();
|
|
5
|
+
|
|
6
|
+
on(listener: Listener<ClarionEvent>): Unsubscribe {
|
|
7
|
+
this.listeners.add(listener);
|
|
8
|
+
return () => {
|
|
9
|
+
this.listeners.delete(listener);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
emit(event: ClarionEvent): void {
|
|
14
|
+
for (const listener of this.listeners) {
|
|
15
|
+
try {
|
|
16
|
+
listener(event);
|
|
17
|
+
} catch {
|
|
18
|
+
// Listener errors must not break the emit loop or other listeners.
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
removeAll(): void {
|
|
24
|
+
this.listeners.clear();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get listenerCount(): number {
|
|
28
|
+
return this.listeners.size;
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/engine.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ClarionEvent, Listener, Unsubscribe } from './events';
|
|
2
|
+
import type { EngineKind, EngineState } from './state';
|
|
3
|
+
|
|
4
|
+
export interface ClarionEngine {
|
|
5
|
+
readonly kind: EngineKind;
|
|
6
|
+
readonly state: EngineState;
|
|
7
|
+
|
|
8
|
+
prepare(): Promise<void>;
|
|
9
|
+
start(): Promise<void>;
|
|
10
|
+
pause(): Promise<void>;
|
|
11
|
+
resume(): Promise<void>;
|
|
12
|
+
stop(): Promise<void>;
|
|
13
|
+
discard(): Promise<void>;
|
|
14
|
+
release(): Promise<void>;
|
|
15
|
+
|
|
16
|
+
on(listener: Listener<ClarionEvent>): Unsubscribe;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface RecorderEngineConfig {
|
|
20
|
+
outputDirectory?: string;
|
|
21
|
+
filenamePrefix?: string;
|
|
22
|
+
rotateAfterMs?: number;
|
|
23
|
+
emitAudioLevel?: boolean;
|
|
24
|
+
audioLevelIntervalMs?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface RecognizerEngineConfig {
|
|
28
|
+
language: string;
|
|
29
|
+
emitPartials?: boolean;
|
|
30
|
+
maxAlternatives?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AzureEngineConfig extends RecognizerEngineConfig {
|
|
34
|
+
subscriptionKey?: string;
|
|
35
|
+
region?: string;
|
|
36
|
+
authToken?: string;
|
|
37
|
+
endpoint?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface HybridEngineConfig {
|
|
41
|
+
online: AzureEngineConfig;
|
|
42
|
+
offline: RecorderEngineConfig;
|
|
43
|
+
preferAzureWhen: 'always-if-online' | 'on-good-network';
|
|
44
|
+
retainOfflineCopy?: boolean;
|
|
45
|
+
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type ErrorCode =
|
|
2
|
+
| 'PERMISSION_DENIED'
|
|
3
|
+
| 'AUDIO_BUSY'
|
|
4
|
+
| 'NETWORK_UNAVAILABLE'
|
|
5
|
+
| 'NETWORK_TIMEOUT'
|
|
6
|
+
| 'AUTH_FAILED'
|
|
7
|
+
| 'QUOTA_EXCEEDED'
|
|
8
|
+
| 'UNSUPPORTED_LANGUAGE'
|
|
9
|
+
| 'UNSUPPORTED_FORMAT'
|
|
10
|
+
| 'NO_SPEECH'
|
|
11
|
+
| 'INTERRUPTED'
|
|
12
|
+
| 'CANCELLED'
|
|
13
|
+
| 'ENGINE_NOT_READY'
|
|
14
|
+
| 'INVALID_STATE'
|
|
15
|
+
| 'IO_ERROR'
|
|
16
|
+
| 'INTERNAL_ERROR'
|
|
17
|
+
| 'UNKNOWN';
|
|
18
|
+
|
|
19
|
+
export interface ClarionErrorOptions {
|
|
20
|
+
code: ErrorCode;
|
|
21
|
+
message: string;
|
|
22
|
+
cause?: unknown;
|
|
23
|
+
recoverable?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class ClarionError extends Error {
|
|
27
|
+
readonly code: ErrorCode;
|
|
28
|
+
readonly recoverable: boolean;
|
|
29
|
+
override readonly cause?: unknown;
|
|
30
|
+
|
|
31
|
+
constructor(opts: ClarionErrorOptions) {
|
|
32
|
+
super(opts.message);
|
|
33
|
+
this.name = 'ClarionError';
|
|
34
|
+
this.code = opts.code;
|
|
35
|
+
this.recoverable = opts.recoverable ?? false;
|
|
36
|
+
if (opts.cause !== undefined) this.cause = opts.cause;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const isClarionError = (e: unknown): e is ClarionError =>
|
|
41
|
+
e instanceof ClarionError;
|
package/src/events.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ClarionError } from './errors';
|
|
2
|
+
import type { RecorderResult, TranscriptResult } from './results';
|
|
3
|
+
import type { EngineState } from './state';
|
|
4
|
+
|
|
5
|
+
export type ClarionEvent =
|
|
6
|
+
| { type: 'state'; state: EngineState }
|
|
7
|
+
| { type: 'audio-level'; rms: number; peak: number }
|
|
8
|
+
| { type: 'partial'; result: TranscriptResult }
|
|
9
|
+
| { type: 'final'; result: TranscriptResult }
|
|
10
|
+
| { type: 'chunk'; uri: string; startMs: number; endMs: number; sizeBytes: number }
|
|
11
|
+
| { type: 'recording-complete'; result: RecorderResult }
|
|
12
|
+
| { type: 'error'; error: ClarionError };
|
|
13
|
+
|
|
14
|
+
export type ClarionEventType = ClarionEvent['type'];
|
|
15
|
+
|
|
16
|
+
export type Listener<T> = (event: T) => void;
|
|
17
|
+
export type Unsubscribe = () => void;
|
package/src/format.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type SampleRate = 8000 | 16000 | 22050 | 44100 | 48000;
|
|
2
|
+
export type ChannelCount = 1 | 2;
|
|
3
|
+
export type BitDepth = 16 | 24 | 32;
|
|
4
|
+
|
|
5
|
+
export interface AudioFormat {
|
|
6
|
+
sampleRate: SampleRate;
|
|
7
|
+
channels: ChannelCount;
|
|
8
|
+
bitDepth: BitDepth;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const DEFAULT_AUDIO_FORMAT: AudioFormat = {
|
|
12
|
+
sampleRate: 16000,
|
|
13
|
+
channels: 1,
|
|
14
|
+
bitDepth: 16,
|
|
15
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './state';
|
|
2
|
+
export * from './format';
|
|
3
|
+
export * from './results';
|
|
4
|
+
export * from './errors';
|
|
5
|
+
export * from './events';
|
|
6
|
+
export * from './permissions';
|
|
7
|
+
export * from './engine';
|
|
8
|
+
export * from './emitter';
|
|
9
|
+
export * from './transitions';
|
|
10
|
+
|
|
11
|
+
export const CLARION_CORE_VERSION = '0.0.1';
|
package/src/results.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AudioFormat } from './format';
|
|
2
|
+
|
|
3
|
+
export interface RecorderResult {
|
|
4
|
+
uri: string;
|
|
5
|
+
durationMs: number;
|
|
6
|
+
sizeBytes: number;
|
|
7
|
+
container: 'm4a';
|
|
8
|
+
audioFormat: AudioFormat;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface TranscriptAlternative {
|
|
12
|
+
text: string;
|
|
13
|
+
confidence: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TranscriptResult {
|
|
17
|
+
text: string;
|
|
18
|
+
isFinal: boolean;
|
|
19
|
+
confidence?: number;
|
|
20
|
+
language?: string;
|
|
21
|
+
alternatives?: TranscriptAlternative[];
|
|
22
|
+
offsetMs?: number;
|
|
23
|
+
durationMs?: number;
|
|
24
|
+
}
|
package/src/state.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type EngineState =
|
|
2
|
+
| 'idle'
|
|
3
|
+
| 'preparing'
|
|
4
|
+
| 'ready'
|
|
5
|
+
| 'starting'
|
|
6
|
+
| 'recording'
|
|
7
|
+
| 'paused'
|
|
8
|
+
| 'stopping'
|
|
9
|
+
| 'error'
|
|
10
|
+
| 'released';
|
|
11
|
+
|
|
12
|
+
export type EngineKind =
|
|
13
|
+
| 'recorder'
|
|
14
|
+
| 'native-recognizer'
|
|
15
|
+
| 'azure-recognizer'
|
|
16
|
+
| 'hybrid';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ClarionError } from './errors';
|
|
2
|
+
import type { EngineState } from './state';
|
|
3
|
+
|
|
4
|
+
const TRANSITIONS: Record<EngineState, readonly EngineState[]> = {
|
|
5
|
+
idle: ['preparing', 'released'],
|
|
6
|
+
preparing: ['ready', 'error', 'released'],
|
|
7
|
+
ready: ['starting', 'released', 'error'],
|
|
8
|
+
starting: ['recording', 'error', 'released'],
|
|
9
|
+
recording: ['paused', 'stopping', 'error', 'released'],
|
|
10
|
+
paused: ['recording', 'stopping', 'error', 'released'],
|
|
11
|
+
stopping: ['ready', 'idle', 'error', 'released'],
|
|
12
|
+
error: ['idle', 'released'],
|
|
13
|
+
released: [],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const canTransition = (from: EngineState, to: EngineState): boolean =>
|
|
17
|
+
TRANSITIONS[from].includes(to);
|
|
18
|
+
|
|
19
|
+
export const assertTransition = (from: EngineState, to: EngineState): void => {
|
|
20
|
+
if (!canTransition(from, to)) {
|
|
21
|
+
throw new ClarionError({
|
|
22
|
+
code: 'INVALID_STATE',
|
|
23
|
+
message: `Illegal state transition: ${from} → ${to}`,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
};
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// @clarionhq/core — placeholder. See https://github.com/clarionhq/clarion
|