voice-router-dev 0.2.0 → 0.2.2
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/index.js +16 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2896,6 +2896,15 @@ var AssemblyAIAdapter = class extends BaseAdapter {
|
|
|
2896
2896
|
});
|
|
2897
2897
|
let sessionStatus = "connecting";
|
|
2898
2898
|
const sessionId = `assemblyai-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
2899
|
+
let audioBuffer = Buffer.alloc(0);
|
|
2900
|
+
const MIN_CHUNK_SIZE = 1600;
|
|
2901
|
+
const MAX_CHUNK_SIZE = 32e3;
|
|
2902
|
+
const flushAudioBuffer = () => {
|
|
2903
|
+
if (audioBuffer.length > 0 && ws.readyState === import_ws2.default.OPEN) {
|
|
2904
|
+
ws.send(audioBuffer);
|
|
2905
|
+
audioBuffer = Buffer.alloc(0);
|
|
2906
|
+
}
|
|
2907
|
+
};
|
|
2899
2908
|
ws.on("open", () => {
|
|
2900
2909
|
sessionStatus = "open";
|
|
2901
2910
|
callbacks?.onOpen?.();
|
|
@@ -2984,13 +2993,13 @@ var AssemblyAIAdapter = class extends BaseAdapter {
|
|
|
2984
2993
|
if (ws.readyState !== import_ws2.default.OPEN) {
|
|
2985
2994
|
throw new Error("WebSocket is not open");
|
|
2986
2995
|
}
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
);
|
|
2996
|
+
audioBuffer = Buffer.concat([audioBuffer, chunk.data]);
|
|
2997
|
+
if (audioBuffer.length >= MIN_CHUNK_SIZE || audioBuffer.length >= MAX_CHUNK_SIZE) {
|
|
2998
|
+
ws.send(audioBuffer);
|
|
2999
|
+
audioBuffer = Buffer.alloc(0);
|
|
3000
|
+
}
|
|
2993
3001
|
if (chunk.isLast) {
|
|
3002
|
+
flushAudioBuffer();
|
|
2994
3003
|
ws.send(
|
|
2995
3004
|
JSON.stringify({
|
|
2996
3005
|
terminate_session: true
|
|
@@ -3003,6 +3012,7 @@ var AssemblyAIAdapter = class extends BaseAdapter {
|
|
|
3003
3012
|
return;
|
|
3004
3013
|
}
|
|
3005
3014
|
sessionStatus = "closing";
|
|
3015
|
+
flushAudioBuffer();
|
|
3006
3016
|
if (ws.readyState === import_ws2.default.OPEN) {
|
|
3007
3017
|
ws.send(
|
|
3008
3018
|
JSON.stringify({
|