@rapidaai/react 1.1.50 → 1.1.51
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/{chunk-2EMDIAFM.mjs → chunk-A2PCWS4P.mjs} +52 -19
- package/dist/{chunk-2EMDIAFM.mjs.map → chunk-A2PCWS4P.mjs.map} +1 -1
- package/dist/components/device-selector.js +51 -18
- package/dist/components/device-selector.js.map +1 -1
- package/dist/components/device-selector.mjs +1 -1
- package/dist/index.js +51 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +11 -2
package/dist/index.js
CHANGED
|
@@ -60185,6 +60185,9 @@ var import_moment = __toESM(require("moment"));
|
|
|
60185
60185
|
function isSafari() {
|
|
60186
60186
|
return getBrowser()?.name === "Safari";
|
|
60187
60187
|
}
|
|
60188
|
+
function isChrome() {
|
|
60189
|
+
return getBrowser()?.name === "Chrome";
|
|
60190
|
+
}
|
|
60188
60191
|
function toDate(timestamp) {
|
|
60189
60192
|
const seconds = timestamp.getSeconds();
|
|
60190
60193
|
const nanos = timestamp.getNanos();
|
|
@@ -61894,6 +61897,24 @@ registerProcessor("raw-audio-processor", RawAudioProcessor);
|
|
|
61894
61897
|
|
|
61895
61898
|
// src/audio/input.ts
|
|
61896
61899
|
var LIBSAMPLERATE_JS = "https://cdn.jsdelivr.net/npm/@alexanderolsen/libsamplerate-js@2.1.2/dist/libsamplerate.worklet.js";
|
|
61900
|
+
function getAudioConstraints(sampleRate) {
|
|
61901
|
+
if (isChrome()) {
|
|
61902
|
+
return {
|
|
61903
|
+
sampleRate: { ideal: sampleRate },
|
|
61904
|
+
echoCancellation: true,
|
|
61905
|
+
noiseSuppression: true,
|
|
61906
|
+
autoGainControl: true,
|
|
61907
|
+
// Chrome-specific: helps with consistent audio quality
|
|
61908
|
+
channelCount: { ideal: 1 }
|
|
61909
|
+
};
|
|
61910
|
+
}
|
|
61911
|
+
return {
|
|
61912
|
+
sampleRate: { ideal: sampleRate },
|
|
61913
|
+
echoCancellation: { ideal: true },
|
|
61914
|
+
noiseSuppression: { ideal: true },
|
|
61915
|
+
autoGainControl: { ideal: true }
|
|
61916
|
+
};
|
|
61917
|
+
}
|
|
61897
61918
|
var Input = class _Input {
|
|
61898
61919
|
constructor(context, analyser, worklet, inputStream) {
|
|
61899
61920
|
this.context = context;
|
|
@@ -61901,18 +61922,10 @@ var Input = class _Input {
|
|
|
61901
61922
|
this.worklet = worklet;
|
|
61902
61923
|
this.inputStream = inputStream;
|
|
61903
61924
|
}
|
|
61904
|
-
static async create({
|
|
61905
|
-
sampleRate,
|
|
61906
|
-
format
|
|
61907
|
-
}) {
|
|
61925
|
+
static async create({ sampleRate, format }, existingStream) {
|
|
61908
61926
|
let context = null;
|
|
61909
61927
|
let inputStream = null;
|
|
61910
61928
|
try {
|
|
61911
|
-
const options = {
|
|
61912
|
-
sampleRate: { ideal: sampleRate },
|
|
61913
|
-
echoCancellation: { ideal: true },
|
|
61914
|
-
noiseSuppression: { ideal: true }
|
|
61915
|
-
};
|
|
61916
61929
|
const supportsSampleRateConstraint = navigator.mediaDevices.getSupportedConstraints().sampleRate;
|
|
61917
61930
|
context = new window.AudioContext(
|
|
61918
61931
|
supportsSampleRateConstraint ? { sampleRate } : {}
|
|
@@ -61922,9 +61935,14 @@ var Input = class _Input {
|
|
|
61922
61935
|
await context.audioWorklet.addModule(LIBSAMPLERATE_JS);
|
|
61923
61936
|
}
|
|
61924
61937
|
await loadRawAudioProcessor(context.audioWorklet);
|
|
61925
|
-
|
|
61926
|
-
|
|
61927
|
-
}
|
|
61938
|
+
if (existingStream) {
|
|
61939
|
+
inputStream = existingStream;
|
|
61940
|
+
} else {
|
|
61941
|
+
const options = getAudioConstraints(sampleRate);
|
|
61942
|
+
inputStream = await navigator.mediaDevices.getUserMedia({
|
|
61943
|
+
audio: options
|
|
61944
|
+
});
|
|
61945
|
+
}
|
|
61928
61946
|
const source = context.createMediaStreamSource(inputStream);
|
|
61929
61947
|
const worklet = new AudioWorkletNode(context, "raw-audio-processor");
|
|
61930
61948
|
worklet.port.postMessage({ type: "setFormat", format, sampleRate });
|
|
@@ -62177,13 +62195,14 @@ var VoiceAgent = class extends Agent {
|
|
|
62177
62195
|
connectDevice = async () => {
|
|
62178
62196
|
try {
|
|
62179
62197
|
this.preliminaryInputStream = await this.waitForUserMediaPermission();
|
|
62180
|
-
|
|
62181
|
-
|
|
62182
|
-
|
|
62183
|
-
|
|
62198
|
+
this.output = await Output.create(this.agentConfig.outputOptions.playerOption);
|
|
62199
|
+
this.input = await Input.create(
|
|
62200
|
+
this.agentConfig.inputOptions.recorderOption,
|
|
62201
|
+
this.preliminaryInputStream
|
|
62202
|
+
// Reuse the same MediaStream
|
|
62203
|
+
);
|
|
62184
62204
|
this.input.worklet.port.onmessage = this.onInputWorkletMessage;
|
|
62185
62205
|
this.output.worklet.port.onmessage = this.onOutputWorkletMessage;
|
|
62186
|
-
this.preliminaryInputStream?.getTracks().forEach((track) => track.stop());
|
|
62187
62206
|
this.preliminaryInputStream = null;
|
|
62188
62207
|
} catch (error) {
|
|
62189
62208
|
await this.disconnectAudio();
|
|
@@ -62193,7 +62212,20 @@ var VoiceAgent = class extends Agent {
|
|
|
62193
62212
|
// Helper method to handle media permissions:
|
|
62194
62213
|
waitForUserMediaPermission = async () => {
|
|
62195
62214
|
try {
|
|
62196
|
-
|
|
62215
|
+
const sampleRate = this.agentConfig.inputOptions.recorderOption.sampleRate;
|
|
62216
|
+
const options = isChrome() ? {
|
|
62217
|
+
sampleRate: { ideal: sampleRate },
|
|
62218
|
+
echoCancellation: true,
|
|
62219
|
+
noiseSuppression: true,
|
|
62220
|
+
autoGainControl: true,
|
|
62221
|
+
channelCount: { ideal: 1 }
|
|
62222
|
+
} : {
|
|
62223
|
+
sampleRate: { ideal: sampleRate },
|
|
62224
|
+
echoCancellation: { ideal: true },
|
|
62225
|
+
noiseSuppression: { ideal: true },
|
|
62226
|
+
autoGainControl: { ideal: true }
|
|
62227
|
+
};
|
|
62228
|
+
return await navigator.mediaDevices.getUserMedia({ audio: options });
|
|
62197
62229
|
} catch (error) {
|
|
62198
62230
|
console.error(
|
|
62199
62231
|
"Permission denied or error while requesting microphone access:",
|
|
@@ -62465,6 +62497,7 @@ var VoiceAgent = class extends Agent {
|
|
|
62465
62497
|
const audioData = content.getContent_asU8();
|
|
62466
62498
|
this.addAudioChunk(new Uint8Array(audioData).buffer);
|
|
62467
62499
|
}
|
|
62500
|
+
break;
|
|
62468
62501
|
case import_common_pb8.AssistantConversationAssistantMessage.MessageCase.TEXT:
|
|
62469
62502
|
const systemTranscript = systemContent.getText()?.getContent();
|
|
62470
62503
|
if (systemTranscript) {
|