@ottocode/web-sdk 0.1.315 → 0.1.316
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/dist/components/index.js +70 -33
- package/dist/components/index.js.map +4 -4
- package/dist/hooks/index.js +69 -32
- package/dist/hooks/index.js.map +3 -3
- package/dist/hooks/useVoiceInput.d.ts.map +1 -1
- package/dist/index.js +70 -33
- package/dist/index.js.map +4 -4
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVoiceInput.d.ts","sourceRoot":"","sources":["../../src/hooks/useVoiceInput.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useVoiceInput.d.ts","sourceRoot":"","sources":["../../src/hooks/useVoiceInput.ts"],"names":[],"mappings":"AA+BA,UAAU,oBAAoB;IAC7B,2DAA2D;IAC3D,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9D,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,UAAU,mBAAmB;IAC5B,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IAC9B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,IAAI,EAAE,MAAM,IAAI,CAAC;CACjB;AAqED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAC7B,YAAY,EACZ,OAAO,EACP,cAAc,EACd,IAAc,GACd,GAAE,oBAAyB,GAAG,mBAAmB,CAgUjD"}
|
package/dist/index.js
CHANGED
|
@@ -5503,6 +5503,7 @@ ${text.slice(lineStart)}`;
|
|
|
5503
5503
|
import { useCallback as useCallback7, useEffect as useEffect12, useRef as useRef4, useState as useState5 } from "react";
|
|
5504
5504
|
var TARGET_SAMPLE_RATE = 16000;
|
|
5505
5505
|
var PCM_FRAME_BYTES = 3200;
|
|
5506
|
+
var PROCESSOR_BUFFER_SIZE = 4096;
|
|
5506
5507
|
function getAudioContextConstructor() {
|
|
5507
5508
|
if (typeof window === "undefined")
|
|
5508
5509
|
return null;
|
|
@@ -5647,8 +5648,7 @@ function useVoiceInput({
|
|
|
5647
5648
|
}, []);
|
|
5648
5649
|
const handleAudioProcess = useCallback7((event) => {
|
|
5649
5650
|
const audioContext = audioContextRef.current;
|
|
5650
|
-
|
|
5651
|
-
if (!audioContext || !socket || socket.readyState !== WebSocket.OPEN || stoppingRef.current) {
|
|
5651
|
+
if (!audioContext || stoppingRef.current) {
|
|
5652
5652
|
return;
|
|
5653
5653
|
}
|
|
5654
5654
|
const input = event.inputBuffer.getChannelData(0);
|
|
@@ -5680,9 +5680,53 @@ function useVoiceInput({
|
|
|
5680
5680
|
setIsTranscribing(false);
|
|
5681
5681
|
stoppingRef.current = false;
|
|
5682
5682
|
try {
|
|
5683
|
-
const
|
|
5683
|
+
const streamPromise = navigator.mediaDevices.getUserMedia({
|
|
5684
|
+
audio: {
|
|
5685
|
+
echoCancellation: true,
|
|
5686
|
+
noiseSuppression: true,
|
|
5687
|
+
autoGainControl: true
|
|
5688
|
+
}
|
|
5689
|
+
});
|
|
5690
|
+
const statusPromise = apiClient.getDictationStatus().then((status2) => ({ status: status2 }), (error2) => ({ error: error2 }));
|
|
5691
|
+
const stream = await streamPromise;
|
|
5692
|
+
if (stoppingRef.current) {
|
|
5693
|
+
for (const track of stream.getTracks())
|
|
5694
|
+
track.stop();
|
|
5695
|
+
return;
|
|
5696
|
+
}
|
|
5697
|
+
streamRef.current = stream;
|
|
5698
|
+
const AudioContextCtor = getAudioContextConstructor();
|
|
5699
|
+
if (!AudioContextCtor)
|
|
5700
|
+
throw new Error("AudioContext is unavailable");
|
|
5701
|
+
const audioContext = new AudioContextCtor;
|
|
5702
|
+
audioContextRef.current = audioContext;
|
|
5703
|
+
const source = audioContext.createMediaStreamSource(stream);
|
|
5704
|
+
const analyserNode = audioContext.createAnalyser();
|
|
5705
|
+
analyserNode.fftSize = 256;
|
|
5706
|
+
analyserNode.smoothingTimeConstant = 0.55;
|
|
5707
|
+
const processor = audioContext.createScriptProcessor(PROCESSOR_BUFFER_SIZE, 1, 1);
|
|
5708
|
+
processor.onaudioprocess = handleAudioProcess;
|
|
5709
|
+
source.connect(analyserNode);
|
|
5710
|
+
source.connect(processor);
|
|
5711
|
+
processor.connect(audioContext.destination);
|
|
5712
|
+
sourceRef.current = source;
|
|
5713
|
+
processorRef.current = processor;
|
|
5714
|
+
if (audioContext.state === "suspended") {
|
|
5715
|
+
await audioContext.resume();
|
|
5716
|
+
}
|
|
5717
|
+
if (stoppingRef.current)
|
|
5718
|
+
return;
|
|
5719
|
+
setAnalyser(analyserNode);
|
|
5720
|
+
setIsListening(true);
|
|
5721
|
+
const statusResult = await statusPromise;
|
|
5722
|
+
if ("error" in statusResult)
|
|
5723
|
+
throw statusResult.error;
|
|
5724
|
+
const { status } = statusResult;
|
|
5725
|
+
if (stoppingRef.current)
|
|
5726
|
+
return;
|
|
5684
5727
|
const model = status.models.find((item) => item.id === status.defaultModel);
|
|
5685
5728
|
if (!model?.installed) {
|
|
5729
|
+
cleanup();
|
|
5686
5730
|
handleMissingModel();
|
|
5687
5731
|
return;
|
|
5688
5732
|
}
|
|
@@ -5690,7 +5734,10 @@ function useVoiceInput({
|
|
|
5690
5734
|
model: status.defaultModel,
|
|
5691
5735
|
language: toLanguageCode(lang)
|
|
5692
5736
|
});
|
|
5737
|
+
if (stoppingRef.current)
|
|
5738
|
+
return;
|
|
5693
5739
|
if (!session.modelInstalled) {
|
|
5740
|
+
cleanup();
|
|
5694
5741
|
handleMissingModel();
|
|
5695
5742
|
return;
|
|
5696
5743
|
}
|
|
@@ -5703,7 +5750,6 @@ function useVoiceInput({
|
|
|
5703
5750
|
reject(new Error("Timed out connecting to local dictation"));
|
|
5704
5751
|
}, 5000);
|
|
5705
5752
|
socket.onopen = () => {
|
|
5706
|
-
window.clearTimeout(timeout);
|
|
5707
5753
|
socket.send(JSON.stringify({
|
|
5708
5754
|
type: "start",
|
|
5709
5755
|
model: session.model,
|
|
@@ -5715,7 +5761,23 @@ function useVoiceInput({
|
|
|
5715
5761
|
},
|
|
5716
5762
|
partialResults: false
|
|
5717
5763
|
}));
|
|
5718
|
-
|
|
5764
|
+
};
|
|
5765
|
+
socket.onmessage = (event) => {
|
|
5766
|
+
if (typeof event.data !== "string")
|
|
5767
|
+
return;
|
|
5768
|
+
const payload = parseServerEvent(event.data);
|
|
5769
|
+
if (!payload)
|
|
5770
|
+
return;
|
|
5771
|
+
if (payload.type === "ready") {
|
|
5772
|
+
window.clearTimeout(timeout);
|
|
5773
|
+
flushFrameBuffer(false);
|
|
5774
|
+
resolve();
|
|
5775
|
+
return;
|
|
5776
|
+
}
|
|
5777
|
+
if (payload.type === "error") {
|
|
5778
|
+
window.clearTimeout(timeout);
|
|
5779
|
+
reject(new Error(payload.message));
|
|
5780
|
+
}
|
|
5719
5781
|
};
|
|
5720
5782
|
socket.onerror = () => {
|
|
5721
5783
|
window.clearTimeout(timeout);
|
|
@@ -5743,32 +5805,6 @@ function useVoiceInput({
|
|
|
5743
5805
|
setIsListening(false);
|
|
5744
5806
|
setIsTranscribing(false);
|
|
5745
5807
|
};
|
|
5746
|
-
const stream = await navigator.mediaDevices.getUserMedia({
|
|
5747
|
-
audio: {
|
|
5748
|
-
echoCancellation: true,
|
|
5749
|
-
noiseSuppression: true,
|
|
5750
|
-
autoGainControl: true
|
|
5751
|
-
}
|
|
5752
|
-
});
|
|
5753
|
-
streamRef.current = stream;
|
|
5754
|
-
const AudioContextCtor = getAudioContextConstructor();
|
|
5755
|
-
if (!AudioContextCtor)
|
|
5756
|
-
throw new Error("AudioContext is unavailable");
|
|
5757
|
-
const audioContext = new AudioContextCtor;
|
|
5758
|
-
const source = audioContext.createMediaStreamSource(stream);
|
|
5759
|
-
const analyserNode = audioContext.createAnalyser();
|
|
5760
|
-
analyserNode.fftSize = 256;
|
|
5761
|
-
analyserNode.smoothingTimeConstant = 0.55;
|
|
5762
|
-
const processor = audioContext.createScriptProcessor(4096, 1, 1);
|
|
5763
|
-
processor.onaudioprocess = handleAudioProcess;
|
|
5764
|
-
source.connect(analyserNode);
|
|
5765
|
-
source.connect(processor);
|
|
5766
|
-
processor.connect(audioContext.destination);
|
|
5767
|
-
audioContextRef.current = audioContext;
|
|
5768
|
-
sourceRef.current = source;
|
|
5769
|
-
processorRef.current = processor;
|
|
5770
|
-
setAnalyser(analyserNode);
|
|
5771
|
-
setIsListening(true);
|
|
5772
5808
|
} catch (err) {
|
|
5773
5809
|
const name = err instanceof Error ? err.name : "";
|
|
5774
5810
|
const msg = name === "NotAllowedError" ? "Microphone permission denied" : err instanceof Error ? err.message : "Could not start voice input";
|
|
@@ -5780,6 +5816,7 @@ function useVoiceInput({
|
|
|
5780
5816
|
emitError,
|
|
5781
5817
|
handleAudioProcess,
|
|
5782
5818
|
handleMissingModel,
|
|
5819
|
+
flushFrameBuffer,
|
|
5783
5820
|
isSupported,
|
|
5784
5821
|
lang
|
|
5785
5822
|
]);
|
|
@@ -42498,7 +42535,7 @@ var ProviderSetupStep = memo75(function ProviderSetupStep2({
|
|
|
42498
42535
|
className: "flex items-center gap-2 p-3 bg-card border border-ring rounded-xl overflow-hidden",
|
|
42499
42536
|
children: [
|
|
42500
42537
|
/* @__PURE__ */ jsx154("div", {
|
|
42501
|
-
className: "shrink-0",
|
|
42538
|
+
className: "shrink-0 flex items-center",
|
|
42502
42539
|
children: /* @__PURE__ */ jsx154(ProviderLogo, {
|
|
42503
42540
|
provider: id,
|
|
42504
42541
|
size: 18
|
|
@@ -46640,4 +46677,4 @@ export {
|
|
|
46640
46677
|
API_BASE_URL
|
|
46641
46678
|
};
|
|
46642
46679
|
|
|
46643
|
-
//# debugId=
|
|
46680
|
+
//# debugId=996FED05264406DC64756E2164756E21
|