@gemies/sdk 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1678 -0
- package/LICENSE +202 -0
- package/NOTICE +15 -0
- package/README.md +516 -2
- package/package.json +105 -4
- package/src/accounts.ts +29 -0
- package/src/animations.ts +5 -0
- package/src/ask-eager.ts +8 -0
- package/src/ask-text.ts +11 -0
- package/src/ask.ts +12 -0
- package/src/avatar.ts +13 -0
- package/src/character.ts +1 -0
- package/src/components/AmbientField.tsx +580 -0
- package/src/components/ComposerDropZone.tsx +235 -0
- package/src/components/ComposerSuggestions.tsx +45 -0
- package/src/components/GemieAccounts.tsx +433 -0
- package/src/components/GemieAskCore.tsx +184 -0
- package/src/components/GemieAskProvider.tsx +18 -0
- package/src/components/GemieAskProviderLazy.tsx +27 -0
- package/src/components/GemieAskProviderText.tsx +25 -0
- package/src/components/GemieAskSheet.tsx +51 -0
- package/src/components/GemieAskSheetWithVoice.tsx +10 -0
- package/src/components/GemieAvatar.tsx +57 -0
- package/src/components/GemieAvatarIcon.tsx +35 -0
- package/src/components/GemieChatContent.tsx +900 -0
- package/src/components/GemieChatHeader.tsx +123 -0
- package/src/components/GemieChatScreen.tsx +170 -0
- package/src/components/GemieChatSheet.tsx +368 -0
- package/src/components/GemieChatWithVoice.tsx +13 -0
- package/src/components/GemieComposer.tsx +388 -0
- package/src/components/GemieGroupWelcome.tsx +37 -0
- package/src/components/GemieParticipants.tsx +133 -0
- package/src/components/GemieParticipantsHeader.tsx +27 -0
- package/src/components/GemieRecentConversations.tsx +65 -0
- package/src/components/GemieSharedConversation.tsx +87 -0
- package/src/components/GemieWelcomeMessage.tsx +58 -0
- package/src/components/IdentityMark.tsx +225 -0
- package/src/components/Image.tsx +12 -0
- package/src/components/InertWhen.tsx +48 -0
- package/src/components/PlanPreviewCard.tsx +53 -0
- package/src/components/QuestionCard.tsx +64 -0
- package/src/components/ReplyMarkdown.tsx +373 -0
- package/src/components/RichBlocks.tsx +195 -0
- package/src/components/VoiceModeIcon.tsx +18 -0
- package/src/components/canvas/CanvasComponent.tsx +65 -0
- package/src/components/canvas/ChartRenderer.tsx +73 -0
- package/src/components/canvas/CodeRenderer.tsx +20 -0
- package/src/components/canvas/DashboardRenderer.tsx +70 -0
- package/src/components/canvas/DeckRenderer.tsx +43 -0
- package/src/components/canvas/FormRenderer.tsx +101 -0
- package/src/components/canvas/MarkdownRenderer.tsx +14 -0
- package/src/components/canvas/TableRenderer.tsx +47 -0
- package/src/components/icons/RiEmojiPicker.tsx +39 -0
- package/src/components/icons/RiMoreDots.tsx +32 -0
- package/src/components/icons/RiReplyLine.tsx +25 -0
- package/src/components/thought/FilesAndSources.tsx +120 -0
- package/src/components/thought/ThoughtPanel.tsx +426 -0
- package/src/components/thought/ToolStep.tsx +134 -0
- package/src/components/thread/AgentExchangeView.tsx +112 -0
- package/src/components/thread/AgentResultCard.tsx +125 -0
- package/src/components/thread/AgentTaskCard.tsx +127 -0
- package/src/components/thread/ChatBubble.tsx +256 -0
- package/src/components/thread/GemieThread.tsx +455 -0
- package/src/components/thread/MessageBlockBoundary.tsx +78 -0
- package/src/components/thread/NewConversationOffer.tsx +54 -0
- package/src/components/thread/ThreadRow.tsx +598 -0
- package/src/components/thread/ThreadSearch.tsx +130 -0
- package/src/components/thread/ThreadSkeleton.tsx +30 -0
- package/src/components/thread/ToolResultCard.tsx +254 -0
- package/src/components/thread/TurnMenu.tsx +54 -0
- package/src/components/thread/TurnStatusLine.tsx +34 -0
- package/src/components/voice/GemieVoiceCall.tsx +21 -0
- package/src/components/voice/GemieVoiceCall.web.tsx +17 -0
- package/src/components/voice/VoiceCallContext.ts +13 -0
- package/src/components/voice/VoiceControls.tsx +106 -0
- package/src/components/voice/VoiceSession.tsx +120 -0
- package/src/components/voice/withVoiceCall.tsx +25 -0
- package/src/csp.ts +50 -0
- package/src/dictation.ts +40 -0
- package/src/hooks/useAmbientWave.ts +184 -0
- package/src/hooks/useAtBottom.ts +51 -0
- package/src/hooks/useAttachMenu.ts +93 -0
- package/src/hooks/useAttachmentIntake.ts +401 -0
- package/src/hooks/useAudioLevelMonitor.ts +46 -0
- package/src/hooks/useAudioLevels.ts +51 -0
- package/src/hooks/useChatComposer.ts +309 -0
- package/src/hooks/useChatVoice.ts +129 -0
- package/src/hooks/useComposerSuggestions.ts +84 -0
- package/src/hooks/useDictation.ts +292 -0
- package/src/hooks/useDocumentPicker.ts +11 -0
- package/src/hooks/useFailedTurnToast.ts +43 -0
- package/src/hooks/useFocusWhenPresented.ts +41 -0
- package/src/hooks/useGemieActivity.ts +31 -0
- package/src/hooks/useImagePicker.ts +38 -0
- package/src/hooks/useMessageReactions.ts +119 -0
- package/src/hooks/useMessageVote.ts +50 -0
- package/src/hooks/useOpenThought.ts +79 -0
- package/src/hooks/usePendingQuestions.ts +19 -0
- package/src/hooks/useReadAloud.ts +92 -0
- package/src/hooks/useShareHandler.ts +24 -0
- package/src/hooks/useSoundEffects.ts +137 -0
- package/src/hooks/useTTS.ts +303 -0
- package/src/hooks/useThoughtScope.ts +59 -0
- package/src/hooks/useThreadRows.ts +157 -0
- package/src/hooks/useThreadView.ts +67 -0
- package/src/hooks/useTimelineWindow.ts +256 -0
- package/src/hooks/useVoiceLauncher.ts +180 -0
- package/src/hooks/useVoiceRoom.ts +212 -0
- package/src/index.ts +141 -0
- package/src/lib/activity-socket.ts +102 -0
- package/src/lib/activity-store.ts +53 -0
- package/src/lib/add-menu.ts +7 -0
- package/src/lib/agent-character.ts +28 -0
- package/src/lib/alia-character.ts +14 -0
- package/src/lib/alia-gemie.ts +6 -0
- package/src/lib/attachment-intake.ts +154 -0
- package/src/lib/attachment-tiles.ts +74 -0
- package/src/lib/audio-level.ts +130 -0
- package/src/lib/audio-request-auth.ts +4 -0
- package/src/lib/audio-session-binding.ts +27 -0
- package/src/lib/bubbles.tsx +16 -0
- package/src/lib/call-thread.ts +33 -0
- package/src/lib/canvas-result.ts +21 -0
- package/src/lib/catalogue-tool.ts +22 -0
- package/src/lib/citations.ts +192 -0
- package/src/lib/clipboard.ts +23 -0
- package/src/lib/content-utils.ts +46 -0
- package/src/lib/copy-en.ts +333 -0
- package/src/lib/copy-es.ts +330 -0
- package/src/lib/copy.ts +38 -0
- package/src/lib/deferred/document-picker.ts +2 -0
- package/src/lib/deferred/document-picker.web.ts +12 -0
- package/src/lib/deferred/expo-audio.ts +2 -0
- package/src/lib/deferred/expo-audio.web.ts +12 -0
- package/src/lib/deferred/image-data-url.ts +5 -0
- package/src/lib/deferred/image-data-url.web.ts +12 -0
- package/src/lib/dictation-protocol.ts +142 -0
- package/src/lib/dictation-recorder-types.ts +37 -0
- package/src/lib/dictation-recorder.native.ts +90 -0
- package/src/lib/dictation-recorder.ts +131 -0
- package/src/lib/dictation-stream.ts +238 -0
- package/src/lib/dictation.ts +216 -0
- package/src/lib/document-picker.ts +31 -0
- package/src/lib/domain.ts +12 -0
- package/src/lib/flights.ts +33 -0
- package/src/lib/focus-return.ts +66 -0
- package/src/lib/greeting.ts +15 -0
- package/src/lib/image-data-url.ts +35 -0
- package/src/lib/keyboard.native.tsx +25 -0
- package/src/lib/keyboard.tsx +55 -0
- package/src/lib/labels-es.ts +113 -0
- package/src/lib/labels.tsx +207 -0
- package/src/lib/origins.ts +28 -0
- package/src/lib/participants.ts +97 -0
- package/src/lib/pcm.ts +57 -0
- package/src/lib/power-level-options.ts +66 -0
- package/src/lib/questions.ts +92 -0
- package/src/lib/speech-language.ts +20 -0
- package/src/lib/speech-messages.ts +54 -0
- package/src/lib/speech-synthesis.ts +156 -0
- package/src/lib/suggestions.ts +53 -0
- package/src/lib/task-labels.ts +35 -0
- package/src/lib/text-input.ts +10 -0
- package/src/lib/tool-call-status.ts +28 -0
- package/src/lib/tool-icons.ts +36 -0
- package/src/lib/tool-registry.ts +71 -0
- package/src/lib/tool-renderers.tsx +32 -0
- package/src/lib/turn-state.ts +15 -0
- package/src/lib/utils.ts +35 -0
- package/src/lib/voice-audio-engine-types.ts +59 -0
- package/src/lib/voice-audio-engine.native.ts +232 -0
- package/src/lib/voice-audio-engine.ts +206 -0
- package/src/lib/voice-call-request.ts +49 -0
- package/src/lib/voice-call.ts +627 -0
- package/src/lib/voice-controls-labels.ts +31 -0
- package/src/lib/voice-levels.ts +64 -0
- package/src/lib/voice-protocol.ts +328 -0
- package/src/lib/voice-worklets.ts +19 -0
- package/src/lib/work-log.ts +370 -0
- package/src/metro/chart-importers.json +18 -0
- package/src/metro/granular-charts.js +3 -0
- package/src/metro/index.cjs +227 -0
- package/src/metro/index.d.cts +5 -0
- package/src/runtime/agents.ts +151 -0
- package/src/runtime/api.ts +144 -0
- package/src/runtime/app-assertion.ts +51 -0
- package/src/runtime/attachment-utils.ts +97 -0
- package/src/runtime/chat-turn-control.ts +74 -0
- package/src/runtime/composer-draft-store.ts +270 -0
- package/src/runtime/config.tsx +222 -0
- package/src/runtime/conversation-dates.ts +31 -0
- package/src/runtime/conversation-store.ts +49 -0
- package/src/runtime/conversations.ts +633 -0
- package/src/runtime/error-utils.ts +144 -0
- package/src/runtime/gemie-accounts.ts +182 -0
- package/src/runtime/host-tools.ts +290 -0
- package/src/runtime/index.ts +137 -0
- package/src/runtime/message-history.ts +124 -0
- package/src/runtime/message-reactions.ts +214 -0
- package/src/runtime/model.ts +39 -0
- package/src/runtime/oxy-files.ts +37 -0
- package/src/runtime/power-levels.ts +66 -0
- package/src/runtime/query-keys.ts +60 -0
- package/src/runtime/random-uuid.ts +25 -0
- package/src/runtime/reaction-cache.ts +45 -0
- package/src/runtime/room-events.ts +333 -0
- package/src/runtime/routes.ts +85 -0
- package/src/runtime/sharing.ts +217 -0
- package/src/runtime/sse-frame-reader.ts +88 -0
- package/src/runtime/stream-events.ts +154 -0
- package/src/runtime/stream-outcome.ts +21 -0
- package/src/runtime/thought-store.ts +103 -0
- package/src/runtime/thread/agent-activity.ts +261 -0
- package/src/runtime/thread/agent-exchange.ts +94 -0
- package/src/runtime/thread/automation-labels.ts +79 -0
- package/src/runtime/thread/conversation-export.ts +135 -0
- package/src/runtime/thread/message-days.ts +120 -0
- package/src/runtime/thread/message-processor.ts +93 -0
- package/src/runtime/thread/speaker-changes.ts +66 -0
- package/src/runtime/thread/task-utils.ts +11 -0
- package/src/runtime/thread/thought-utils.ts +750 -0
- package/src/runtime/thread/thread-history.ts +139 -0
- package/src/runtime/thread/timeline.ts +202 -0
- package/src/runtime/thread/title-tags.ts +8 -0
- package/src/runtime/thread/tool-cards.ts +387 -0
- package/src/runtime/turn-failure.ts +108 -0
- package/src/runtime/turn-preparation.ts +21 -0
- package/src/runtime/types.ts +172 -0
- package/src/runtime/usage-limit-error.ts +44 -0
- package/src/runtime/use-agent-activity.ts +80 -0
- package/src/runtime/use-conversation-stream.ts +1669 -0
- package/src/runtime/use-conversation-thread.ts +590 -0
- package/src/runtime/use-gemie-thread.ts +54 -0
- package/src/runtime/use-room-events.ts +75 -0
- package/src/runtime/use-start-conversation.ts +107 -0
- package/src/runtime/use-thread-history.ts +73 -0
- package/src/runtime/use-thread-search.ts +100 -0
- package/src/runtime/use-turn-edit.ts +99 -0
- package/src/text.ts +19 -0
- package/src/theme.ts +16 -0
- package/src/tools.ts +27 -0
- package/src/types.ts +161 -0
- package/src/voice-messages.ts +2 -0
- package/src/voice.ts +67 -0
- package/tsconfig.json +17 -0
- package/worklets/voice-processors.js +152 -0
package/src/voice.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/// <reference types="nativewind/types" />
|
|
2
|
+
// @gemies/sdk/voice — Alia voice surface
|
|
3
|
+
// The voice call (speech to speech through Alia's /v1/voice/session and Kaana),
|
|
4
|
+
// its audio engine, audio visualisation, ambient wave and sound effects. Split
|
|
5
|
+
// out of the root entry so text-chat consumers never compile the call or
|
|
6
|
+
// `react-native-audio-api`.
|
|
7
|
+
|
|
8
|
+
// ── Voice components ──
|
|
9
|
+
export { VoiceSession } from './components/voice/VoiceSession';
|
|
10
|
+
export { VoiceControls } from './components/voice/VoiceControls';
|
|
11
|
+
export { VOICE_CONTROLS_LABELS } from './components/voice/VoiceControls';
|
|
12
|
+
export type { VoiceControlsLabels, VoiceControlsProps } from './components/voice/VoiceControls';
|
|
13
|
+
|
|
14
|
+
// ── Voice hooks ──
|
|
15
|
+
export { useVoiceRoom, roomStateOf, agentStateOf } from './hooks/useVoiceRoom';
|
|
16
|
+
export type { UseVoiceRoomOptions } from './hooks/useVoiceRoom';
|
|
17
|
+
export { VoiceCall } from './lib/voice-call';
|
|
18
|
+
export type {
|
|
19
|
+
VoiceCallOptions,
|
|
20
|
+
VoiceCallSnapshot,
|
|
21
|
+
VoiceSocket,
|
|
22
|
+
VoiceSocketFactory,
|
|
23
|
+
} from './lib/voice-call';
|
|
24
|
+
export { createVoiceAudioEngine, VoiceAudioEngineError } from './lib/voice-audio-engine';
|
|
25
|
+
export type {
|
|
26
|
+
VoiceAudioEngine,
|
|
27
|
+
VoiceAudioEngineErrorCode,
|
|
28
|
+
VoiceAudioEngineHandlers,
|
|
29
|
+
} from './lib/voice-audio-engine-types';
|
|
30
|
+
export {
|
|
31
|
+
VOICE_PROTOCOL_VERSION,
|
|
32
|
+
VOICE_SAMPLE_RATE,
|
|
33
|
+
decodeAssistantAudioFrame,
|
|
34
|
+
encodeAssistantAudioFrame,
|
|
35
|
+
voiceSessionUrl,
|
|
36
|
+
} from './lib/voice-protocol';
|
|
37
|
+
export type {
|
|
38
|
+
VoiceClientEvent,
|
|
39
|
+
VoiceCloseReason,
|
|
40
|
+
VoiceServerErrorCode,
|
|
41
|
+
VoiceServerEvent,
|
|
42
|
+
} from './lib/voice-protocol';
|
|
43
|
+
export type { VoiceLevelSource } from './lib/voice-levels';
|
|
44
|
+
export { VOICE_ERROR_MESSAGES } from './lib/speech-messages';
|
|
45
|
+
export type { VoiceErrorCode } from './lib/speech-messages';
|
|
46
|
+
export { useAudioLevelMonitor } from './hooks/useAudioLevelMonitor';
|
|
47
|
+
export { useAudioLevels } from './hooks/useAudioLevels';
|
|
48
|
+
export { useAmbientWave } from './hooks/useAmbientWave';
|
|
49
|
+
export type {
|
|
50
|
+
UseAmbientWaveOptions,
|
|
51
|
+
UseAmbientWaveResult,
|
|
52
|
+
AmbientWaveVoice,
|
|
53
|
+
AmbientWaveMode,
|
|
54
|
+
} from './hooks/useAmbientWave';
|
|
55
|
+
export { useSoundEffects, useVoiceSoundEffects } from './hooks/useSoundEffects';
|
|
56
|
+
export type { SoundName, SoundSources } from './hooks/useSoundEffects';
|
|
57
|
+
|
|
58
|
+
// ── Voice types ──
|
|
59
|
+
export type {
|
|
60
|
+
RoomState,
|
|
61
|
+
AgentState,
|
|
62
|
+
VoiceCallState,
|
|
63
|
+
VoiceMessage,
|
|
64
|
+
VoiceToolInvocation,
|
|
65
|
+
VoiceSessionProps,
|
|
66
|
+
VoiceSessionState,
|
|
67
|
+
} from './types';
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"erasableSyntaxOnly": true,
|
|
9
|
+
"noUnusedLocals": true,
|
|
10
|
+
"noUnusedParameters": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"declaration": true,
|
|
14
|
+
"outDir": "lib"
|
|
15
|
+
},
|
|
16
|
+
"include": ["src", "tests"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// The web voice call's two AudioWorklet processors (`src/lib/voice-audio-engine.ts`).
|
|
2
|
+
//
|
|
3
|
+
// Served from Alia's web origin, content-addressed (`/sdk/voice-worklets/<revision>.js`,
|
|
4
|
+
// `src/lib/voice-worklets.ts`), so a host page loads it under `script-src https://alia.onl`
|
|
5
|
+
// instead of a `blob:` URL its CSP would have to allow. Plain JavaScript with no imports: a
|
|
6
|
+
// worklet module runs in the AudioWorkletGlobalScope. Every number it needs arrives in
|
|
7
|
+
// `processorOptions`, so the bytes stay the same while the engine's settings change.
|
|
8
|
+
|
|
9
|
+
class AliaVoiceCapture extends AudioWorkletProcessor {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
super();
|
|
12
|
+
const { streamSampleRate, frameSamples } = options.processorOptions;
|
|
13
|
+
this.ratio = sampleRate / streamSampleRate;
|
|
14
|
+
this.frameSamples = frameSamples;
|
|
15
|
+
this.t = 0;
|
|
16
|
+
this.prev = 0;
|
|
17
|
+
this.frame = new Int16Array(frameSamples);
|
|
18
|
+
this.filled = 0;
|
|
19
|
+
}
|
|
20
|
+
process(inputs) {
|
|
21
|
+
const input = inputs[0]?.[0];
|
|
22
|
+
if (!input || input.length === 0) return true;
|
|
23
|
+
const n = input.length;
|
|
24
|
+
while (this.t < n - 1) {
|
|
25
|
+
const i = Math.floor(this.t);
|
|
26
|
+
const f = this.t - i;
|
|
27
|
+
const a = i < 0 ? this.prev : input[i];
|
|
28
|
+
const b = input[i + 1];
|
|
29
|
+
let s = a + (b - a) * f;
|
|
30
|
+
s = s < -1 ? -1 : s > 1 ? 1 : s;
|
|
31
|
+
this.frame[this.filled++] = s < 0 ? s * 0x8000 : s * 0x7fff;
|
|
32
|
+
if (this.filled === this.frame.length) {
|
|
33
|
+
const out = this.frame;
|
|
34
|
+
this.port.postMessage(out.buffer, [out.buffer]);
|
|
35
|
+
this.frame = new Int16Array(this.frameSamples);
|
|
36
|
+
this.filled = 0;
|
|
37
|
+
}
|
|
38
|
+
this.t += this.ratio;
|
|
39
|
+
}
|
|
40
|
+
this.t -= n;
|
|
41
|
+
this.prev = input[n - 1];
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
registerProcessor('alia-voice-capture', AliaVoiceCapture);
|
|
46
|
+
|
|
47
|
+
class AliaVoicePlayback extends AudioWorkletProcessor {
|
|
48
|
+
constructor(options) {
|
|
49
|
+
super();
|
|
50
|
+
const { streamSampleRate, prebufferMs, prebufferIdleMs } = options.processorOptions;
|
|
51
|
+
this.streamSampleRate = streamSampleRate;
|
|
52
|
+
this.prebufferSamples = (streamSampleRate * prebufferMs) / 1000;
|
|
53
|
+
this.prebufferIdleSeconds = prebufferIdleMs / 1000;
|
|
54
|
+
this.step = streamSampleRate / sampleRate;
|
|
55
|
+
this.queue = [];
|
|
56
|
+
this.queued = 0;
|
|
57
|
+
this.pos = 0;
|
|
58
|
+
this.buffering = true;
|
|
59
|
+
this.lastChunkAt = 0;
|
|
60
|
+
this.item = null;
|
|
61
|
+
this.played = 0;
|
|
62
|
+
this.sinceReport = 0;
|
|
63
|
+
this.sumSquares = 0;
|
|
64
|
+
this.count = 0;
|
|
65
|
+
this.port.onmessage = (event) => {
|
|
66
|
+
const message = event.data;
|
|
67
|
+
if (message.type === 'chunk') {
|
|
68
|
+
this.queue.push({ itemId: message.itemId, samples: message.samples });
|
|
69
|
+
this.queued += message.samples.length;
|
|
70
|
+
this.lastChunkAt = currentTime;
|
|
71
|
+
} else if (message.type === 'flush') {
|
|
72
|
+
const playedMs = this.item === null ? null : this.playedMs();
|
|
73
|
+
this.port.postMessage({ type: 'flushed', itemId: this.item, playedMs });
|
|
74
|
+
this.queue = [];
|
|
75
|
+
this.queued = 0;
|
|
76
|
+
this.pos = 0;
|
|
77
|
+
this.buffering = true;
|
|
78
|
+
this.item = null;
|
|
79
|
+
this.played = 0;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
playedMs() {
|
|
84
|
+
return (this.played / this.streamSampleRate) * 1000;
|
|
85
|
+
}
|
|
86
|
+
report(force) {
|
|
87
|
+
if (!force && this.sinceReport < sampleRate / 20) return;
|
|
88
|
+
const rms = this.count === 0 ? 0 : Math.sqrt(this.sumSquares / this.count);
|
|
89
|
+
this.port.postMessage({ type: 'progress', itemId: this.item, playedMs: this.playedMs(), rms });
|
|
90
|
+
this.sinceReport = 0;
|
|
91
|
+
this.sumSquares = 0;
|
|
92
|
+
this.count = 0;
|
|
93
|
+
}
|
|
94
|
+
process(_inputs, outputs) {
|
|
95
|
+
const out = outputs[0][0];
|
|
96
|
+
if (this.buffering) {
|
|
97
|
+
const ready =
|
|
98
|
+
this.queued >= this.prebufferSamples ||
|
|
99
|
+
(this.queued > 0 && currentTime - this.lastChunkAt > this.prebufferIdleSeconds);
|
|
100
|
+
if (!ready) {
|
|
101
|
+
out.fill(0);
|
|
102
|
+
for (let c = 1; c < outputs[0].length; c++) outputs[0][c].fill(0);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
this.buffering = false;
|
|
106
|
+
}
|
|
107
|
+
for (let k = 0; k < out.length; k++) {
|
|
108
|
+
const head = this.queue[0];
|
|
109
|
+
if (!head) {
|
|
110
|
+
out[k] = 0;
|
|
111
|
+
if (!this.buffering) {
|
|
112
|
+
this.buffering = true;
|
|
113
|
+
this.report(true);
|
|
114
|
+
this.port.postMessage({ type: 'idle' });
|
|
115
|
+
}
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (head.itemId !== this.item) {
|
|
119
|
+
this.item = head.itemId;
|
|
120
|
+
this.played = 0;
|
|
121
|
+
this.port.postMessage({ type: 'started', itemId: head.itemId });
|
|
122
|
+
}
|
|
123
|
+
const i = Math.floor(this.pos);
|
|
124
|
+
const f = this.pos - i;
|
|
125
|
+
const a = head.samples[i];
|
|
126
|
+
const b = i + 1 < head.samples.length ? head.samples[i + 1] : a;
|
|
127
|
+
const s = a + (b - a) * f;
|
|
128
|
+
out[k] = s;
|
|
129
|
+
this.sumSquares += s * s;
|
|
130
|
+
this.count++;
|
|
131
|
+
this.pos += this.step;
|
|
132
|
+
const consumed = Math.floor(this.pos);
|
|
133
|
+
if (consumed > 0) {
|
|
134
|
+
const taken = Math.min(consumed, head.samples.length);
|
|
135
|
+
this.played += taken;
|
|
136
|
+
this.queued -= taken;
|
|
137
|
+
if (consumed >= head.samples.length) {
|
|
138
|
+
this.queue.shift();
|
|
139
|
+
this.pos = 0;
|
|
140
|
+
} else {
|
|
141
|
+
head.samples = head.samples.subarray(consumed);
|
|
142
|
+
this.pos -= consumed;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
for (let c = 1; c < outputs[0].length; c++) outputs[0][c].set(out);
|
|
147
|
+
this.sinceReport += out.length;
|
|
148
|
+
this.report(false);
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
registerProcessor('alia-voice-playback', AliaVoicePlayback);
|