generated from cameronking4/VapiBlocks
-
Notifications
You must be signed in to change notification settings - Fork 8
/
siri.tsx
165 lines (156 loc) · 5.79 KB
/
siri.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"use client";
import React, { useState, useEffect } from 'react';
import { Mic, MicOff } from 'lucide-react';
import ReactSiriwave, { IReactSiriwaveProps } from 'react-siriwave';
import { motion, AnimatePresence } from 'framer-motion';
import useWebRTCAudioSession from '@/hooks/use-webrtc'; // Replace useVapi import
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
// Define CurveStyle type
type CurveStyle = "ios" | "ios9";
interface SiriProps {
theme: CurveStyle;
}
const Siri: React.FC<SiriProps> = ({ theme }) => {
const { currentVolume, isSessionActive, handleStartStopClick } = useWebRTCAudioSession('alloy'); // Replace useVapi hook
const [siriWaveConfig, setSiriWaveConfig] = useState<IReactSiriwaveProps>({
theme: theme || "ios9",
ratio: 1,
speed: 5,
amplitude: 25,
frequency: 15,
color: '#9E9E9E',
cover: true,
width: 300,
height: 100,
autostart: true,
pixelDepth: 1,
lerpSpeed: 0.1,
});
useEffect(() => {
setSiriWaveConfig(prevConfig => ({
...prevConfig,
amplitude: isSessionActive ? (currentVolume > 0.02 ? currentVolume * 50 : 0) : 0,
speed: isSessionActive ? (currentVolume > 0.1 ? currentVolume * 50 : 0) : 0,
frequency: isSessionActive ? (currentVolume > 0.01 ? currentVolume * 50 : 0) : (currentVolume > 0.5 ? currentVolume * 100 : 0),
}));
}, [currentVolume, isSessionActive]);
const handleToggleCall = () => {
handleStartStopClick();
};
const handleConfigChange = (key: keyof IReactSiriwaveProps, value: any) => {
setSiriWaveConfig(prevConfig => ({
...prevConfig,
[key]: value,
}));
};
return (
<div className="flex flex-col items-center justify-center min-h-full p-6">
<div className="flex items-center justify-center">
<motion.button
key="callButton"
onClick={handleToggleCall}
className="p-2 rounded-xl bg-secondary"
whileTap={{ scale: 0.9 }}
whileHover={{ scale: 1.1 }}
initial={{ x: 0 }}
animate={{ x: isSessionActive ? -10 : 0 }}
transition={{ duration: 0.3 }}
style={{ zIndex: 10, position: 'relative' }}
>
<AnimatePresence>
{!isSessionActive ? (
<motion.div
key="micIcon"
initial={{ opacity: 1 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.2 }}
>
<Mic size={20} />
</motion.div>
) : (
<MicOff size={20} />
)}
</AnimatePresence>
</motion.button>
<motion.div
className="rounded-4xl p-4 overflow-hidden"
initial={{ width: 0, opacity: 0 }}
animate={{ width: '100%', opacity: 1 }}
exit={{ width: 0, opacity: 0 }}
transition={{ duration: 0.3 }}
style={{ marginLeft: '10px' }}
>
<ReactSiriwave {...siriWaveConfig} />
</motion.div>
</div>
<Popover>
<PopoverTrigger asChild>
<Button variant="outline" className="mt-4">Configure Siriwave</Button>
</PopoverTrigger>
<PopoverContent className="w-80">
<div className="grid gap-4">
<div className="space-y-2">
<h4 className="font-medium leading-none">Siriwave Configuration</h4>
</div>
<div className="grid gap-2">
<div className="grid grid-cols-3 items-center gap-4">
<Label htmlFor="theme">Theme</Label>
<Input
id="theme"
defaultValue={siriWaveConfig.theme}
className="col-span-2 h-8"
onChange={e => handleConfigChange('theme', e.target.value)}
/>
</div>
<div className="grid grid-cols-3 items-center gap-4">
<Label htmlFor="speed">Speed</Label>
<Input
id="speed"
type="number"
defaultValue={siriWaveConfig.speed}
className="col-span-2 h-8"
onChange={e => handleConfigChange('speed', parseFloat(e.target.value))}
/>
</div>
<div className="grid grid-cols-3 items-center gap-4">
<Label htmlFor="amplitude">Amplitude</Label>
<Input
id="amplitude"
type="number"
defaultValue={siriWaveConfig.amplitude}
className="col-span-2 h-8"
onChange={e => handleConfigChange('amplitude', parseFloat(e.target.value))}
/>
</div>
<div className="grid grid-cols-3 items-center gap-4">
<Label htmlFor="frequency">Frequency</Label>
<Input
id="frequency"
type="number"
defaultValue={siriWaveConfig.frequency}
className="col-span-2 h-8"
onChange={e => handleConfigChange('frequency', parseFloat(e.target.value))}
/>
</div>
<div className="grid grid-cols-3 items-center gap-4">
<Label htmlFor="color">Color</Label>
<Input
id="color"
type="text"
defaultValue={siriWaveConfig.color}
className="col-span-2 h-8"
onChange={e => handleConfigChange('color', e.target.value)}
/>
</div>
</div>
</div>
</PopoverContent>
</Popover>
</div>
);
};
export default Siri;