diff --git a/src/routes/visualizations-chat/+page.svelte b/src/routes/visualizations-chat/+page.svelte index e75bb66..06aa638 100644 --- a/src/routes/visualizations-chat/+page.svelte +++ b/src/routes/visualizations-chat/+page.svelte @@ -8,6 +8,7 @@ import InnerGlowVisualizer from '$lib/realtime/visualizations/InnerGlowVisualizer.svelte'; import CircleCirclesVisualizer from '$lib/realtime/visualizations/CircleCirclesVisualizer.svelte'; import BarVisualizer from '$lib/realtime/visualizations/BarVisualizer.svelte'; + import type { ItemType } from '@openai/realtime-api-beta/dist/lib/client'; export let wavRecorder: WavRecorder; let wavStreamPlayer: WavStreamPlayer; @@ -21,10 +22,40 @@ let current = 0; $: shownVisualizer = visualizations[current]; + + let items: ItemType[] = []; + + let lastAssistantText = ''; + let lastUserText = ''; + + $: if (items && items.length > 0) { + // last item with role "assistant" + + const lastAssistant = items + .slice() + .reverse() + .find((item) => item.role === 'assistant'); + + if ( + lastAssistant?.formatted.transcript && + lastAssistant.formatted.transcript !== lastAssistantText + ) { + lastAssistantText = lastAssistant.formatted.transcript; + } + + const lastUser = items + .slice() + .reverse() + .find((item) => item.role === 'user'); + + if (lastUser?.formatted.transcript && lastUser.formatted.transcript !== lastUserText) { + lastUserText = lastUser.formatted.transcript; + } + } {#if apiKey} - + {/if} {#if shownVisualizer === 'circle-bars'} -
-
- +
+
+
+
-
- +
+
+
{:else if shownVisualizer === 'bars'} -
-
- -
+
+
+
+ +
+
{:else if shownVisualizer === 'circle-circles'} -
-
- +
+
+
-
- +
+
+
+
{:else if shownVisualizer === 'deformed-circle'} -
+
- +
+
+
- +
{:else if shownVisualizer === 'innerglow'} @@ -103,6 +151,22 @@
{/if} +
+
+ {lastAssistantText} +
+
+
+ {lastUserText} +
+
+ { startConversation(); diff --git a/src/routes/visualizations-input/+page.svelte b/src/routes/visualizations-input/+page.svelte index d51ac22..add9db3 100644 --- a/src/routes/visualizations-input/+page.svelte +++ b/src/routes/visualizations-input/+page.svelte @@ -21,8 +21,9 @@ recording = true; }} - class="rounded-full px-5 py-3 text-base font-semibold focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-amber-500 text-amber-500 bg-amber-500/10 border border-amber-500/20 hover:bg-amber-500/20 {recording ? 'cursor-not-allowed opacity-50' : ''}" - >start microphonestart microphone
@@ -39,7 +40,7 @@
- +