voice-router-dev 0.2.1 → 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 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -1
- 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,8 +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
|
-
|
|
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
|
+
}
|
|
2988
3001
|
if (chunk.isLast) {
|
|
3002
|
+
flushAudioBuffer();
|
|
2989
3003
|
ws.send(
|
|
2990
3004
|
JSON.stringify({
|
|
2991
3005
|
terminate_session: true
|
|
@@ -2998,6 +3012,7 @@ var AssemblyAIAdapter = class extends BaseAdapter {
|
|
|
2998
3012
|
return;
|
|
2999
3013
|
}
|
|
3000
3014
|
sessionStatus = "closing";
|
|
3015
|
+
flushAudioBuffer();
|
|
3001
3016
|
if (ws.readyState === import_ws2.default.OPEN) {
|
|
3002
3017
|
ws.send(
|
|
3003
3018
|
JSON.stringify({
|