@drawdream/livespeech 0.1.10 → 0.1.14
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/README.md +196 -377
- package/dist/index.d.mts +139 -9
- package/dist/index.d.ts +139 -9
- package/dist/index.js +65 -1
- package/dist/index.mjs +65 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -689,14 +689,22 @@ var LiveSpeechClient = class {
|
|
|
689
689
|
};
|
|
690
690
|
this.on("sessionStarted", onSessionStarted);
|
|
691
691
|
this.on("error", onError);
|
|
692
|
+
const sessionDuration = config?.sessionDuration;
|
|
693
|
+
const hasSessionDuration = typeof sessionDuration?.maxSeconds === "number";
|
|
692
694
|
this.connection.send({
|
|
693
695
|
action: "startSession",
|
|
694
696
|
...config?.prePrompt && { prePrompt: config.prePrompt },
|
|
695
697
|
...config?.language && { language: config.language },
|
|
698
|
+
...config?.outputLanguage && { outputLanguage: config.outputLanguage },
|
|
696
699
|
pipelineMode: config?.pipelineMode ?? "live",
|
|
697
700
|
...config?.aiSpeaksFirst && { aiSpeaksFirst: config.aiSpeaksFirst },
|
|
698
701
|
allowHarmCategory: config?.allowHarmCategory ?? false,
|
|
699
|
-
...config?.tools && config.tools.length > 0 && { tools: config.tools }
|
|
702
|
+
...config?.tools && config.tools.length > 0 && { tools: config.tools },
|
|
703
|
+
...hasSessionDuration && {
|
|
704
|
+
sessionMaxDurationSeconds: sessionDuration.maxSeconds,
|
|
705
|
+
enableSessionWarning: sessionDuration.enableWarning ?? false,
|
|
706
|
+
enableSessionGoodbye: sessionDuration.enableGoodbye ?? false
|
|
707
|
+
}
|
|
700
708
|
});
|
|
701
709
|
});
|
|
702
710
|
}
|
|
@@ -838,6 +846,35 @@ var LiveSpeechClient = class {
|
|
|
838
846
|
payload: { id, response }
|
|
839
847
|
});
|
|
840
848
|
}
|
|
849
|
+
/**
|
|
850
|
+
* Explicitly interrupt the current AI response
|
|
851
|
+
*
|
|
852
|
+
* Use this method for:
|
|
853
|
+
* - UI "Stop" button functionality
|
|
854
|
+
* - Programmatic control to stop AI mid-response
|
|
855
|
+
*
|
|
856
|
+
* Note: In most cases, simply speaking will trigger automatic
|
|
857
|
+
* interruption via Gemini's voice activity detection (VAD).
|
|
858
|
+
* This method is for explicit programmatic control.
|
|
859
|
+
*
|
|
860
|
+
* @example
|
|
861
|
+
* // User clicks "Stop" button
|
|
862
|
+
* client.interrupt();
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* // Stop AI after a certain time
|
|
866
|
+
* setTimeout(() => client.interrupt(), 10000);
|
|
867
|
+
*/
|
|
868
|
+
interrupt() {
|
|
869
|
+
if (!this.isConnected) {
|
|
870
|
+
throw new Error("Not connected");
|
|
871
|
+
}
|
|
872
|
+
if (!this.isStreaming) {
|
|
873
|
+
throw new Error("No active Live session. Call audioStart() first.");
|
|
874
|
+
}
|
|
875
|
+
this.logger.info("Sending explicit interrupt");
|
|
876
|
+
this.connection.send({ action: "interrupt" });
|
|
877
|
+
}
|
|
841
878
|
/**
|
|
842
879
|
* Update the user ID for the current connection (guest-to-user migration)
|
|
843
880
|
*
|
|
@@ -1007,6 +1044,24 @@ var LiveSpeechClient = class {
|
|
|
1007
1044
|
timestamp: message.timestamp
|
|
1008
1045
|
});
|
|
1009
1046
|
break;
|
|
1047
|
+
case "session_warning": {
|
|
1048
|
+
const warningEvent = {
|
|
1049
|
+
type: "sessionWarning",
|
|
1050
|
+
remainingSeconds: message.remainingSeconds ?? 0,
|
|
1051
|
+
timestamp: message.timestamp
|
|
1052
|
+
};
|
|
1053
|
+
this.emit("sessionWarning", warningEvent);
|
|
1054
|
+
break;
|
|
1055
|
+
}
|
|
1056
|
+
case "session_goodbye": {
|
|
1057
|
+
const goodbyeEvent = {
|
|
1058
|
+
type: "sessionGoodbye",
|
|
1059
|
+
remainingSeconds: message.remainingSeconds ?? 0,
|
|
1060
|
+
timestamp: message.timestamp
|
|
1061
|
+
};
|
|
1062
|
+
this.emit("sessionGoodbye", goodbyeEvent);
|
|
1063
|
+
break;
|
|
1064
|
+
}
|
|
1010
1065
|
case "ready": {
|
|
1011
1066
|
const readyEvent = {
|
|
1012
1067
|
type: "ready",
|
|
@@ -1080,6 +1135,15 @@ var LiveSpeechClient = class {
|
|
|
1080
1135
|
this.emit("userIdUpdated", userIdUpdatedEvent);
|
|
1081
1136
|
break;
|
|
1082
1137
|
}
|
|
1138
|
+
case "interrupted": {
|
|
1139
|
+
const interruptedEvent = {
|
|
1140
|
+
type: "interrupted",
|
|
1141
|
+
timestamp: message.timestamp
|
|
1142
|
+
};
|
|
1143
|
+
this.logger.info("AI response interrupted (barge-in)");
|
|
1144
|
+
this.emit("interrupted", interruptedEvent);
|
|
1145
|
+
break;
|
|
1146
|
+
}
|
|
1083
1147
|
case "error":
|
|
1084
1148
|
this.handleError(message.code, message.message);
|
|
1085
1149
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drawdream/livespeech",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Real-time speech-to-speech AI conversation SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/node": "^20.10.0",
|
|
58
58
|
"@types/ws": "^8.5.10",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
60
|
-
"@typescript-eslint/parser": "^
|
|
61
|
-
"eslint": "^8.
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
60
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
61
|
+
"eslint": "^8.56.0",
|
|
62
62
|
"tsup": "^8.0.1",
|
|
63
63
|
"typescript": "^5.3.0",
|
|
64
|
-
"vitest": "^
|
|
64
|
+
"vitest": "^4.0.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"typescript": ">=5.0.0"
|