Compare commits

...

1 Commits

Author SHA1 Message Date
James Hush
81d066074c Fix lint 2025-04-14 11:48:55 +08:00
2 changed files with 34 additions and 12 deletions

View File

@@ -1,13 +1,13 @@
import { useRef, useCallback } from 'react'; import { useRef, useCallback } from "react";
import { import {
Participant, Participant,
RTVIEvent, RTVIEvent,
TransportState, TransportState,
TranscriptData, TranscriptData,
BotLLMTextData, BotLLMTextData,
} from '@pipecat-ai/client-js'; } from "@pipecat-ai/client-js";
import { useRTVIClient, useRTVIClientEvent } from '@pipecat-ai/client-react'; import { useRTVIClient, useRTVIClientEvent } from "@pipecat-ai/client-react";
import './DebugDisplay.css'; import "./DebugDisplay.css";
export function DebugDisplay() { export function DebugDisplay() {
const debugLogRef = useRef<HTMLDivElement>(null); const debugLogRef = useRef<HTMLDivElement>(null);
@@ -16,14 +16,14 @@ export function DebugDisplay() {
const log = useCallback((message: string) => { const log = useCallback((message: string) => {
if (!debugLogRef.current) return; if (!debugLogRef.current) return;
const entry = document.createElement('div'); const entry = document.createElement("div");
entry.textContent = `${new Date().toISOString()} - ${message}`; entry.textContent = `${new Date().toISOString()} - ${message}`;
// Add styling based on message type // Add styling based on message type
if (message.startsWith('User: ')) { if (message.startsWith("User: ")) {
entry.style.color = '#2196F3'; // blue for user entry.style.color = "#2196F3"; // blue for user
} else if (message.startsWith('Bot: ')) { } else if (message.startsWith("Bot: ")) {
entry.style.color = '#4CAF50'; // green for bot entry.style.color = "#4CAF50"; // green for bot
} }
debugLogRef.current.appendChild(entry); debugLogRef.current.appendChild(entry);
@@ -68,7 +68,7 @@ export function DebugDisplay() {
useCallback( useCallback(
(track: MediaStreamTrack, participant?: Participant) => { (track: MediaStreamTrack, participant?: Participant) => {
log( log(
`Track started: ${track.kind} from ${participant?.name || 'unknown'}` `Track started: ${track.kind} from ${participant?.name || "unknown"}`
); );
}, },
[log] [log]
@@ -80,7 +80,7 @@ export function DebugDisplay() {
useCallback( useCallback(
(track: MediaStreamTrack, participant?: Participant) => { (track: MediaStreamTrack, participant?: Participant) => {
log( log(
`Track stopped: ${track.kind} from ${participant?.name || 'unknown'}` `Track stopped: ${track.kind} from ${participant?.name || "unknown"}`
); );
}, },
[log] [log]
@@ -135,6 +135,16 @@ export function DebugDisplay() {
) )
); );
useRTVIClientEvent(
RTVIEvent.ServerMessage,
useCallback(
(data: unknown) => {
log(`Server Message: ${data}`);
},
[log]
)
);
return ( return (
<div className="debug-panel"> <div className="debug-panel">
<h3>Debug Info</h3> <h3>Debug Info</h3>

View File

@@ -40,7 +40,12 @@ from pipecat.pipeline.runner import PipelineRunner
from pipecat.pipeline.task import PipelineParams, PipelineTask from pipecat.pipeline.task import PipelineParams, PipelineTask
from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
from pipecat.processors.frameworks.rtvi import RTVIConfig, RTVIObserver, RTVIProcessor from pipecat.processors.frameworks.rtvi import (
RTVIConfig,
RTVIObserver,
RTVIProcessor,
RTVIServerMessageFrame,
)
from pipecat.services.elevenlabs.tts import ElevenLabsTTSService from pipecat.services.elevenlabs.tts import ElevenLabsTTSService
from pipecat.services.openai.llm import OpenAILLMService from pipecat.services.openai.llm import OpenAILLMService
from pipecat.transports.services.daily import DailyParams, DailyTransport from pipecat.transports.services.daily import DailyParams, DailyTransport
@@ -90,15 +95,22 @@ class TalkingAnimation(FrameProcessor):
""" """
await super().process_frame(frame, direction) await super().process_frame(frame, direction)
# Send a custom message to client
animation_frame = RTVIServerMessageFrame(
data={"type": "animation", "payload": {"is_talking": self._is_talking}}
)
# Switch to talking animation when bot starts speaking # Switch to talking animation when bot starts speaking
if isinstance(frame, BotStartedSpeakingFrame): if isinstance(frame, BotStartedSpeakingFrame):
if not self._is_talking: if not self._is_talking:
await self.push_frame(talking_frame) await self.push_frame(talking_frame)
self._is_talking = True self._is_talking = True
await self.push_frame(animation_frame)
# Return to static frame when bot stops speaking # Return to static frame when bot stops speaking
elif isinstance(frame, BotStoppedSpeakingFrame): elif isinstance(frame, BotStoppedSpeakingFrame):
await self.push_frame(quiet_frame) await self.push_frame(quiet_frame)
self._is_talking = False self._is_talking = False
await self.push_frame(animation_frame)
await self.push_frame(frame, direction) await self.push_frame(frame, direction)