Bug fixed

This commit is contained in:
Xin Wang 2025-12-17 23:13:42 +08:00
parent 853e1558b1
commit da11561f47
2 changed files with 52 additions and 18 deletions

View File

@ -1018,6 +1018,16 @@ async def entrypoint(ctx: JobContext, avatar_dispatcher_url: str = None, vision_
initial_instructions = participant.attributes.get("instructions")
logger.info(f"User selected instructions: {initial_instructions}")
# Read talking_mode from frontend state
initial_talking_mode = DEFAULT_TALKING_MODE
if participant.attributes.get("talking_mode"):
frontend_talking_mode = participant.attributes.get("talking_mode")
if frontend_talking_mode in ["push_to_talk", "realtime"]:
initial_talking_mode = frontend_talking_mode
logger.info(f"Initializing talking_mode from frontend: {initial_talking_mode}")
else:
logger.warning(f"Invalid talking_mode from frontend: {frontend_talking_mode}, using default: {initial_talking_mode}")
# Replace the datetime and weekday placeholders to avoid KeyError from other braces in the prompt
initial_instructions = initial_instructions.replace("{datetime}", current_time)
initial_instructions = initial_instructions.replace("{weekday}", current_weekday)
@ -1128,7 +1138,7 @@ async def entrypoint(ctx: JobContext, avatar_dispatcher_url: str = None, vision_
)
# disable input audio at the start
_talking_mode = DEFAULT_TALKING_MODE
_talking_mode = initial_talking_mode
if _talking_mode == "push_to_talk":
session.input.set_audio_enabled(False)
else:

View File

@ -78,6 +78,32 @@ export function PhoneSimulator({
}
}, [config.settings.attributes]);
// Set talking_mode attribute when connected or when mode changes
useEffect(() => {
if (roomState === ConnectionState.Connected && localParticipant) {
const talkingMode = isPushToTalkMode ? "push_to_talk" : "realtime";
try {
// Get current attributes to preserve them
const currentAttributes: Record<string, string> = {};
// Note: LiveKit's setAttributes replaces all attributes, so we need to merge
// with existing ones from config if any
const configAttributes = config.settings.attributes || [];
configAttributes.forEach(attr => {
if (attr.key && attr.value) {
currentAttributes[attr.key] = attr.value;
}
});
// Set talking_mode along with other attributes
localParticipant.setAttributes({
...currentAttributes,
talking_mode: talkingMode,
});
} catch (error) {
console.error("Failed to set talking_mode attribute:", error);
}
}
}, [roomState, localParticipant, isPushToTalkMode, config.settings.attributes]);
const [currentTime, setCurrentTime] = useState("");
const [visualizerPosition, setVisualizerPosition] = useState({
@ -1255,7 +1281,7 @@ export function PhoneSimulator({
)}
{/* Realtime Mode Layout */}
{!isPushToTalkMode && (
{!isPushToTalkMode && phoneMode !== "hand_off" && (
<>
{/* Important Message Mode - Centered End Call Button */}
{phoneMode === "important_message" ? (
@ -1270,22 +1296,20 @@ export function PhoneSimulator({
) : (
<div className="w-full flex items-center justify-center gap-4">
{/* Mic Toggle */}
{phoneMode !== "hand_off" && (
<button
className={`p-4 rounded-full backdrop-blur-md transition-colors ${
!isMicEnabled
? "bg-white text-black"
: "bg-gray-600/50 text-white hover:bg-gray-600/70"
}`}
onClick={handleMicToggle}
>
{isMicEnabled ? (
<MicIcon className="w-6 h-6" />
) : (
<MicOffIcon className="w-6 h-6" />
)}
</button>
)}
<button
className={`p-4 rounded-full backdrop-blur-md transition-colors ${
!isMicEnabled
? "bg-white text-black"
: "bg-gray-600/50 text-white hover:bg-gray-600/70"
}`}
onClick={handleMicToggle}
>
{isMicEnabled ? (
<MicIcon className="w-6 h-6" />
) : (
<MicOffIcon className="w-6 h-6" />
)}
</button>
{/* End Call Button */}
<button