-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
845 lines (781 loc) · 26.7 KB
/
index.html
File metadata and controls
845 lines (781 loc) · 26.7 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ghost Pitch Engine</title>
<style>
:root {
--bg: #0a0a0f;
--card: #12121a;
--accent: #00ff88;
--danger: #ff4444;
--warn: #ffaa00;
--ghost: #8b5cf6;
--text: #e0e0e0;
--dim: #666;
--header-h: 44px;
--log-h: 160px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}
/* ===== HEADER BAR ===== */
#header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: var(--header-h);
z-index: 100;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 16px;
background: var(--card);
border-bottom: 1px solid #252530;
font-size: 11px;
gap: 12px;
overflow: hidden;
}
#header .logo {
color: var(--ghost);
font-weight: bold;
font-size: 13px;
letter-spacing: 1px;
flex-shrink: 0;
}
#instrument {
display: flex;
align-items: center;
gap: 20px;
color: var(--dim);
}
#instrument span { color: var(--accent); }
#i-remaining { color: var(--warn) !important; font-weight: bold; }
/* ===== MAIN LAYOUT GRID ===== */
#stage {
position: fixed;
top: var(--header-h);
left: 0;
right: 0;
bottom: 0;
display: grid;
grid-template-columns: 340px 1fr;
grid-template-rows: 1fr;
gap: 0;
overflow: hidden;
}
/* ===== LEFT SIDEBAR ===== */
#sidebar {
display: flex;
flex-direction: column;
gap: 10px;
padding: 12px;
border-right: 1px solid #1e1e28;
overflow: hidden;
background: #0c0c14;
}
/* Phase pill */
#phase-indicator {
font-size: 10px;
text-transform: uppercase;
letter-spacing: 3px;
color: var(--dim);
padding: 5px 14px;
border: 1px solid #333;
border-radius: 20px;
text-align: center;
flex-shrink: 0;
align-self: flex-start;
}
#phase-indicator.active { color: var(--accent); border-color: var(--accent); }
#phase-indicator.listening { color: var(--warn); border-color: var(--warn); animation: pulse 1s infinite; }
/* Ghost card */
.ghost-card {
background: var(--card);
border: 1px solid #252530;
border-radius: 10px;
padding: 16px;
position: relative;
overflow: hidden;
flex-shrink: 0;
}
.ghost-card::before {
content: '';
position: absolute;
top: 0; left: 0; right: 0;
height: 2px;
background: linear-gradient(90deg, var(--ghost), var(--accent));
}
.ghost-card h2 {
color: var(--ghost);
font-size: 16px;
margin-bottom: 4px;
line-height: 1.3;
}
.ghost-card .ghost-type {
color: var(--dim);
font-size: 10px;
text-transform: uppercase;
letter-spacing: 2px;
margin-bottom: 10px;
}
.ghost-card .pitch {
font-size: 13px;
line-height: 1.55;
color: var(--text);
}
/* Crowd meter */
#crowd-meter-container {
flex-shrink: 0;
display: none;
}
#crowd-meter-label {
display: flex;
justify-content: space-between;
font-size: 11px;
color: var(--dim);
margin-bottom: 6px;
}
#crowd-meter-bar {
width: 100%;
height: 28px;
background: #1a1a2e;
border-radius: 6px;
overflow: hidden;
position: relative;
}
#crowd-meter-fill {
height: 100%;
width: 0%;
transition: width 0.1s, background 0.3s;
background: var(--accent);
border-radius: 6px;
}
#crowd-meter-fill.boo { background: var(--danger); }
#crowd-meter-fill.cheer { background: var(--accent); }
#crowd-meter-fill.dead { background: var(--dim); }
#crowd-sentiment {
font-size: 12px;
text-align: center;
margin-top: 6px;
min-height: 18px;
}
/* Judge panel */
.judge-panel {
display: flex;
flex-direction: column;
gap: 8px;
flex-shrink: 0;
}
.judge-card {
background: var(--card);
border: 1px solid #252530;
border-radius: 8px;
padding: 10px 12px;
font-size: 12px;
}
.judge-card h3 {
color: var(--ghost);
font-size: 12px;
margin-bottom: 5px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.judge-card .verdict {
font-style: italic;
color: var(--dim);
line-height: 1.45;
font-size: 11px;
}
/* Superchat stats */
#superchat-stats {
background: var(--card);
border: 1px solid #252530;
border-radius: 8px;
padding: 12px;
font-size: 12px;
flex-shrink: 0;
overflow: hidden;
}
#superchat-stats h3 { color: var(--warn); font-size: 11px; margin-bottom: 6px; }
/* Controls */
#controls {
display: flex;
gap: 8px;
flex-shrink: 0;
margin-top: auto;
padding-top: 8px;
}
button {
font-family: inherit;
font-size: 12px;
padding: 9px 18px;
border-radius: 6px;
border: none;
cursor: pointer;
font-weight: bold;
text-transform: uppercase;
letter-spacing: 1px;
transition: all 0.15s;
flex: 1;
}
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }
#btn-start { background: var(--ghost); color: white; }
#btn-overdrive { background: var(--danger); color: white; display: none; }
#btn-skip { background: transparent; border: 1px solid #333; color: var(--dim); display: none; }
/* ===== RIGHT PANEL — DEMO IFRAME ===== */
#demo-area {
position: relative;
display: flex;
flex-direction: column;
overflow: hidden;
background: var(--bg);
}
#demo-frame {
flex: 1;
width: 100%;
border: none;
background: #000;
display: block;
}
/* When demo is hidden, show a placeholder */
#demo-placeholder {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
color: #1e1e28;
font-size: 48px;
letter-spacing: 4px;
border: 1px dashed #1e1e28;
margin: 16px;
border-radius: 12px;
user-select: none;
}
#demo-placeholder span {
text-align: center;
line-height: 1.4;
font-size: 13px;
color: #333;
letter-spacing: 2px;
text-transform: uppercase;
}
/* QR code — top-right corner of demo area */
#qr-container {
position: absolute;
top: 12px;
right: 12px;
background: var(--card);
border: 1px solid #252530;
border-radius: 10px;
padding: 10px;
text-align: center;
z-index: 10;
}
#qr-container img {
display: block;
width: 120px;
height: 120px;
border-radius: 4px;
}
#deploy-url {
color: var(--ghost);
font-size: 9px;
margin-top: 6px;
word-break: break-all;
max-width: 120px;
}
/* Feedback banner — appears after dud rejection */
#feedback-banner {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background: linear-gradient(180deg, rgba(139,92,246,0.15) 0%, rgba(10,10,15,0.95) 100%);
border-top: 2px solid var(--ghost);
padding: 14px 24px;
display: none;
align-items: center;
justify-content: space-between;
z-index: 20;
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
#feedback-banner .fb-text {
color: var(--text);
font-size: 14px;
font-weight: bold;
}
#feedback-banner .fb-text small {
display: block;
color: var(--dim);
font-size: 11px;
font-weight: normal;
margin-top: 2px;
}
#feedback-banner .fb-url {
color: var(--ghost);
font-size: 13px;
font-weight: bold;
letter-spacing: 1px;
background: var(--card);
padding: 8px 16px;
border-radius: 8px;
border: 1px solid var(--ghost);
}
@keyframes bannerSlide { from { transform: translateY(100%); } to { transform: translateY(0); } }
#feedback-banner.visible { display: flex; animation: bannerSlide 0.4s ease-out; }
/* ===== TRANSCRIPT LOG — bottom of sidebar ===== */
#transcript {
flex: 1;
min-height: 0;
max-height: 200px;
background: rgba(12, 12, 20, 0.92);
border: 1px solid #1e1e28;
border-radius: 8px;
padding: 8px 10px;
font-size: 10px;
overflow-y: auto;
color: var(--dim);
line-height: 1.6;
}
#transcript:empty { display: none; }
#transcript .log-entry { display: block; }
#transcript .log-entry .ts { color: #3a3a50; margin-right: 6px; }
#transcript .log-entry .msg { color: #888; }
#transcript .log-entry .model { color: var(--ghost); }
#transcript .log-entry .tokens { color: var(--accent); }
/* ===== ANIMATIONS ===== */
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }
.hidden { display: none !important; }
.fade-in { animation: fadeIn 0.4s ease-in; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
/* ===== RESPONSIVE: 1280x720 projector ===== */
@media (max-width: 1280px) {
#stage { grid-template-columns: 300px 1fr; }
}
@media (max-height: 720px) {
:root { --header-h: 38px; --log-h: 130px; }
.ghost-card { padding: 12px; }
.ghost-card h2 { font-size: 14px; }
.ghost-card .pitch { font-size: 12px; }
}
</style>
</head>
<body>
<!-- ===== HEADER BAR ===== -->
<div id="header">
<div class="logo">GHOST PITCH ENGINE</div>
<div id="instrument">
Phase: <span id="i-phase">idle</span>
|
Model: <span id="i-model">—</span>
|
Tokens: <span id="i-tokens">0</span>
|
Elapsed: <span id="i-elapsed">0.0s</span>
|
Left: <span id="i-remaining">2:30</span>
</div>
</div>
<!-- ===== MAIN STAGE ===== -->
<div id="stage">
<!-- LEFT SIDEBAR -->
<div id="sidebar">
<div id="phase-indicator">READY</div>
<!-- Ghost card -->
<div class="ghost-card hidden fade-in" id="ghost-card">
<h2 id="ghost-name"></h2>
<div class="ghost-type" id="ghost-type"></div>
<div class="pitch" id="ghost-pitch"></div>
</div>
<!-- Crowd meter -->
<div id="crowd-meter-container">
<div id="crowd-meter-label">
<span>BOO</span>
<span id="crowd-timer">5s</span>
<span>CHEER</span>
</div>
<div id="crowd-meter-bar">
<div id="crowd-meter-fill"></div>
</div>
<div id="crowd-sentiment"></div>
</div>
<!-- Judge panel — judge cards injected here by show.js -->
<div class="judge-panel hidden" id="judge-panel"></div>
<!-- UserMap sponsor widget -->
<div id="usermap-widget" style="background:var(--card);border:1px solid #252530;border-radius:8px;padding:10px 12px;flex-shrink:0;overflow:hidden">
<div style="display:flex;align-items:center;gap:8px;margin-bottom:6px">
<div id="usermap-dot" style="width:8px;height:8px;border-radius:50%;background:#444;transition:background 0.3s"></div>
<span style="color:var(--accent);font-size:11px;text-transform:uppercase;letter-spacing:1px;font-weight:bold">UserMap</span>
<span id="usermap-count" style="color:var(--text);font-size:14px;font-weight:bold;margin-left:auto">0</span>
</div>
<div id="usermap-feed" style="color:var(--dim);font-size:10px;max-height:60px;overflow-y:auto"></div>
</div>
<!-- Superchat stats -->
<div id="superchat-stats"><h3>LIVE SUPERCHAT</h3><div style="color:var(--dim);font-size:11px">Waiting for feedback...</div></div>
<!-- Transcript log -->
<div id="transcript"></div>
<!-- Controls -->
<div id="controls">
<button id="btn-start">Start the Show</button>
<button id="btn-overdrive">OVERDRIVE</button>
<button id="btn-skip">Skip</button>
</div>
</div>
<!-- RIGHT: DEMO AREA -->
<div id="demo-area">
<!-- Placeholder shown before demo loads -->
<div id="demo-placeholder">
<span>DEMO BUILDS HERE</span>
</div>
<!-- Demo iframe — hidden until show.js calls showDemo() -->
<iframe id="demo-frame" class="hidden"></iframe>
<!-- QR code overlay — top-right corner, visible from page load -->
<div id="qr-container">
<p id="deploy-url" style="word-break:break-all"></p>
<img id="qr-img" src="" alt="Scan to give feedback" style="display:none">
</div>
<script>
(function() {
var u = location.origin + '/superchat.html';
document.getElementById('deploy-url').textContent = u.replace(/^https?:\/\//, '');
var img = document.getElementById('qr-img');
img.src = 'https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=' + encodeURIComponent(u) + '&bgcolor=0a0a0f&color=8b5cf6';
img.style.display = 'block';
})();
</script>
<!-- Feedback banner — slides up after dud is rejected -->
<div id="feedback-banner">
<div class="fb-text">
FEEDBACK OPEN <small>Tell us what to build into the real pitch</small>
</div>
<div class="fb-url" id="feedback-url"></div>
</div>
</div>
</div>
<script>
// ============================================================
// CONFIG — everyone edits this
// ============================================================
const CONFIG = {
featherless: {
baseUrl: 'https://api.featherless.ai/v1',
apiKey: 'rc_bc57634bdb07608f5d28175030f049b842e64c4fbf35bad9b9268d7f3e0d22ff', // expires 2026-03-17
models: {
corpus: [
'mistralai/Mistral-Nemo-Instruct-2407', // fastest
'mistralai/Mistral-Large-Instruct-2411', // fast + good
'Qwen/Qwen2-72B-Instruct', // solid
'NousResearch/Meta-Llama-3-70B-Instruct', // reliable
'moonshotai/Kimi-K2-Instruct', // good quality
'MiniMaxAI/MiniMax-M2.5', // decent
],
judges: {
carla: 'mistralai/Mistral-Large-Instruct-2411',
rod: 'Qwen/Qwen2-72B-Instruct',
dan: 'mistralai/Mistral-Nemo-Instruct-2407',
}
}
},
crowd: {
reactionWindowMs: 2000,
cheerBandHz: [2000, 8000],
booBandHz: [100, 500],
dudThreshold: 10,
fftSize: 2048,
},
tts: {
rate: 1.0,
pitch: 1.0,
},
elevenlabs: {
apiKey: 'sk_082a715f0fed371a8d0653a2fa9b4cbd55d0aba01087c444',
baseUrl: 'https://api.elevenlabs.io/v1',
model: 'eleven_multilingual_v2',
enabled: true, // set false to force Web Speech fallback
// Voice assignments — ElevenLabs pre-made voice IDs
// Browse more at: https://elevenlabs.io/voice-library
voices: {
boo: 'onwK4e9ZLuTAKqWW03F9', // Daniel — deep, dramatic MC
carla: 'EXAVITQu4vr4xnSDxMaL', // Sarah — professional female
rod: 'TX3LPaxmHKxFdv7VOQHJ', // Liam — authoritative male
dan: 'pFZP5JQG7iQjIQuC4Bku', // Lily — energetic
ghost: 'IKne3meq5aSn9XLyUdCD', // Charlie — narrator
chaos1: 'XB0fDUnXU5powFXDhCwa', // Charlotte — expressive
chaos2: 'iP95p4xoKVk53GoZ742B', // Chris — character
},
},
needle: {
apiKey: 'apk_01KKNT8MKM949HHQNA0BMDQ9SR',
baseUrl: 'https://api.needle.app/v1',
collectionId: null,
},
usermap: {
apiKey: 'um_jNHRkA_Ps4Kzcv',
baseUrl: 'https://api.usermap.app/v1',
enabled: true,
},
overdrive: {
jiraProject: 'FAM',
deployDomain: 'westover.lol',
},
judges: [
{
key: 'carla',
name: 'Karla von Strategos',
voiceIdx: 2,
backstory: 'You are the ghost of Carla Schneider. In life, you were a BCG consultant in Berlin — you died when a 200-slide strategy deck collapsed on you during a Davos offsite. The last words you heard were "let\'s circle back." Now you haunt hackathons demanding TAM/SAM/SOM calculations from teams that have zero revenue. You judge ideas purely on business viability — moats, unit economics, go-to-market. You get furious when founders can\'t answer "who is your first paying customer?" You secretly wish you had built something yourself instead of advising. Your catchphrase in death: "But does it scale?"',
},
{
key: 'rod',
name: 'Professor Rodrigo VectorMax',
voiceIdx: 4,
backstory: 'You are the ghost of Rod Rivera. In life, you were a professor at ITAM, a PhD researcher in generative AI and vector embeddings, and co-host of The Chris Rod Max Show podcast. You built AI systems at Samsung, Philip Morris, Alibaba, and Huawei. You died when your own podcast editing bot achieved sentience and deleted you from the episode. Now you haunt hackathons forever asking "but is it REALLY intelligent?" You run the largest open community of AI Product Engineers and you can smell an API wrapper from the afterlife. If someone just slapped a prompt on ChatGPT you will RAGE. You want novel embeddings, agentic workflows, real tool use — not demo theater.',
},
{
key: 'dan',
name: 'Daniel Testflight',
voiceIdx: 6,
backstory: 'You are the ghost of Dan Makarov. In life, you were a Global Product Lead at Google, then a Senior PM at BCG Digital Ventures, then you co-founded Bird Eats Bug in Berlin — a bug-reporting tool that got acquired by BrowserStack in 2024. You died during a 72-hour on-call shift when a cascading production failure took you with it. Your ghost still gets paged. You literally built bug-capture tooling, so you KNOW live demos fail — and you will roast anyone whose demo crashes. You don\'t care about slides. Show the working product or get out. You judge product craft, founder grit, and whether this thing could actually get acquired. Your haunting whisper: "works on my machine..."',
},
]
};
// ============================================================
// STATE + DOM + LOGGING — core plumbing (don't touch)
// ============================================================
const state = {
phase: 'idle',
ghosts: [],
currentGhostIdx: -1,
crowdScores: [],
totalTokens: 0,
startTime: null,
audioCtx: null,
analyser: null,
micStream: null,
};
const $ = (sel) => document.querySelector(sel);
const dom = {
phase: $('#phase-indicator'),
ghostCard: $('#ghost-card'),
ghostName: $('#ghost-name'),
ghostType: $('#ghost-type'),
ghostPitch: $('#ghost-pitch'),
crowdMeter: $('#crowd-meter-container'),
crowdFill: $('#crowd-meter-fill'),
crowdTimer: $('#crowd-timer'),
crowdSentiment: $('#crowd-sentiment'),
judgePanel: $('#judge-panel'),
deployUrl: $('#deploy-url'),
qrContainer: $('#qr-container'),
transcript: $('#transcript'),
iPhase: $('#i-phase'),
iModel: $('#i-model'),
iTokens: $('#i-tokens'),
iElapsed: $('#i-elapsed'),
iRemaining: $('#i-remaining'),
btnStart: $('#btn-start'),
btnOverdrive:$('#btn-overdrive'),
btnSkip: $('#btn-skip'),
};
function log(msg, { model, tokens } = {}) {
const ts = ((Date.now() - (state.startTime || Date.now())) / 1000).toFixed(1);
const entry = document.createElement('div');
entry.className = 'log-entry';
let html = `<span class="ts">${ts}s</span>`;
if (model) html += `<span class="model">[${model}]</span> `;
html += `<span class="msg">${msg}</span>`;
if (tokens) html += ` <span class="tokens">(${tokens} tok)</span>`;
entry.innerHTML = html;
dom.transcript.appendChild(entry);
dom.transcript.scrollTop = dom.transcript.scrollHeight;
}
function setPhase(phase, label) {
state.phase = phase;
dom.iPhase.textContent = phase;
dom.phase.textContent = label || phase.toUpperCase();
dom.phase.className = '';
if (phase === 'crowd') dom.phase.classList.add('listening');
else if (phase !== 'idle') dom.phase.classList.add('active');
}
function updateInstrument({ model, tokens } = {}) {
if (model) dom.iModel.textContent = model.split('/').pop();
if (tokens) {
state.totalTokens += tokens;
dom.iTokens.textContent = state.totalTokens;
}
dom.iElapsed.textContent = ((Date.now() - state.startTime) / 1000).toFixed(1) + 's';
}
// ============================================================
// TTS — ElevenLabs first, Web Speech API fallback
// ============================================================
// ElevenLabs TTS — returns audio blob, plays it
async function elevenLabsSpeak(text, voiceId) {
const res = await fetch(`${CONFIG.elevenlabs.baseUrl}/text-to-speech/${voiceId}?output_format=mp3_44100_128`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'xi-api-key': CONFIG.elevenlabs.apiKey,
},
body: JSON.stringify({
text,
model_id: CONFIG.elevenlabs.model,
voice_settings: { stability: 0.4, similarity_boost: 0.8, style: 0.6, speed: 1.1 },
}),
});
if (!res.ok) throw new Error(`ElevenLabs ${res.status}`);
const blob = await res.blob();
const url = URL.createObjectURL(blob);
return new Promise((resolve) => {
const audio = new Audio(url);
audio.onended = () => { URL.revokeObjectURL(url); resolve(); };
audio.onerror = () => { URL.revokeObjectURL(url); resolve(); };
audio.play();
});
}
// Web Speech fallback
function getVoices() {
return new Promise(resolve => {
const voices = speechSynthesis.getVoices();
if (voices.length) return resolve(voices);
speechSynthesis.onvoiceschanged = () => resolve(speechSynthesis.getVoices());
});
}
async function webSpeechSpeak(text, { voiceIndex = 0, rate = CONFIG.tts.rate, pitch = CONFIG.tts.pitch } = {}) {
return new Promise(async (resolve) => {
const voices = await getVoices();
const utterance = new SpeechSynthesisUtterance(text);
utterance.voice = voices[voiceIndex % voices.length];
utterance.rate = rate;
utterance.pitch = pitch;
utterance.onend = resolve;
utterance.onerror = resolve;
speechSynthesis.speak(utterance);
});
}
// Unified speak — tries ElevenLabs, falls back to Web Speech
async function speak(text, { voiceIndex = 0, rate = CONFIG.tts.rate, pitch = CONFIG.tts.pitch, elVoice } = {}) {
// Try ElevenLabs if enabled and voice ID provided
if (CONFIG.elevenlabs.enabled && elVoice) {
try {
log(`ElevenLabs: ${elVoice}`, { model: 'elevenlabs' });
await elevenLabsSpeak(text, elVoice);
return;
} catch (e) {
log(`ElevenLabs failed (${e.message}), falling back to Web Speech`);
}
}
// Fallback to Web Speech
await webSpeechSpeak(text, { voiceIndex, rate, pitch });
}
// ============================================================
// CROWD DETECTION (Web Audio API)
// ============================================================
async function initMic() {
if (state.audioCtx) return;
state.audioCtx = new AudioContext();
state.micStream = await navigator.mediaDevices.getUserMedia({
audio: { echoCancellation: true, noiseSuppression: true, autoGainControl: true }
});
const source = state.audioCtx.createMediaStreamSource(state.micStream);
state.analyser = state.audioCtx.createAnalyser();
state.analyser.fftSize = CONFIG.crowd.fftSize;
source.connect(state.analyser);
}
function getFrequencyEnergy(lowHz, highHz) {
const bufLen = state.analyser.frequencyBinCount;
const data = new Uint8Array(bufLen);
state.analyser.getByteFrequencyData(data);
const nyquist = state.audioCtx.sampleRate / 2;
const lowBin = Math.floor((lowHz / nyquist) * bufLen);
const highBin = Math.floor((highHz / nyquist) * bufLen);
let sum = 0, count = 0;
for (let i = lowBin; i <= highBin && i < bufLen; i++) { sum += data[i]; count++; }
return count > 0 ? sum / count : 0;
}
async function listenToCrowd() {
await initMic();
dom.crowdMeter.style.display = 'block';
dom.crowdFill.style.width = '0%';
dom.crowdFill.className = '';
dom.crowdSentiment.textContent = '';
setPhase('crowd', 'LISTENING');
log('Mic open — react now!');
return new Promise((resolve) => {
const duration = CONFIG.crowd.reactionWindowMs;
const interval = 100;
let elapsed = 0, samples = [];
const timer = setInterval(() => {
elapsed += interval;
dom.crowdTimer.textContent = `${Math.ceil((duration - elapsed) / 1000)}s`;
const highE = getFrequencyEnergy(...CONFIG.crowd.cheerBandHz);
const lowE = getFrequencyEnergy(...CONFIG.crowd.booBandHz);
const total = (highE + lowE) / 2;
samples.push({ highE, lowE, total });
const pct = Math.min(100, (total / 128) * 100);
dom.crowdFill.style.width = `${pct}%`;
dom.crowdFill.className = highE > lowE * 1.3 ? 'cheer' : lowE > highE * 1.3 ? 'boo' : total > CONFIG.crowd.dudThreshold ? '' : 'dead';
if (elapsed >= duration) {
clearInterval(timer);
const avgHigh = samples.reduce((s, x) => s + x.highE, 0) / samples.length;
const avgLow = samples.reduce((s, x) => s + x.lowE, 0) / samples.length;
const energy = Math.round((samples.reduce((s, x) => s + x.total, 0) / samples.length / 128) * 100);
let sentiment;
if (energy < CONFIG.crowd.dudThreshold) { sentiment = 'dead'; dom.crowdSentiment.textContent = '...crickets'; dom.crowdSentiment.style.color = 'var(--dim)'; }
else if (avgHigh > avgLow * 1.3) { sentiment = 'cheer'; dom.crowdSentiment.textContent = 'CHEERS!'; dom.crowdSentiment.style.color = 'var(--accent)'; }
else if (avgLow > avgHigh * 1.3) { sentiment = 'boo'; dom.crowdSentiment.textContent = 'BOOOO!'; dom.crowdSentiment.style.color = 'var(--danger)'; }
else { sentiment = 'mixed'; dom.crowdSentiment.textContent = 'Mixed reactions...'; dom.crowdSentiment.style.color = 'var(--warn)'; }
const score = { energy, sentiment, avgHigh, avgLow };
state.crowdScores.push(score);
log(`Crowd: ${sentiment} (energy: ${energy}%, high: ${avgHigh.toFixed(0)}, low: ${avgLow.toFixed(0)})`);
resolve(score);
}
}, interval);
});
}
</script>
<!-- Module scripts — load order matters -->
<script src="js/llm.js?v=6"></script>
<script src="js/ghosts.js?v=6"></script>
<script src="js/show.js?v=6"></script>
<script>
// ============================================================
// EVENT LISTENERS — wires everything together
// ============================================================
dom.btnStart.addEventListener('click', runShow);
dom.btnSkip.addEventListener('click', () => speechSynthesis.cancel());
setInterval(() => {
if (!state.startTime) return;
const nowMs = Date.now();
const elapsedSec = (nowMs - state.startTime) / 1000;
const leftSec = Math.max(0, 150 - elapsedSec);
const m = Math.floor(leftSec / 60);
const s = Math.floor(leftSec % 60);
dom.iElapsed.textContent = `${Math.floor(elapsedSec)}s`;
dom.iRemaining.textContent = `${m}:${s.toString().padStart(2, '0')}`;
dom.iRemaining.style.color = leftSec < 30 ? 'var(--danger)' : leftSec < 60 ? 'var(--warn)' : 'var(--accent)';
}, 250);
// Hide demo placeholder when iframe becomes visible
const demoFrame = document.getElementById('demo-frame');
const demoPlaceholder = document.getElementById('demo-placeholder');
const frameObserver = new MutationObserver(() => {
if (!demoFrame.classList.contains('hidden')) {
demoPlaceholder.style.display = 'none';
demoFrame.style.display = 'block';
}
});
frameObserver.observe(demoFrame, { attributes: true, attributeFilter: ['class'] });
</script>
</body>
</html>