-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheos.html
More file actions
606 lines (525 loc) · 22 KB
/
eos.html
File metadata and controls
606 lines (525 loc) · 22 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Echoes of Silence</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🔔</text></svg>">
<meta name="description"
content="A calm, minimal web app for creating an endless, layered soundscape with Tibetan singing bowls.">
<style>
/* --- Reset & Base Styles --- */
:root {
--bg-deep-blue: #041735;
--bg-mid-blue: #0A2A4A;
--accent-gold: #C9A84D;
--text-light: #EDE8DC;
--shadow-color: rgba(0, 0, 0, 0.25);
--font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
--font-serif-display: 'Lora', 'Georgia', serif;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html,
body {
height: 100vh;
/* Use viewport height */
overflow: hidden;
/* Prevent scrolling on the body */
}
body {
background-color: var(--bg-deep-blue);
color: var(--text-light);
font-family: var(--font-sans);
display: flex;
justify-content: center;
align-items: center;
padding: 1rem;
line-height: 1.5;
}
/* --- New Content Wrapper --- */
.content-wrapper {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
max-width: 450px;
}
/* --- Main App Container & Layout --- */
.app-container {
width: 100%;
max-height: 95vh;
background-color: var(--bg-mid-blue);
border-radius: 2rem;
padding: 1.5rem;
box-shadow: 0 10px 30px var(--shadow-color);
display: flex;
flex-direction: column;
gap: 1.5rem;
/* Adjusted gap */
transition: all 0.3s ease;
}
@media (min-width: 640px) {
.app-container {
padding: 2rem;
}
}
/* --- Header --- */
.header {
text-align: center;
}
.header-image {
width: 280px;
height: 280px;
border-radius: 1rem;
object-fit: cover;
border: 0px solid var(--accent-gold);
margin-bottom: 1rem;
box-shadow: 0 5px 15px var(--shadow-color);
}
.title-container {
display: flex;
align-items: center;
justify-content: center;
gap: 0.75rem;
}
.header h1 {
font-family: var(--font-serif-display);
color: var(--accent-gold);
font-size: 1.6rem;
font-weight: 500;
letter-spacing: 0.5px;
margin-bottom: 0.25rem;
}
.info-button {
background: none;
border: none;
width: 26px;
/* Sized to be similar to the old emoji */
height: 26px;
cursor: pointer;
color: var(--accent-gold);
padding: 0;
line-height: 1;
opacity: 0.8;
transition: opacity 0.2s ease;
}
.info-button:hover {
opacity: 1;
}
.info-button svg {
width: 100%;
height: 100%;
}
.header p {
font-size: 0.9rem;
opacity: 0.8;
}
/* --- Controls --- */
.controls {
display: flex;
justify-content: center;
margin-top: 1rem;
/* Added margin for spacing */
}
.control-button {
background-color: var(--accent-gold);
color: var(--bg-deep-blue);
border: none;
border-radius: 50px;
padding: 0.9rem 2rem;
/* Increased padding */
font-size: 1.1rem;
/* Increased font size */
font-weight: 600;
cursor: pointer;
transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
width: 200px;
/* Set a fixed width */
text-align: center;
}
.control-button:disabled {
cursor: not-allowed;
opacity: 0.7;
}
.control-button:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 4px 15px rgba(201, 168, 77, 0.3);
}
.control-button.active {
background-color: #a88d3e;
/* Darker gold when active */
}
/* --- Information Overlay --- */
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
display: none;
justify-content: center;
align-items: center;
padding: 1rem;
z-index: 1000;
backdrop-filter: blur(5px);
}
.overlay-content {
background-color: var(--bg-mid-blue);
padding: 2.5rem 2rem 2rem 2rem;
border-radius: 1rem;
max-width: 450px;
width: 100%;
position: relative;
box-shadow: 0 5px 25px var(--shadow-color);
border: 1px solid var(--accent-gold);
text-align: center;
}
.overlay-content h2 {
font-family: var(--font-serif-display);
color: var(--accent-gold);
margin-bottom: 1rem;
font-size: 1.5rem;
}
.overlay-content p {
opacity: 0.9;
line-height: 1.7;
}
.close-button {
position: absolute;
top: 1rem;
right: 1rem;
background: none;
border: none;
font-size: 2rem;
font-weight: bold;
color: var(--text-light);
cursor: pointer;
line-height: 1;
opacity: 0.7;
transition: opacity 0.2s ease;
}
.close-button:hover {
opacity: 1;
}
/* --- Now Playing Element --- */
.now-playing-text {
text-align: center;
margin-top: 1.5rem;
font-size: 0.9rem;
opacity: 0.1;
min-height: 1.5em;
/* Prevent layout shift */
transition: opacity 0.3s ease-in-out;
}
/* --- Footer (example if needed inside app-container) --- */
.site-footer {
text-align: center;
margin-top: auto;
/* Pushes footer to the bottom of the flex container */
padding-top: 1rem;
font-size: 0.8rem;
color: var(--text-light);
opacity: 0.6;
}
.site-footer a {
color: var(--accent-gold);
text-decoration: none;
font-weight: 500;
}
.site-footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="content-wrapper">
<main class="app-container" aria-live="polite">
<header class="header">
<img src="tb.jpg" alt="An ornate brass Tibetan singing bowl" class="header-image">
<div class="title-container">
<h1>Echoes of Silence</h1>
</div>
<div class="subtitle-container">
<p>Sound Meditation</p>
<br>
<button id="infoBtn" class="info-button" aria-label="About">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"
aria-hidden="true">
<path
d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z" />
</svg>
</button>
</div>
</header>
<div class="controls">
<button id="toggleMeditationBtn" class="control-button">Start Meditation</button>
</div>
</main>
<p id="nowPlaying" class="now-playing-text"></p>
</div>
<div id="infoOverlay" class="overlay">
<div class="overlay-content">
<button id="closeOverlayBtn" class="close-button" aria-label="Close">×</button>
<h2>About</h2>
<p>
'Echoes of Silence' lets you meditate with the magic sounds of authentic Tibetan singing bowls. Press
<b>Start</b> to create an endless, evolving soundscape—randomized in a unique sequence and unique timing
every time—when you are done, press <b>Stop</b> to end.
<br><br>
The sounds are adapted from varied recordings by
<a href="https://kasper.bandcamp.com/album/singing-bowls" target="_blank" rel="noopener noreferrer"
style="color:white; text-decoration:underline;">
Kasper</a> and include over 15 different tones. Koshi chimes from <a href="https://freesound.org" target="_blank" rel="noopener noreferrer"
style="color:white; text-decoration:underline;"> FreeSound</a>.
<br><br>
For the best experience, listen with headphones at low volume for at least five minutes while focusing
on your breath. This app will always be free, ad-free, and dedicated solely to well-being 🙏.
</p>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
// --- DOM Elements ---
const toggleBtn = document.getElementById('toggleMeditationBtn');
const infoBtn = document.getElementById('infoBtn');
const infoOverlay = document.getElementById('infoOverlay');
const closeOverlayBtn = document.getElementById('closeOverlayBtn');
const nowPlayingEl = document.getElementById('nowPlaying');
// --- App State & Audio Config ---
const BOWL_SOUNDS = [
'tibetanbowls/110_a.mp3', 'tibetanbowls/130_c.mp3', 'tibetanbowls/147_d.mp3',
'tibetanbowls/164_e.mp3', 'tibetanbowls/174_f.mp3', 'tibetanbowls/198_g.mp3',
'tibetanbowls/220_a.mp3', 'tibetanbowls/264_c.mp3', 'tibetanbowls/50_g.mp3',
'tibetanbowls/50_g.mp3', 'tibetanbowls/50_g.mp3', 'tibetanbowls/64_c.mp3',
'tibetanbowls/75_d.mp3', 'tibetanbowls/82_e.mp3', 'tibetanbowls/87_f.mp3',
'tibetanbowls/98_g.mp3', 'tibetanbowls/bell_f.mp3', 'tibetanbowls/bell_a.mp3',
'tibetanbowls/bell_g.mp3', 'tibetanbowls/bell_e.mp3', 'tibetanbowls/drone_c.mp3',
'tibetanbowls/drone_a.mp3', 'tibetanbowls/drone_f.mp3', 'tibetanbowls/drone_c.mp3',
'tibetanbowls/drone_f.mp3'
];
const CHIME_SOUNDS = [
'tibetanbowls/kcam1.mp3', 'tibetanbowls/kcam2.mp3'
];
let isPlaying = false;
let soundScheduler = null;
let chimeScheduler = null;
let wakeLock = null; // To hold the WakeLockSentinel object
// --- Web Audio API specific variables ---
let audioContext = null;
let compressor = null; // NEW: To equalize volume
const audioBuffers = {};
let activeSources = [];
let soundsLoaded = false;
// --- Wake Lock Functions ---
const requestWakeLock = async () => {
if ('wakeLock' in navigator) {
try {
wakeLock = await navigator.wakeLock.request('screen');
wakeLock.addEventListener('release', () => {
console.log('Screen Wake Lock was released by the system.');
});
console.log('Screen Wake Lock is active.');
} catch (err) {
console.error(`Wake Lock request failed: ${err.name}, ${err.message}`);
}
} else {
console.warn('Screen Wake Lock API is not supported on this browser.');
}
};
const releaseWakeLock = async () => {
if (wakeLock !== null) {
try {
await wakeLock.release();
wakeLock = null;
console.log('Screen Wake Lock released.');
} catch (err) {
console.error(`Wake Lock release failed: ${err.name}, ${err.message}`);
}
}
};
// Re-acquire the lock if the page becomes visible again (e.g., user switches tabs and comes back)
const handleVisibilityChange = async () => {
if (isPlaying && document.visibilityState === 'visible') {
await requestWakeLock();
}
};
// --- Event Listeners ---
toggleBtn.addEventListener('click', toggleMeditation);
infoBtn.addEventListener('click', () => infoOverlay.style.display = 'flex');
closeOverlayBtn.addEventListener('click', () => infoOverlay.style.display = 'none');
infoOverlay.addEventListener('click', (e) => {
infoOverlay.style.display = 'none';
});
document.addEventListener('visibilitychange', handleVisibilityChange);
// --- Core Functions ---
async function toggleMeditation() {
isPlaying = !isPlaying;
if (isPlaying) {
// Create AudioContext on first user interaction
if (!audioContext) {
audioContext = new(window.AudioContext || window.webkitAudioContext)();
// NEW: Create and configure the compressor for volume equalization
compressor = audioContext.createDynamicsCompressor();
// Connect the compressor to the final output (speakers)
compressor.connect(audioContext.destination);
}
await startSoundscape();
} else {
await stopSoundscape();
}
updateButtonUI();
}
async function startSoundscape() {
console.log("Starting soundscape...");
await requestWakeLock(); // Request the wake lock
if (!soundsLoaded) {
toggleBtn.textContent = 'Loading...';
toggleBtn.disabled = true;
await preloadAllSounds();
soundsLoaded = true;
toggleBtn.disabled = false;
updateButtonUI(); // Update text back to 'Stop'
}
playRandomBowl(); // Play the first sound immediately
scheduleNextBowl();
scheduleNextChime();
}
async function stopSoundscape() {
console.log("Stopping soundscape...");
await releaseWakeLock(); // Release the wake lock
clearTimeout(soundScheduler);
clearTimeout(chimeScheduler);
soundScheduler = null;
chimeScheduler = null;
toggleBtn.disabled = true;
const fadeDuration = 4; // 4 seconds
// Fade out all currently playing sounds using Web Audio API
if (audioContext) {
activeSources.forEach(({ gainNode }) => {
gainNode.gain.linearRampToValueAtTime(0, audioContext.currentTime + fadeDuration);
});
}
setTimeout(() => {
window.location.reload();
}, (fadeDuration * 1000) + 500); // Add a buffer
}
function scheduleNextBowl() {
if (!isPlaying) return;
const delay = Math.random() * 10000 + 10000; // 10-20 seconds
console.log(`[${new Date().toLocaleTimeString()}] Next bowl sound in ${(delay / 1000).toFixed(2)}s`);
soundScheduler = setTimeout(() => {
playRandomBowl();
scheduleNextBowl();
}, delay);
}
function scheduleNextChime() {
if (!isPlaying) return;
// Chimes are set to play once every 3 minutes
const delay = 180000; // 3 minutes in milliseconds
console.log(`[${new Date().toLocaleTimeString()}] Next chime in ${(delay / 1000).toFixed(2)}s`);
chimeScheduler = setTimeout(() => {
playRandomChime();
scheduleNextChime();
}, delay);
}
function playSound(soundSrc, type) {
if (!isPlaying || !audioContext) return;
const buffer = audioBuffers[soundSrc];
if (!buffer) {
console.error(`Buffer for ${soundSrc} not found.`);
return;
}
console.log(`[${new Date().toLocaleTimeString()}] Playing [${type}]: ${soundSrc}`);
// Only update the UI for the main bowl sounds
if (type === 'bowl') {
const fileName = soundSrc.split('/').pop().replace('.mp3', '');
nowPlayingEl.textContent = fileName;
}
// Setup Web Audio nodes
const source = audioContext.createBufferSource();
const gainNode = audioContext.createGain();
source.buffer = buffer;
// Make chimes slightly quieter
gainNode.gain.value = (type === 'chime') ? 0.6 : 0.8;
source.connect(gainNode);
// MODIFIED: Connect the gain node to the compressor instead of directly to the destination
gainNode.connect(compressor);
source.start(0);
// Track the source along with its type
const sourceData = { source, gainNode, type };
activeSources.push(sourceData);
// Clean up the source from the array once it has finished
source.onended = () => {
activeSources = activeSources.filter(s => s !== sourceData);
// If no more bowls are playing, clear the text
if (!activeSources.some(s => s.type === 'bowl')) {
nowPlayingEl.textContent = '';
}
};
}
function playRandomBowl() {
if (!isPlaying || BOWL_SOUNDS.length === 0) return;
const soundIndex = Math.floor(Math.random() * BOWL_SOUNDS.length);
const soundSrc = BOWL_SOUNDS[soundIndex];
playSound(soundSrc, 'bowl');
}
function playRandomChime() {
if (!isPlaying || CHIME_SOUNDS.length === 0) return;
// CRITICAL CHECK: Only play chime if a bowl is currently active
const isBowlPlaying = activeSources.some(s => s.type === 'bowl');
if (isBowlPlaying) {
const soundIndex = Math.floor(Math.random() * CHIME_SOUNDS.length);
const soundSrc = CHIME_SOUNDS[soundIndex];
playSound(soundSrc, 'chime');
} else {
console.log(`[${new Date().toLocaleTimeString()}] Skipping chime: No bowl sound is currently playing.`);
}
}
// --- Web Audio API Helper Functions ---
async function loadSound(url) {
if (audioBuffers[url]) return audioBuffers[url]; // Return cached buffer
try {
const response = await fetch(url);
const arrayBuffer = await response.arrayBuffer();
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
audioBuffers[url] = audioBuffer;
return audioBuffer;
} catch (error) {
console.error(`Error loading sound: ${url}`, error);
}
}
async function preloadAllSounds() {
console.log("Preloading all sounds...");
const allSounds = [...BOWL_SOUNDS, ...CHIME_SOUNDS];
const uniqueSounds = [...new Set(allSounds)];
const promises = uniqueSounds.map(url => loadSound(url));
await Promise.all(promises);
console.log("All sounds preloaded.");
}
function updateButtonUI() {
if (isPlaying) {
toggleBtn.textContent = 'Stop Meditation';
toggleBtn.classList.add('active');
toggleBtn.setAttribute('aria-label', 'Stop the meditation soundscape');
} else {
toggleBtn.textContent = 'Start Meditation';
toggleBtn.classList.remove('active');
toggleBtn.setAttribute('aria-label', 'Start the meditation soundscape');
nowPlayingEl.textContent = '';
}
}
});
</script>
</body>
</html>