Spaces:
Running

axeronis commited on
Commit
2d10f2f
·
1 Parent(s): 3e1a476

fix(voice): remove borders, fix stop button, match site style

Browse files
Files changed (1) hide show
  1. frontend/app/settings/voice/page.tsx +106 -269
frontend/app/settings/voice/page.tsx CHANGED
@@ -4,7 +4,7 @@ import { useState, useEffect, useRef } from 'react'
4
  import { useAuth } from '@/contexts/AuthContext'
5
  import {
6
  Mic, MicOff, Upload, Trash2, Save, Loader2, CheckCircle2,
7
- Play, Pause, Volume2, AlertCircle, Sparkles, Info
8
  } from 'lucide-react'
9
  import { motion, AnimatePresence } from 'framer-motion'
10
  import { cn } from '@/lib/utils'
@@ -17,59 +17,43 @@ interface VoiceSettings {
17
  voice_reference_url: string | null
18
  }
19
 
20
- // Voice options with demo phrases
21
  const VOICE_OPTIONS = [
22
  {
23
  id: 'professional_male',
24
  name: 'Профессионал',
25
  gender: 'Мужской',
26
- description: 'Уверенный деловой голос. Идеален для B2B продаж и консалтинга.',
27
  icon: '👔',
28
  color: 'indigo',
29
- demoText: 'Здравствуйте! Я ваш персональный менеджер. Готов помочь вам найти идеальное решение для вашего бизнеса.',
30
- traits: ['Уверенный', 'Деловой', 'Авторитетный']
31
  },
32
  {
33
  id: 'friendly_male',
34
  name: 'Дружелюбный',
35
  gender: 'Мужской',
36
- description: 'Тёплый голос для налаживания контакта. Отлично подходит для B2C.',
37
  icon: '😊',
38
  color: 'emerald',
39
- demoText: 'Привет! Рад, что вы написали. Давайте вместе разберёмся, что вам нужно — я уверен, мы найдём отличный вариант!',
40
- traits: ['Дружелюбный', 'Тёплый', 'Располагающий']
41
  },
42
  {
43
  id: 'professional_female',
44
  name: 'Элегантный',
45
  gender: 'Женский',
46
- description: 'Профессиональный женский голос. Вызывает доверие и симпатию.',
47
  icon: '👩‍💼',
48
  color: 'purple',
49
- demoText: 'Добрый день! Спасибо за ваш интерес. Позвольте рассказать вам о наших возможностях подробнее.',
50
- traits: ['Элегантный', 'Доверительный', 'Приятный']
51
  }
52
  ]
53
 
54
- const COLOR_MAP: Record<string, { bg: string, border: string, text: string, badge: string }> = {
55
- indigo: {
56
- bg: 'bg-indigo-500/10',
57
- border: 'border-indigo-500',
58
- text: 'text-indigo-400',
59
- badge: 'bg-indigo-500/20 text-indigo-300'
60
- },
61
- emerald: {
62
- bg: 'bg-emerald-500/10',
63
- border: 'border-emerald-500',
64
- text: 'text-emerald-400',
65
- badge: 'bg-emerald-500/20 text-emerald-300'
66
- },
67
- purple: {
68
- bg: 'bg-purple-500/10',
69
- border: 'border-purple-500',
70
- text: 'text-purple-400',
71
- badge: 'bg-purple-500/20 text-purple-300'
72
- }
73
  }
74
 
75
  export default function VoiceSettingsPage() {
@@ -84,17 +68,8 @@ export default function VoiceSettingsPage() {
84
  const [saving, setSaving] = useState(false)
85
  const [uploading, setUploading] = useState(false)
86
  const [playingVoice, setPlayingVoice] = useState<string | null>(null)
87
- const [isServiceAvailable, setIsServiceAvailable] = useState<boolean | null>(null)
88
- const speechSynthRef = useRef<SpeechSynthesisUtterance | null>(null)
89
 
90
- // Check if Chatterbox service is available
91
- useEffect(() => {
92
- // For now, we'll show as unavailable until user deploys
93
- // In production, this would check CHATTERBOX_API_URL/health
94
- setIsServiceAvailable(false)
95
- }, [])
96
-
97
- // Fetch current settings
98
  useEffect(() => {
99
  const fetchSettings = async () => {
100
  try {
@@ -112,45 +87,35 @@ export default function VoiceSettingsPage() {
112
  setLoading(false)
113
  }
114
  }
115
-
116
- if (token) {
117
- fetchSettings()
118
- }
119
  }, [token])
120
 
121
- // Play demo voice using browser TTS
 
 
 
 
122
  const playDemoVoice = (voiceId: string, text: string) => {
123
- if (playingVoice === voiceId) {
124
- // Stop playing
125
- window.speechSynthesis.cancel()
126
- setPlayingVoice(null)
127
- return
128
  }
129
 
130
- // Stop any current playback
131
- window.speechSynthesis.cancel()
132
-
133
  const utterance = new SpeechSynthesisUtterance(text)
134
  utterance.lang = 'ru-RU'
135
  utterance.rate = 0.9
136
- utterance.pitch = 1.0
137
 
138
- // Try to find a suitable voice
139
  const voices = window.speechSynthesis.getVoices()
140
  const russianVoice = voices.find(v => v.lang.startsWith('ru'))
141
- if (russianVoice) {
142
- utterance.voice = russianVoice
143
- }
144
 
145
  utterance.onend = () => setPlayingVoice(null)
146
  utterance.onerror = () => setPlayingVoice(null)
147
 
148
- speechSynthRef.current = utterance
149
  setPlayingVoice(voiceId)
150
  window.speechSynthesis.speak(utterance)
151
  }
152
 
153
- // Save settings
154
  const saveSettings = async () => {
155
  setSaving(true)
156
  try {
@@ -159,45 +124,22 @@ export default function VoiceSettingsPage() {
159
  })
160
  toast.success('Настройки голоса сохранены!')
161
  } catch (error) {
162
- console.error('Failed to save voice settings:', error)
163
  toast.error('Ошибка сохранения настроек')
164
  } finally {
165
  setSaving(false)
166
  }
167
  }
168
 
169
- // Handle file upload for custom voice
170
  const handleFileUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
171
  const file = event.target.files?.[0]
172
  if (!file) return
173
-
174
  if (file.size > 10 * 1024 * 1024) {
175
  toast.error('Файл слишком большой. Максимум 10MB.')
176
  return
177
  }
178
-
179
- setUploading(true)
180
- try {
181
- toast.warning('Загрузка голоса пока недоступна. Сначала разверните Chatterbox сервис.')
182
- } catch (error) {
183
- console.error('Failed to upload voice:', error)
184
- toast.error('Ошибка загрузки голоса')
185
- } finally {
186
- setUploading(false)
187
- }
188
- }
189
-
190
- const removeCustomVoice = () => {
191
- setSettings(prev => ({
192
- ...prev,
193
- voice_reference_url: null,
194
- voice_id: 'professional_male'
195
- }))
196
  }
197
 
198
- const selectedVoice = VOICE_OPTIONS.find(v => v.id === settings.voice_id)
199
- const selectedColor = selectedVoice ? COLOR_MAP[selectedVoice.color] : COLOR_MAP.indigo
200
-
201
  if (loading) {
202
  return (
203
  <div className="flex items-center justify-center min-h-[400px]">
@@ -207,7 +149,7 @@ export default function VoiceSettingsPage() {
207
  }
208
 
209
  return (
210
- <div className="max-w-5xl mx-auto p-6 space-y-8">
211
  {/* Header */}
212
  <div className="flex items-center justify-between">
213
  <div>
@@ -215,297 +157,192 @@ export default function VoiceSettingsPage() {
215
  <div className="p-2 rounded-xl bg-gradient-to-br from-indigo-500 to-purple-600">
216
  <Volume2 className="w-6 h-6 text-white" />
217
  </div>
218
- Голос AI-менеджера
219
  </h1>
220
- <p className="text-zinc-400 mt-1">
221
- Выберите голос, которым AI будет общаться с клиентами
222
- </p>
223
  </div>
224
-
225
  <button
226
  onClick={saveSettings}
227
  disabled={saving}
228
- className="flex items-center gap-2 px-5 py-2.5 bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500 rounded-xl text-white font-medium transition-all shadow-lg shadow-indigo-500/25 disabled:opacity-50"
229
  >
230
- {saving ? (
231
- <Loader2 className="w-4 h-4 animate-spin" />
232
- ) : (
233
- <Save className="w-4 h-4" />
234
- )}
235
  Сохранить
236
  </button>
237
  </div>
238
 
239
- {/* Service Status Banner */}
240
- {isServiceAvailable === false && (
241
- <motion.div
242
- initial={{ opacity: 0, y: -10 }}
243
- animate={{ opacity: 1, y: 0 }}
244
- className="bg-amber-500/10 border border-amber-500/30 rounded-xl p-4 flex items-start gap-3"
245
- >
246
  <AlertCircle className="w-5 h-5 text-amber-400 flex-shrink-0 mt-0.5" />
247
  <div>
248
  <p className="text-amber-200 font-medium">Голосовой сервис не подключен</p>
249
  <p className="text-amber-300/70 text-sm mt-1">
250
- Для работы голосовых ответов разверните Chatterbox сервис.
251
- Пока что используется демо-режим браузера.
252
  </p>
253
  </div>
254
- </motion.div>
255
  )}
256
 
257
- {/* Voice Enabled Toggle */}
258
- <motion.div
259
- initial={{ opacity: 0, y: 20 }}
260
- animate={{ opacity: 1, y: 0 }}
261
- className="bg-zinc-900/80 backdrop-blur rounded-2xl border border-zinc-800 p-6"
262
- >
263
  <div className="flex items-center justify-between">
264
  <div className="flex items-center gap-4">
265
  <div className={cn(
266
- "w-14 h-14 rounded-2xl flex items-center justify-center transition-all",
267
  settings.voice_enabled
268
- ? "bg-gradient-to-br from-indigo-500 to-purple-600 shadow-lg shadow-indigo-500/30"
269
  : "bg-zinc-800"
270
  )}>
271
- {settings.voice_enabled ? (
272
- <Mic className="w-7 h-7 text-white" />
273
- ) : (
274
- <MicOff className="w-7 h-7 text-zinc-500" />
275
- )}
276
  </div>
277
  <div>
278
- <h3 className="text-lg font-semibold text-white">Голосовые ответы AI</h3>
279
- <p className="text-zinc-400 text-sm">
280
- {settings.voice_enabled
281
- ? 'AI отправляет голосовые сообщения в ключевые моменты'
282
- : 'AI отвечает только текстом'
283
- }
284
  </p>
285
  </div>
286
  </div>
287
-
288
  <button
289
  onClick={() => setSettings(prev => ({ ...prev, voice_enabled: !prev.voice_enabled }))}
290
  className={cn(
291
- "relative w-16 h-9 rounded-full transition-all",
292
- settings.voice_enabled
293
- ? "bg-gradient-to-r from-indigo-600 to-purple-600"
294
- : "bg-zinc-700"
295
  )}
296
  >
297
  <motion.div
298
- animate={{ x: settings.voice_enabled ? 30 : 4 }}
299
  transition={{ type: "spring", stiffness: 500, damping: 30 }}
300
- className="absolute top-1.5 w-6 h-6 bg-white rounded-full shadow-lg"
301
  />
302
  </button>
303
  </div>
304
- </motion.div>
305
 
306
  {/* Voice Selection */}
307
- <motion.div
308
- initial={{ opacity: 0, y: 20 }}
309
- animate={{ opacity: 1, y: 0 }}
310
- transition={{ delay: 0.1 }}
311
- className="space-y-4"
312
- >
313
- <div className="flex items-center gap-2">
314
- <Sparkles className="w-5 h-5 text-indigo-400" />
315
- <h3 className="text-lg font-semibold text-white">Выберите голос</h3>
316
  </div>
317
- <p className="text-zinc-400 text-sm">
318
- Нажмите ▶ чтобы прослушать демо голоса
319
- </p>
320
 
321
- <div className="grid grid-cols-1 lg:grid-cols-3 gap-4">
322
  {VOICE_OPTIONS.map((voice) => {
323
  const isSelected = settings.voice_id === voice.id
324
  const isPlaying = playingVoice === voice.id
325
  const colors = COLOR_MAP[voice.color]
326
 
327
  return (
328
- <motion.div
329
  key={voice.id}
330
- whileHover={{ scale: 1.02 }}
331
- whileTap={{ scale: 0.98 }}
332
  className={cn(
333
- "relative p-5 rounded-2xl border-2 cursor-pointer transition-all",
334
- isSelected
335
- ? `${colors.border} ${colors.bg}`
336
- : "border-zinc-700/50 bg-zinc-900/50 hover:border-zinc-600"
337
  )}
338
- onClick={() => setSettings(prev => ({ ...prev, voice_id: voice.id }))}
339
  >
340
- {/* Selected badge */}
341
- <AnimatePresence>
342
- {isSelected && (
343
- <motion.div
344
- initial={{ opacity: 0, scale: 0.5 }}
345
- animate={{ opacity: 1, scale: 1 }}
346
- exit={{ opacity: 0, scale: 0.5 }}
347
- className="absolute -top-2 -right-2 w-6 h-6 bg-white rounded-full flex items-center justify-center shadow-lg"
348
- >
349
- <CheckCircle2 className={cn("w-5 h-5", colors.text)} />
350
- </motion.div>
351
- )}
352
- </AnimatePresence>
353
 
354
- {/* Icon and name */}
355
- <div className="flex items-center gap-3 mb-3">
356
- <span className="text-3xl">{voice.icon}</span>
357
  <div>
358
- <h4 className="font-semibold text-white">{voice.name}</h4>
359
  <span className="text-xs text-zinc-500">{voice.gender}</span>
360
  </div>
361
  </div>
362
 
363
- {/* Description */}
364
  <p className="text-sm text-zinc-400 mb-3">{voice.description}</p>
365
 
366
- {/* Traits */}
367
- <div className="flex flex-wrap gap-1 mb-4">
368
  {voice.traits.map(trait => (
369
- <span
370
- key={trait}
371
- className={cn(
372
- "px-2 py-0.5 rounded-full text-xs",
373
- isSelected ? colors.badge : "bg-zinc-800 text-zinc-400"
374
- )}
375
- >
376
  {trait}
377
  </span>
378
  ))}
379
  </div>
380
 
381
- {/* Play button */}
382
  <button
383
  onClick={(e) => {
384
  e.stopPropagation()
385
  playDemoVoice(voice.id, voice.demoText)
386
  }}
387
  className={cn(
388
- "w-full flex items-center justify-center gap-2 py-2.5 rounded-xl transition-all font-medium text-sm",
389
- isPlaying
390
- ? `${colors.bg} ${colors.text} border ${colors.border}`
391
- : "bg-zinc-800 hover:bg-zinc-700 text-zinc-300"
392
  )}
393
  >
394
  {isPlaying ? (
395
- <>
396
- <Pause className="w-4 h-4" />
397
- Остановить
398
- </>
399
  ) : (
400
- <>
401
- <Play className="w-4 h-4" />
402
- Прослушать
403
- </>
404
  )}
405
  </button>
406
- </motion.div>
407
  )
408
  })}
409
  </div>
410
- </motion.div>
411
 
412
- {/* Custom Voice Upload */}
413
- <motion.div
414
- initial={{ opacity: 0, y: 20 }}
415
- animate={{ opacity: 1, y: 0 }}
416
- transition={{ delay: 0.2 }}
417
- className="bg-zinc-900/80 backdrop-blur rounded-2xl border border-zinc-800 p-6"
418
- >
419
  <div className="flex items-center gap-2 mb-2">
420
  <Upload className="w-5 h-5 text-purple-400" />
421
- <h3 className="text-lg font-semibold text-white">Клонировать свой голос</h3>
422
- <span className="px-2 py-0.5 rounded-full bg-purple-500/20 text-purple-300 text-xs font-medium">
423
- Скоро
424
- </span>
425
  </div>
426
- <p className="text-zinc-400 text-sm mb-4">
427
- Загрузите аудио 10-30 секунд чётной речи — AI будет говорить вашим голосом
428
- </p>
429
 
430
  {settings.voice_reference_url ? (
431
- <div className="flex items-center gap-4 p-4 bg-zinc-800/50 rounded-xl">
432
- <div className="w-12 h-12 rounded-xl bg-green-500/20 flex items-center justify-center">
433
- <CheckCircle2 className="w-6 h-6 text-green-400" />
434
- </div>
435
  <div className="flex-1">
436
- <p className="text-white font-medium">Кастомный голос загружен</p>
437
- <p className="text-sm text-zinc-400">Ваш голос используется для ответов AI</p>
438
  </div>
439
- <button
440
- onClick={removeCustomVoice}
441
- className="p-2 text-red-400 hover:bg-red-500/10 rounded-lg transition-colors"
442
- >
443
- <Trash2 className="w-5 h-5" />
444
  </button>
445
  </div>
446
  ) : (
447
  <label className="block">
448
- <input
449
- type="file"
450
- accept="audio/*"
451
- onChange={handleFileUpload}
452
- className="hidden"
453
- disabled={uploading || !isServiceAvailable}
454
- />
455
  <div className={cn(
456
- "flex flex-col items-center justify-center p-8 border-2 border-dashed rounded-xl transition-colors",
457
- !isServiceAvailable
458
- ? "border-zinc-700 bg-zinc-800/20 cursor-not-allowed opacity-50"
459
- : uploading
460
- ? "border-zinc-600 bg-zinc-800/30 cursor-wait"
461
- : "border-zinc-700 hover:border-purple-500 hover:bg-purple-500/5 cursor-pointer"
462
  )}>
463
- {uploading ? (
464
- <Loader2 className="w-8 h-8 animate-spin text-purple-400 mb-2" />
465
- ) : (
466
- <Upload className="w-8 h-8 text-zinc-500 mb-2" />
467
- )}
468
- <p className="text-white font-medium">
469
- {!isServiceAvailable
470
- ? 'Сначала подключите голосовой сервис'
471
- : uploading
472
- ? 'Загрузка...'
473
- : 'Нажмите для загрузки аудио'
474
- }
475
- </p>
476
- <p className="text-sm text-zinc-500 mt-1">
477
- WAV, MP3, OGG • Максимум 10MB
478
- </p>
479
  </div>
480
  </label>
481
  )}
482
- </motion.div>
483
 
484
- {/* When AI uses voice - Info box */}
485
- <motion.div
486
- initial={{ opacity: 0, y: 20 }}
487
- animate={{ opacity: 1, y: 0 }}
488
- transition={{ delay: 0.3 }}
489
- className="bg-gradient-to-br from-indigo-500/10 via-purple-500/10 to-pink-500/10 rounded-2xl border border-indigo-500/20 p-6"
490
- >
491
- <h3 className="text-lg font-semibold text-white mb-4 flex items-center gap-2">
492
- <Info className="w-5 h-5 text-indigo-400" />
493
  Когда AI отправляет голосовые?
494
  </h3>
495
- <div className="grid grid-cols-1 md:grid-cols-2 gap-3">
496
  {[
497
- { emoji: '🎙️', text: 'Когда клиент отправляет голосовое (voice-to-voice)' },
498
- { emoji: '🤝', text: 'При закрытии сделки — для усиления эффекта' },
499
- { emoji: '💪', text: 'При преодолении возражений — показывает уверенность' },
500
- { emoji: '❤️', text: 'Для создания доверия ("Я лично гарантирую...")' }
501
  ].map((item, i) => (
502
- <div key={i} className="flex items-center gap-3 p-3 rounded-xl bg-white/5">
503
- <span className="text-xl">{item.emoji}</span>
504
- <span className="text-zinc-300 text-sm">{item.text}</span>
505
  </div>
506
  ))}
507
  </div>
508
- </motion.div>
509
  </div>
510
  )
511
  }
 
4
  import { useAuth } from '@/contexts/AuthContext'
5
  import {
6
  Mic, MicOff, Upload, Trash2, Save, Loader2, CheckCircle2,
7
+ Play, Square, Volume2, AlertCircle, Sparkles, Info
8
  } from 'lucide-react'
9
  import { motion, AnimatePresence } from 'framer-motion'
10
  import { cn } from '@/lib/utils'
 
17
  voice_reference_url: string | null
18
  }
19
 
 
20
  const VOICE_OPTIONS = [
21
  {
22
  id: 'professional_male',
23
  name: 'Профессионал',
24
  gender: 'Мужской',
25
+ description: 'Уверенный деловой голос. Идеален для B2B продаж.',
26
  icon: '👔',
27
  color: 'indigo',
28
+ demoText: 'Здравствуйте! Я ваш менеджер. Готов помочь найти решение для бизнеса.',
29
+ traits: ['Уверенный', 'Деловой']
30
  },
31
  {
32
  id: 'friendly_male',
33
  name: 'Дружелюбный',
34
  gender: 'Мужской',
35
+ description: 'Тёплый голос для налаживания контакта.',
36
  icon: '😊',
37
  color: 'emerald',
38
+ demoText: 'Привет! Рад что написали. Давайте разберёмся что вам нужно!',
39
+ traits: ['Тёплый', 'Располагающий']
40
  },
41
  {
42
  id: 'professional_female',
43
  name: 'Элегантный',
44
  gender: 'Женский',
45
+ description: 'Профессиональный женский голос.',
46
  icon: '👩‍💼',
47
  color: 'purple',
48
+ demoText: 'Добрый день! Спасибо за интерес. Расскажу подробнее.',
49
+ traits: ['Элегантный', 'Приятный']
50
  }
51
  ]
52
 
53
+ const COLOR_MAP: Record<string, { bg: string, text: string, badge: string }> = {
54
+ indigo: { bg: 'bg-indigo-500/10', text: 'text-indigo-400', badge: 'bg-indigo-500/20 text-indigo-300' },
55
+ emerald: { bg: 'bg-emerald-500/10', text: 'text-emerald-400', badge: 'bg-emerald-500/20 text-emerald-300' },
56
+ purple: { bg: 'bg-purple-500/10', text: 'text-purple-400', badge: 'bg-purple-500/20 text-purple-300' }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  }
58
 
59
  export default function VoiceSettingsPage() {
 
68
  const [saving, setSaving] = useState(false)
69
  const [uploading, setUploading] = useState(false)
70
  const [playingVoice, setPlayingVoice] = useState<string | null>(null)
71
+ const [isServiceAvailable] = useState<boolean>(false)
 
72
 
 
 
 
 
 
 
 
 
73
  useEffect(() => {
74
  const fetchSettings = async () => {
75
  try {
 
87
  setLoading(false)
88
  }
89
  }
90
+ if (token) fetchSettings()
 
 
 
91
  }, [token])
92
 
93
+ const stopPlayback = () => {
94
+ window.speechSynthesis.cancel()
95
+ setPlayingVoice(null)
96
+ }
97
+
98
  const playDemoVoice = (voiceId: string, text: string) => {
99
+ if (playingVoice) {
100
+ stopPlayback()
101
+ if (playingVoice === voiceId) return
 
 
102
  }
103
 
 
 
 
104
  const utterance = new SpeechSynthesisUtterance(text)
105
  utterance.lang = 'ru-RU'
106
  utterance.rate = 0.9
 
107
 
 
108
  const voices = window.speechSynthesis.getVoices()
109
  const russianVoice = voices.find(v => v.lang.startsWith('ru'))
110
+ if (russianVoice) utterance.voice = russianVoice
 
 
111
 
112
  utterance.onend = () => setPlayingVoice(null)
113
  utterance.onerror = () => setPlayingVoice(null)
114
 
 
115
  setPlayingVoice(voiceId)
116
  window.speechSynthesis.speak(utterance)
117
  }
118
 
 
119
  const saveSettings = async () => {
120
  setSaving(true)
121
  try {
 
124
  })
125
  toast.success('Настройки голоса сохранены!')
126
  } catch (error) {
 
127
  toast.error('Ошибка сохранения настроек')
128
  } finally {
129
  setSaving(false)
130
  }
131
  }
132
 
 
133
  const handleFileUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
134
  const file = event.target.files?.[0]
135
  if (!file) return
 
136
  if (file.size > 10 * 1024 * 1024) {
137
  toast.error('Файл слишком большой. Максимум 10MB.')
138
  return
139
  }
140
+ toast.warning('Сначала разверните Chatterbox сервис.')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
142
 
 
 
 
143
  if (loading) {
144
  return (
145
  <div className="flex items-center justify-center min-h-[400px]">
 
149
  }
150
 
151
  return (
152
+ <div className="max-w-4xl mx-auto p-6 space-y-6">
153
  {/* Header */}
154
  <div className="flex items-center justify-between">
155
  <div>
 
157
  <div className="p-2 rounded-xl bg-gradient-to-br from-indigo-500 to-purple-600">
158
  <Volume2 className="w-6 h-6 text-white" />
159
  </div>
160
+ Голос AI
161
  </h1>
162
+ <p className="text-zinc-400 mt-1">Настройте голос AI-менеджера</p>
 
 
163
  </div>
 
164
  <button
165
  onClick={saveSettings}
166
  disabled={saving}
167
+ className="flex items-center gap-2 px-5 py-2.5 bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500 rounded-xl text-white font-medium transition-all disabled:opacity-50"
168
  >
169
+ {saving ? <Loader2 className="w-4 h-4 animate-spin" /> : <Save className="w-4 h-4" />}
 
 
 
 
170
  Сохранить
171
  </button>
172
  </div>
173
 
174
+ {/* Service Status */}
175
+ {!isServiceAvailable && (
176
+ <div className="bg-amber-500/10 rounded-xl p-4 flex items-start gap-3">
 
 
 
 
177
  <AlertCircle className="w-5 h-5 text-amber-400 flex-shrink-0 mt-0.5" />
178
  <div>
179
  <p className="text-amber-200 font-medium">Голосовой сервис не подключен</p>
180
  <p className="text-amber-300/70 text-sm mt-1">
181
+ Демо использует браузерный синтез (роботизированный). После развертывания Chatterbox голоса будут естественными.
 
182
  </p>
183
  </div>
184
+ </div>
185
  )}
186
 
187
+ {/* Voice Toggle */}
188
+ <div className="bg-zinc-900/50 rounded-xl p-5">
 
 
 
 
189
  <div className="flex items-center justify-between">
190
  <div className="flex items-center gap-4">
191
  <div className={cn(
192
+ "w-12 h-12 rounded-xl flex items-center justify-center",
193
  settings.voice_enabled
194
+ ? "bg-gradient-to-br from-indigo-500 to-purple-600"
195
  : "bg-zinc-800"
196
  )}>
197
+ {settings.voice_enabled ? <Mic className="w-6 h-6 text-white" /> : <MicOff className="w-6 h-6 text-zinc-500" />}
 
 
 
 
198
  </div>
199
  <div>
200
+ <h3 className="text-lg font-medium text-white">Голосовые ответы</h3>
201
+ <p className="text-zinc-500 text-sm">
202
+ {settings.voice_enabled ? 'AI отправляет голосовые в ключевые моменты' : 'Только текст'}
 
 
 
203
  </p>
204
  </div>
205
  </div>
 
206
  <button
207
  onClick={() => setSettings(prev => ({ ...prev, voice_enabled: !prev.voice_enabled }))}
208
  className={cn(
209
+ "relative w-14 h-8 rounded-full transition-all",
210
+ settings.voice_enabled ? "bg-gradient-to-r from-indigo-600 to-purple-600" : "bg-zinc-700"
 
 
211
  )}
212
  >
213
  <motion.div
214
+ animate={{ x: settings.voice_enabled ? 26 : 4 }}
215
  transition={{ type: "spring", stiffness: 500, damping: 30 }}
216
+ className="absolute top-1 w-6 h-6 bg-white rounded-full shadow-lg"
217
  />
218
  </button>
219
  </div>
220
+ </div>
221
 
222
  {/* Voice Selection */}
223
+ <div className="space-y-4">
224
+ <div className="flex items-center justify-between">
225
+ <div className="flex items-center gap-2">
226
+ <Sparkles className="w-5 h-5 text-indigo-400" />
227
+ <h3 className="text-lg font-medium text-white">Выберите голос</h3>
228
+ </div>
229
+ <span className="text-zinc-500 text-sm">▶ — прослушать демо</span>
 
 
230
  </div>
 
 
 
231
 
232
+ <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
233
  {VOICE_OPTIONS.map((voice) => {
234
  const isSelected = settings.voice_id === voice.id
235
  const isPlaying = playingVoice === voice.id
236
  const colors = COLOR_MAP[voice.color]
237
 
238
  return (
239
+ <div
240
  key={voice.id}
241
+ onClick={() => setSettings(prev => ({ ...prev, voice_id: voice.id }))}
 
242
  className={cn(
243
+ "relative p-4 rounded-xl cursor-pointer transition-all",
244
+ isSelected ? colors.bg : "bg-zinc-900/50 hover:bg-zinc-800/50"
 
 
245
  )}
 
246
  >
247
+ {isSelected && (
248
+ <div className="absolute -top-1.5 -right-1.5 w-5 h-5 bg-white rounded-full flex items-center justify-center">
249
+ <CheckCircle2 className={cn("w-4 h-4", colors.text)} />
250
+ </div>
251
+ )}
 
 
 
 
 
 
 
 
252
 
253
+ <div className="flex items-center gap-3 mb-2">
254
+ <span className="text-2xl">{voice.icon}</span>
 
255
  <div>
256
+ <h4 className="font-medium text-white">{voice.name}</h4>
257
  <span className="text-xs text-zinc-500">{voice.gender}</span>
258
  </div>
259
  </div>
260
 
 
261
  <p className="text-sm text-zinc-400 mb-3">{voice.description}</p>
262
 
263
+ <div className="flex flex-wrap gap-1 mb-3">
 
264
  {voice.traits.map(trait => (
265
+ <span key={trait} className={cn("px-2 py-0.5 rounded-full text-xs", isSelected ? colors.badge : "bg-zinc-800 text-zinc-500")}>
 
 
 
 
 
 
266
  {trait}
267
  </span>
268
  ))}
269
  </div>
270
 
 
271
  <button
272
  onClick={(e) => {
273
  e.stopPropagation()
274
  playDemoVoice(voice.id, voice.demoText)
275
  }}
276
  className={cn(
277
+ "w-full flex items-center justify-center gap-2 py-2 rounded-lg transition-all text-sm",
278
+ isPlaying ? `${colors.bg} ${colors.text}` : "bg-zinc-800 hover:bg-zinc-700 text-zinc-400"
 
 
279
  )}
280
  >
281
  {isPlaying ? (
282
+ <><Square className="w-3.5 h-3.5" /> Стоп</>
 
 
 
283
  ) : (
284
+ <><Play className="w-3.5 h-3.5" /> Демо</>
 
 
 
285
  )}
286
  </button>
287
+ </div>
288
  )
289
  })}
290
  </div>
291
+ </div>
292
 
293
+ {/* Custom Voice */}
294
+ <div className="bg-zinc-900/50 rounded-xl p-5">
 
 
 
 
 
295
  <div className="flex items-center gap-2 mb-2">
296
  <Upload className="w-5 h-5 text-purple-400" />
297
+ <h3 className="font-medium text-white">Клонировать свой голос</h3>
298
+ <span className="px-2 py-0.5 rounded-full bg-purple-500/20 text-purple-300 text-xs">Скоро</span>
 
 
299
  </div>
300
+ <p className="text-zinc-500 text-sm mb-4">Загрузите аудио 10-30 сек для к��онирования</p>
 
 
301
 
302
  {settings.voice_reference_url ? (
303
+ <div className="flex items-center gap-4 p-3 bg-zinc-800/50 rounded-lg">
304
+ <CheckCircle2 className="w-5 h-5 text-green-400" />
 
 
305
  <div className="flex-1">
306
+ <p className="text-white text-sm">Голос загружен</p>
 
307
  </div>
308
+ <button onClick={() => setSettings(prev => ({ ...prev, voice_reference_url: null, voice_id: 'professional_male' }))} className="p-1.5 text-red-400 hover:bg-red-500/10 rounded-lg">
309
+ <Trash2 className="w-4 h-4" />
 
 
 
310
  </button>
311
  </div>
312
  ) : (
313
  <label className="block">
314
+ <input type="file" accept="audio/*" onChange={handleFileUpload} className="hidden" disabled={!isServiceAvailable} />
 
 
 
 
 
 
315
  <div className={cn(
316
+ "flex flex-col items-center justify-center p-6 rounded-xl transition-colors",
317
+ !isServiceAvailable ? "bg-zinc-800/30 cursor-not-allowed opacity-50" : "bg-zinc-800/50 hover:bg-zinc-800 cursor-pointer"
 
 
 
 
318
  )}>
319
+ <Upload className="w-6 h-6 text-zinc-500 mb-2" />
320
+ <p className="text-zinc-400 text-sm">{!isServiceAvailable ? 'Подключите сервис' : 'Загрузить аудио'}</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  </div>
322
  </label>
323
  )}
324
+ </div>
325
 
326
+ {/* Info */}
327
+ <div className="bg-gradient-to-br from-indigo-500/5 to-purple-500/5 rounded-xl p-5">
328
+ <h3 className="font-medium text-white mb-3 flex items-center gap-2">
329
+ <Info className="w-4 h-4 text-indigo-400" />
 
 
 
 
 
330
  Когда AI отправляет голосовые?
331
  </h3>
332
+ <div className="grid grid-cols-2 gap-2 text-sm">
333
  {[
334
+ { emoji: '🎙️', text: 'Ответ на голосовое клиента' },
335
+ { emoji: '🤝', text: 'Закрытие сделки' },
336
+ { emoji: '💪', text: 'Преодоление возражений' },
337
+ { emoji: '❤️', text: 'Создание доверия' }
338
  ].map((item, i) => (
339
+ <div key={i} className="flex items-center gap-2 p-2 rounded-lg bg-zinc-900/30">
340
+ <span>{item.emoji}</span>
341
+ <span className="text-zinc-400">{item.text}</span>
342
  </div>
343
  ))}
344
  </div>
345
+ </div>
346
  </div>
347
  )
348
  }