|
8 | 8 | import InnerGlowVisualizer from '$lib/realtime/visualizations/InnerGlowVisualizer.svelte';
|
9 | 9 | import CircleCirclesVisualizer from '$lib/realtime/visualizations/CircleCirclesVisualizer.svelte';
|
10 | 10 | import BarVisualizer from '$lib/realtime/visualizations/BarVisualizer.svelte';
|
| 11 | + import type { ItemType } from '@openai/realtime-api-beta/dist/lib/client'; |
11 | 12 |
|
12 | 13 | export let wavRecorder: WavRecorder;
|
13 | 14 | let wavStreamPlayer: WavStreamPlayer;
|
|
21 | 22 | let current = 0;
|
22 | 23 |
|
23 | 24 | $: shownVisualizer = visualizations[current];
|
| 25 | +
|
| 26 | + let items: ItemType[] = []; |
| 27 | +
|
| 28 | + let lastAssistantText = ''; |
| 29 | + let lastUserText = ''; |
| 30 | +
|
| 31 | + $: if (items && items.length > 0) { |
| 32 | + // last item with role "assistant" |
| 33 | +
|
| 34 | + const lastAssistant = items |
| 35 | + .slice() |
| 36 | + .reverse() |
| 37 | + .find((item) => item.role === 'assistant'); |
| 38 | +
|
| 39 | + if ( |
| 40 | + lastAssistant?.formatted.transcript && |
| 41 | + lastAssistant.formatted.transcript !== lastAssistantText |
| 42 | + ) { |
| 43 | + lastAssistantText = lastAssistant.formatted.transcript; |
| 44 | + } |
| 45 | +
|
| 46 | + const lastUser = items |
| 47 | + .slice() |
| 48 | + .reverse() |
| 49 | + .find((item) => item.role === 'user'); |
| 50 | +
|
| 51 | + if (lastUser?.formatted.transcript && lastUser.formatted.transcript !== lastUserText) { |
| 52 | + lastUserText = lastUser.formatted.transcript; |
| 53 | + } |
| 54 | + } |
24 | 55 | </script>
|
25 | 56 |
|
26 | 57 | <button
|
27 |
| - class="absolute inset-0 h-[100dvh] w-screen z-10 text-white flex items-end justify-center p-8 text-sm font-semibold" |
| 58 | + class="absolute inset-0 h-[100dvh] w-screen z-10 text-white flex items-end justify-center p-4 text-sm font-semibold" |
28 | 59 | on:click={() => {
|
29 | 60 | current = (current + 1) % visualizations.length;
|
30 | 61 | }}
|
|
33 | 64 | </button>
|
34 | 65 |
|
35 | 66 | {#if apiKey}
|
36 |
| - <Realtime bind:startConversation bind:wavRecorder bind:wavStreamPlayer {apiKey} /> |
| 67 | + <Realtime bind:startConversation bind:items bind:wavRecorder bind:wavStreamPlayer {apiKey} /> |
37 | 68 | {/if}
|
38 | 69 |
|
39 | 70 | {#if shownVisualizer === 'circle-bars'}
|
40 |
| - <div |
41 |
| - class="absolute flex flex-col md:flex-row items-center justify-center h-[100dvh] w-screen gap-16" |
42 |
| - > |
43 |
| - <div class="h-64 w-96"> |
44 |
| - <CircleBarVisualizer detail={128} wavInput={wavStreamPlayer} startHue={150} endHue={220} /> |
| 71 | + <div class="absolute flex items-center justify-center h-[100dvh] w-screen"> |
| 72 | + <div class="h-96 w-96"> |
| 73 | + <CircleBarVisualizer |
| 74 | + detail={128} |
| 75 | + wavInput={wavRecorder} |
| 76 | + startHue={0} |
| 77 | + endHue={50} |
| 78 | + varyBrightness |
| 79 | + /> |
45 | 80 | </div>
|
| 81 | + </div> |
46 | 82 |
|
47 |
| - <div class="h-64 w-96"> |
48 |
| - <CircleBarVisualizer detail={128} wavInput={wavRecorder} startHue={0} endHue={50} /> |
| 83 | + <div class="absolute flex items-center justify-center h-[100dvh] w-screen"> |
| 84 | + <div class="h-96 w-96"> |
| 85 | + <CircleBarVisualizer |
| 86 | + detail={128} |
| 87 | + wavInput={wavStreamPlayer} |
| 88 | + startHue={150} |
| 89 | + endHue={220} |
| 90 | + varyBrightness |
| 91 | + /> |
49 | 92 | </div>
|
50 | 93 | </div>
|
51 | 94 | {:else if shownVisualizer === 'bars'}
|
52 |
| - <div |
53 |
| - class="absolute flex flex-col md:flex-row items-center justify-center h-[100dvh] w-screen gap-16" |
54 |
| - > |
55 |
| - <div class="h-64 w-96 -scale-y-100 md:scale-y-100"> |
56 |
| - <BarVisualizer barSpacing={8} wavInput={wavStreamPlayer} startHue={150} endHue={220} /> |
57 |
| - </div> |
| 95 | + <div class="absolute flex items-center justify-center h-[100dvh] w-screen"> |
58 | 96 | <div class="h-64 w-96">
|
59 | 97 | <BarVisualizer barSpacing={8} wavInput={wavRecorder} startHue={0} endHue={50} />
|
60 | 98 | </div>
|
61 | 99 | </div>
|
| 100 | + <div class="absolute flex items-center justify-center h-[100dvh] w-screen"> |
| 101 | + <div class="h-64 w-96 -scale-y-100 md:scale-y-100"> |
| 102 | + <BarVisualizer barSpacing={8} wavInput={wavStreamPlayer} startHue={150} endHue={220} /> |
| 103 | + </div> |
| 104 | + </div> |
62 | 105 | {:else if shownVisualizer === 'circle-circles'}
|
63 |
| - <div |
64 |
| - class="absolute flex flex-col md:flex-row items-center justify-center h-[100dvh] w-screen gap-16" |
65 |
| - > |
66 |
| - <div class="h-64 w-96"> |
67 |
| - <CircleCirclesVisualizer wavInput={wavStreamPlayer} startHue={150} endHue={220} /> |
| 106 | + <div class="absolute flex items-center justify-center h-[100dvh] w-screen"> |
| 107 | + <div class="h-96 w-96"> |
| 108 | + <CircleCirclesVisualizer wavInput={wavRecorder} startHue={0} endHue={50} varyBrightness /> |
68 | 109 | </div>
|
69 |
| - <div class="h-64 w-96"> |
70 |
| - <CircleCirclesVisualizer wavInput={wavRecorder} startHue={0} endHue={50} /> |
| 110 | + </div> |
| 111 | + <div class="absolute flex items-center justify-center h-[100dvh] w-screen"> |
| 112 | + <div class="h-96 w-96"> |
| 113 | + <CircleCirclesVisualizer |
| 114 | + wavInput={wavStreamPlayer} |
| 115 | + startHue={150} |
| 116 | + endHue={220} |
| 117 | + varyBrightness |
| 118 | + /> |
71 | 119 | </div>
|
72 | 120 | </div>
|
73 | 121 | {:else if shownVisualizer === 'deformed-circle'}
|
74 |
| - <div |
75 |
| - class="absolute flex flex-col md:flex-row items-center justify-center h-[100dvh] w-screen gap-16" |
76 |
| - > |
| 122 | + <div class="absolute flex items-center justify-center h-[100dvh] w-screen"> |
77 | 123 | <div class="h-96 w-96">
|
78 |
| - <DeformedCircleVisualizer wavInput={wavStreamPlayer} startHue={150} endHue={220} /> |
| 124 | + <DeformedCircleVisualizer wavInput={wavRecorder} startHue={0} endHue={50} /> |
79 | 125 | </div>
|
| 126 | + </div> |
| 127 | + <div class="absolute flex items-center justify-center h-[100dvh] w-screen"> |
80 | 128 | <div class="h-96 w-96">
|
81 |
| - <DeformedCircleVisualizer wavInput={wavRecorder} startHue={0} endHue={50} /> |
| 129 | + <DeformedCircleVisualizer wavInput={wavStreamPlayer} startHue={150} endHue={220} /> |
82 | 130 | </div>
|
83 | 131 | </div>
|
84 | 132 | {:else if shownVisualizer === 'innerglow'}
|
|
103 | 151 | </div>
|
104 | 152 | {/if}
|
105 | 153 |
|
| 154 | +<div |
| 155 | + class="absolute flex flex-col items-center justify-between h-[100dvh] w-screen py-16 px-4 text-center" |
| 156 | +> |
| 157 | + <div |
| 158 | + class="bg-gradient-to-r from-blue-400 via-cyan-400 to-green-400 inline-block text-transparent bg-clip-text font-semibold text-xl max-w-xl" |
| 159 | + > |
| 160 | + {lastAssistantText} |
| 161 | + </div> |
| 162 | + <div class="h-96 w-96"></div> |
| 163 | + <div |
| 164 | + class="bg-gradient-to-r from-red-400 to-amber-400 inline-block text-transparent bg-clip-text font-semibold text-xl max-w-xl" |
| 165 | + > |
| 166 | + {lastUserText} |
| 167 | + </div> |
| 168 | +</div> |
| 169 | + |
106 | 170 | <Modal
|
107 | 171 | onStart={() => {
|
108 | 172 | startConversation();
|
|
0 commit comments