Compare commits
13 Commits
DMZTdhruv/
...
harrowmyke
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d370136a11 | ||
bec523ce6b
|
|||
ba62f3bfa2
|
|||
498fa97a86
|
|||
280aa1dcb4 | |||
3299f2dcc6
|
|||
b398f4d025
|
|||
58b47201a6
|
|||
13ae315b7d
|
|||
8e76c91c72
|
|||
74d2378ef4
|
|||
37cf800d8d
|
|||
0e744af73f
|
73
fal_app.py
Normal file
73
fal_app.py
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import datetime
|
||||||
|
from pathlib import Path
|
||||||
|
import threading
|
||||||
|
from audiocraft.data.audio import audio_write
|
||||||
|
import fal
|
||||||
|
from fastapi import Response, status
|
||||||
|
import torch
|
||||||
|
|
||||||
|
DATA_DIR = Path("/data/audio")
|
||||||
|
|
||||||
|
PROMPTS = [
|
||||||
|
"Create a futuristic lo-fi beat that blends modern electronic elements with synthwave influences. Incorporate smooth, atmospheric synths and gentle, relaxing rhythms to evoke a sense of a serene, neon-lit future. Ensure the track is continuous with no background noise or interruptions, maintaining a calm and tranquil atmosphere throughout while adding a touch of retro-futuristic vibes.",
|
||||||
|
"gentle lo-fi beat with a smooth, mellow piano melody in the background. Ensure there are no background noises or interruptions, maintaining a continuous and seamless flow throughout the track. The beat should be relaxing and tranquil, perfect for a calm and reflective atmosphere.",
|
||||||
|
"Create an earthy lo-fi beat that evokes a natural, grounded atmosphere. Incorporate organic sounds like soft percussion, rustling leaves, and gentle acoustic instruments. The track should have a warm, soothing rhythm with a continuous flow and no background noise or interruptions, maintaining a calm and reflective ambiance throughout.",
|
||||||
|
"Create a soothing lo-fi beat featuring gentle, melodic guitar riffs. The guitar should be the focal point, supported by subtle, ambient electronic elements and a smooth, relaxed rhythm. Ensure the track is continuous with no background noise or interruptions, maintaining a warm and mellow atmosphere throughout.",
|
||||||
|
"Create an ambient lo-fi beat with a tranquil and ethereal atmosphere. Use soft, atmospheric pads, gentle melodies, and minimalistic percussion to evoke a sense of calm and serenity. Ensure the track is continuous with no background noise or interruptions, maintaining a soothing and immersive ambiance throughout.",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class InfinifiFalApp(fal.App, keep_alive=300):
|
||||||
|
machine_type = "GPU-A6000"
|
||||||
|
requirements = [
|
||||||
|
"torch==2.1.0",
|
||||||
|
"audiocraft==1.3.0",
|
||||||
|
"torchaudio==2.1.0",
|
||||||
|
"websockets==11.0.3",
|
||||||
|
"numpy==1.26.4",
|
||||||
|
]
|
||||||
|
|
||||||
|
__is_generating = False
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
import torchaudio
|
||||||
|
from audiocraft.models.musicgen import MusicGen
|
||||||
|
|
||||||
|
self.model = MusicGen.get_pretrained("facebook/musicgen-large")
|
||||||
|
self.model.set_generation_params(duration=60)
|
||||||
|
|
||||||
|
@fal.endpoint("/generate")
|
||||||
|
def run(self):
|
||||||
|
if self.__is_generating:
|
||||||
|
return Response(status_code=status.HTTP_409_CONFLICT)
|
||||||
|
threading.Thread(target=self.__generate_audio).start()
|
||||||
|
|
||||||
|
@fal.endpoint("/clips/{index}")
|
||||||
|
def get_clips(self, index):
|
||||||
|
if self.__is_generating:
|
||||||
|
return Response(status_code=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
|
path = DATA_DIR.joinpath(f"{index}")
|
||||||
|
with open(path.with_suffix(".mp3"), "rb") as f:
|
||||||
|
data = f.read()
|
||||||
|
return Response(content=data)
|
||||||
|
|
||||||
|
def __generate_audio(self):
|
||||||
|
self.__is_generating = True
|
||||||
|
|
||||||
|
print(f"[INFO] {datetime.datetime.now()}: generating audio...")
|
||||||
|
|
||||||
|
wav = self.model.generate(PROMPTS)
|
||||||
|
for i, one_wav in enumerate(wav):
|
||||||
|
path = DATA_DIR.joinpath(f"{i}")
|
||||||
|
audio_write(
|
||||||
|
path,
|
||||||
|
one_wav.cpu(),
|
||||||
|
self.model.sample_rate,
|
||||||
|
format="mp3",
|
||||||
|
strategy="loudness",
|
||||||
|
loudness_compressor=True,
|
||||||
|
make_parent_dir=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.__is_generating = False
|
11
generate.py
11
generate.py
@@ -2,22 +2,17 @@ import torchaudio
|
|||||||
from audiocraft.models.musicgen import MusicGen
|
from audiocraft.models.musicgen import MusicGen
|
||||||
from audiocraft.data.audio import audio_write
|
from audiocraft.data.audio import audio_write
|
||||||
|
|
||||||
|
from prompts import PROMPTS
|
||||||
|
|
||||||
MODEL_NAME = "facebook/musicgen-large"
|
MODEL_NAME = "facebook/musicgen-large"
|
||||||
MUSIC_DURATION_SECONDS = 60
|
MUSIC_DURATION_SECONDS = 60
|
||||||
|
|
||||||
model = MusicGen.get_pretrained(MODEL_NAME)
|
model = MusicGen.get_pretrained(MODEL_NAME)
|
||||||
model.set_generation_params(duration=MUSIC_DURATION_SECONDS)
|
model.set_generation_params(duration=MUSIC_DURATION_SECONDS)
|
||||||
descriptions = [
|
|
||||||
"Create a futuristic lo-fi beat that blends modern electronic elements with synthwave influences. Incorporate smooth, atmospheric synths and gentle, relaxing rhythms to evoke a sense of a serene, neon-lit future. Ensure the track is continuous with no background noise or interruptions, maintaining a calm and tranquil atmosphere throughout while adding a touch of retro-futuristic vibes.",
|
|
||||||
"gentle lo-fi beat with a smooth, mellow piano melody in the background. Ensure there are no background noises or interruptions, maintaining a continuous and seamless flow throughout the track. The beat should be relaxing and tranquil, perfect for a calm and reflective atmosphere.",
|
|
||||||
"Create an earthy lo-fi beat that evokes a natural, grounded atmosphere. Incorporate organic sounds like soft percussion, rustling leaves, and gentle acoustic instruments. The track should have a warm, soothing rhythm with a continuous flow and no background noise or interruptions, maintaining a calm and reflective ambiance throughout.",
|
|
||||||
"Create a soothing lo-fi beat featuring gentle, melodic guitar riffs. The guitar should be the focal point, supported by subtle, ambient electronic elements and a smooth, relaxed rhythm. Ensure the track is continuous with no background noise or interruptions, maintaining a warm and mellow atmosphere throughout.",
|
|
||||||
"Create an ambient lo-fi beat with a tranquil and ethereal atmosphere. Use soft, atmospheric pads, gentle melodies, and minimalistic percussion to evoke a sense of calm and serenity. Ensure the track is continuous with no background noise or interruptions, maintaining a soothing and immersive ambiance throughout.",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def generate(offset=0):
|
def generate(offset=0):
|
||||||
wav = model.generate(descriptions)
|
wav = model.generate(PROMPTS)
|
||||||
|
|
||||||
for idx, one_wav in enumerate(wav):
|
for idx, one_wav in enumerate(wav):
|
||||||
# Will save under {idx}.wav, with loudness normalization at -14 db LUFS.
|
# Will save under {idx}.wav, with loudness normalization at -14 db LUFS.
|
||||||
|
@@ -3,6 +3,8 @@ import time
|
|||||||
from audiocraft.models.musicgen import MusicGen
|
from audiocraft.models.musicgen import MusicGen
|
||||||
from audiocraft.data.audio import audio_write
|
from audiocraft.data.audio import audio_write
|
||||||
|
|
||||||
|
from prompts import PROMPTS
|
||||||
|
|
||||||
MODEL_NAME = "facebook/musicgen-large"
|
MODEL_NAME = "facebook/musicgen-large"
|
||||||
MUSIC_DURATION_SECONDS = 60
|
MUSIC_DURATION_SECONDS = 60
|
||||||
|
|
||||||
@@ -10,18 +12,11 @@ print("obtaining model...")
|
|||||||
|
|
||||||
model = MusicGen.get_pretrained(MODEL_NAME)
|
model = MusicGen.get_pretrained(MODEL_NAME)
|
||||||
model.set_generation_params(duration=MUSIC_DURATION_SECONDS)
|
model.set_generation_params(duration=MUSIC_DURATION_SECONDS)
|
||||||
descriptions = [
|
|
||||||
"Create a futuristic lo-fi beat that blends modern electronic elements with synthwave influences. Incorporate smooth, atmospheric synths and gentle, relaxing rhythms to evoke a sense of a serene, neon-lit future. Ensure the track is continuous with no background noise or interruptions, maintaining a calm and tranquil atmosphere throughout while adding a touch of retro-futuristic vibes.",
|
|
||||||
"gentle lo-fi beat with a smooth, mellow piano melody in the background. Ensure there are no background noises or interruptions, maintaining a continuous and seamless flow throughout the track. The beat should be relaxing and tranquil, perfect for a calm and reflective atmosphere.",
|
|
||||||
"Create an earthy lo-fi beat that evokes a natural, grounded atmosphere. Incorporate organic sounds like soft percussion, rustling leaves, and gentle acoustic instruments. The track should have a warm, soothing rhythm with a continuous flow and no background noise or interruptions, maintaining a calm and reflective ambiance throughout.",
|
|
||||||
"Create a soothing lo-fi beat featuring gentle, melodic guitar riffs. The guitar should be the focal point, supported by subtle, ambient electronic elements and a smooth, relaxed rhythm. Ensure the track is continuous with no background noise or interruptions, maintaining a warm and mellow atmosphere throughout.",
|
|
||||||
"Create an ambient lo-fi beat with a tranquil and ethereal atmosphere. Use soft, atmospheric pads, gentle melodies, and minimalistic percussion to evoke a sense of calm and serenity. Ensure the track is continuous with no background noise or interruptions, maintaining a soothing and immersive ambiance throughout.",
|
|
||||||
]
|
|
||||||
|
|
||||||
print("model obtained. generating audio...")
|
print("model obtained. generating audio...")
|
||||||
|
|
||||||
a = time.time()
|
a = time.time()
|
||||||
wav = model.generate(descriptions)
|
wav = model.generate(PROMPTS)
|
||||||
b = time.time()
|
b = time.time()
|
||||||
|
|
||||||
print(f"audio generated. took {b - a} seconds.")
|
print(f"audio generated. took {b - a} seconds.")
|
||||||
|
7
prompts.py
Normal file
7
prompts.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
PROMPTS = [
|
||||||
|
"Create a futuristic lo-fi beat that blends modern electronic elements with synthwave influences. Incorporate smooth, atmospheric synths and gentle, relaxing rhythms to evoke a sense of a serene, neon-lit future. Ensure the track is continuous with no background noise or interruptions, maintaining a calm and tranquil atmosphere throughout while adding a touch of retro-futuristic vibes.",
|
||||||
|
"gentle lo-fi beat with a smooth, mellow piano melody in the background. Ensure there are no background noises or interruptions, maintaining a continuous and seamless flow throughout the track. The beat should be relaxing and tranquil, perfect for a calm and reflective atmosphere.",
|
||||||
|
"Create an earthy lo-fi beat that evokes a natural, grounded atmosphere. Incorporate organic sounds like soft percussion, rustling leaves, and gentle acoustic instruments. The track should have a warm, soothing rhythm with a continuous flow and no background noise or interruptions, maintaining a calm and reflective ambiance throughout.",
|
||||||
|
"Create a soothing lo-fi beat featuring gentle, melodic guitar riffs. The guitar should be the focal point, supported by subtle, ambient electronic elements and a smooth, relaxed rhythm. Ensure the track is continuous with no background noise or interruptions, maintaining a warm and mellow atmosphere throughout.",
|
||||||
|
"Create an ambient lo-fi beat with a tranquil and ethereal atmosphere. Use soft, atmospheric pads, gentle melodies, and minimalistic percussion to evoke a sense of calm and serenity. Ensure the track is continuous with no background noise or interruptions, maintaining a soothing and immersive ambiance throughout.",
|
||||||
|
]
|
92
server.py
92
server.py
@@ -1,9 +1,10 @@
|
|||||||
import threading
|
import threading
|
||||||
import os
|
import os
|
||||||
|
from time import sleep
|
||||||
|
import requests
|
||||||
|
|
||||||
import websocket
|
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
|
from fastapi import FastAPI, WebSocket, WebSocketDisconnect, status
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from logger import log_info, log_warn
|
from logger import log_info, log_warn
|
||||||
@@ -13,33 +14,32 @@ from websocket_connection_manager import WebSocketConnectionManager
|
|||||||
current_index = -1
|
current_index = -1
|
||||||
# the timer that periodically advances the current audio track
|
# the timer that periodically advances the current audio track
|
||||||
t = None
|
t = None
|
||||||
# websocket connection to the inference server
|
inference_url = ""
|
||||||
ws = None
|
api_key = ""
|
||||||
ws_url = ""
|
|
||||||
ws_connection_manager = WebSocketConnectionManager()
|
ws_connection_manager = WebSocketConnectionManager()
|
||||||
active_listeners = set()
|
active_listeners = set()
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
global ws, ws_url
|
global ws, inference_url, api_key
|
||||||
|
|
||||||
ws_url = os.environ.get("INFERENCE_SERVER_WS_URL")
|
inference_url = os.environ.get("INFERENCE_SERVER_URL")
|
||||||
if not ws_url:
|
api_key = os.environ.get("API_KEY")
|
||||||
ws_url = "ws://localhost:8001"
|
|
||||||
|
if not inference_url:
|
||||||
|
inference_url = "http://localhost:8001"
|
||||||
|
|
||||||
advance()
|
advance()
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
if ws:
|
|
||||||
ws.close()
|
|
||||||
if t:
|
if t:
|
||||||
t.cancel()
|
t.cancel()
|
||||||
|
|
||||||
|
|
||||||
def generate_new_audio():
|
def generate_new_audio():
|
||||||
if not ws_url:
|
if not inference_url:
|
||||||
return
|
return
|
||||||
|
|
||||||
global current_index
|
global current_index
|
||||||
@@ -52,31 +52,61 @@ def generate_new_audio():
|
|||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
log_info("generating new audio...")
|
log_info("requesting new audio...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ws = websocket.create_connection(ws_url)
|
requests.post(
|
||||||
|
f"{inference_url}/generate",
|
||||||
ws.send("generate")
|
headers={"Authorization": f"key {api_key}"},
|
||||||
|
)
|
||||||
wavs = []
|
|
||||||
for i in range(5):
|
|
||||||
raw = ws.recv()
|
|
||||||
if isinstance(raw, str):
|
|
||||||
continue
|
|
||||||
wavs.append(raw)
|
|
||||||
|
|
||||||
for i, wav in enumerate(wavs):
|
|
||||||
with open(f"{i + offset}.mp3", "wb") as f:
|
|
||||||
f.write(wav)
|
|
||||||
|
|
||||||
log_info("audio generated.")
|
|
||||||
|
|
||||||
ws.close()
|
|
||||||
except:
|
except:
|
||||||
log_warn(
|
log_warn(
|
||||||
"inference server potentially unreachable. recycling cached audio for now."
|
"inference server potentially unreachable. recycling cached audio for now."
|
||||||
)
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
is_available = False
|
||||||
|
while not is_available:
|
||||||
|
try:
|
||||||
|
res = requests.post(
|
||||||
|
f"{inference_url}/clips/0",
|
||||||
|
stream=True,
|
||||||
|
headers={"Authorization": f"key {api_key}"},
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
log_warn(
|
||||||
|
"inference server potentially unreachable. recycling cached audio for now."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
if res.status_code != status.HTTP_200_OK:
|
||||||
|
print(res.status_code)
|
||||||
|
print("still generating...")
|
||||||
|
sleep(30)
|
||||||
|
continue
|
||||||
|
|
||||||
|
print("inference complete! downloading new clips")
|
||||||
|
|
||||||
|
is_available = True
|
||||||
|
with open(f"{offset}.mp3", "wb") as f:
|
||||||
|
for chunk in res.iter_content(chunk_size=128):
|
||||||
|
f.write(chunk)
|
||||||
|
|
||||||
|
for i in range(4):
|
||||||
|
res = requests.post(
|
||||||
|
f"{inference_url}/clips/{i + 1}",
|
||||||
|
stream=True,
|
||||||
|
headers={"Authorization": f"key {api_key}"},
|
||||||
|
)
|
||||||
|
|
||||||
|
if res.status_code != status.HTTP_200_OK:
|
||||||
|
continue
|
||||||
|
|
||||||
|
with open(f"{i + 1 + offset}.mp3", "wb") as f:
|
||||||
|
for chunk in res.iter_content(chunk_size=128):
|
||||||
|
f.write(chunk)
|
||||||
|
|
||||||
|
log_info("audio generated.")
|
||||||
|
|
||||||
|
|
||||||
def advance():
|
def advance():
|
||||||
|
1
web/images/fal-logo-dark.svg
Normal file
1
web/images/fal-logo-dark.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg width="100%" height="100%" viewBox="0 0 89 32" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M52.308 3.07812H57.8465V4.92428H56.0003V6.77043H54.1541V10.4627H57.8465V12.3089H54.1541V25.232H52.308V27.0781H46.7695V25.232H48.6157V12.3089H46.7695V10.4627H48.6157V6.77043H50.4618V4.92428H52.308V3.07812Z" fill="#cdd6f4"></path><path d="M79.3849 23.3858H81.2311V25.232H83.0772V27.0781H88.6157V25.232H86.7695V23.3858H84.9234V4.92428H79.3849V23.3858Z" fill="#cdd6f4"></path><path d="M57.8465 14.155H59.6926V12.3089H61.5388V10.4627H70.7695V12.3089H74.4618V23.3858H76.308V25.232H78.1541V27.0781H72.6157V25.232H70.7695V23.3858H68.9234V14.155H67.0772V12.3089H65.2311V14.155H63.3849V23.3858H65.2311V25.232H67.0772V27.0781H61.5388V25.232H59.6926V23.3858H57.8465V14.155Z" fill="#cdd6f4"></path><path d="M67.0772 25.232V23.3858H68.9234V25.232H67.0772Z" fill="#cdd6f4"></path><rect opacity="0.22" x="7.38477" y="29.5391" width="2.46154" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.85" x="2.46094" y="19.6914" width="12.3077" height="2.46154" fill="#5F4CD9"></rect><rect x="4.92383" y="17.2305" width="9.84615" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.4" x="7.38477" y="27.0781" width="4.92308" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.7" y="22.1562" width="14.7692" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.5" x="7.38477" y="24.6133" width="7.38462" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.22" x="7.38477" y="12.3086" width="2.46154" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.85" x="2.46094" y="2.46094" width="12.3077" height="2.46154" fill="#5F4CD9"></rect><rect x="4.92383" width="9.84615" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.4" x="7.38477" y="9.84375" width="4.92308" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.7" y="4.92188" width="14.7692" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.5" x="7.38477" y="7.38281" width="7.38462" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.22" x="24.6152" y="29.5391" width="2.46154" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.85" x="19.6914" y="19.6914" width="12.3077" height="2.46154" fill="#5F4CD9"></rect><rect x="22.1543" y="17.2305" width="9.84615" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.4" x="24.6152" y="27.0781" width="4.92308" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.7" x="17.2305" y="22.1562" width="14.7692" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.5" x="24.6152" y="24.6133" width="7.38462" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.22" x="24.6152" y="12.3086" width="2.46154" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.85" x="19.6914" y="2.46094" width="12.3077" height="2.46154" fill="#5F4CD9"></rect><rect x="22.1543" width="9.84615" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.4" x="24.6152" y="9.84375" width="4.92308" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.7" x="17.2305" y="4.92188" width="14.7692" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.5" x="24.6152" y="7.38281" width="7.38462" height="2.46154" fill="#5F4CD9"></rect></svg>
|
After Width: | Height: | Size: 3.1 KiB |
1
web/images/fal-logo-light.svg
Normal file
1
web/images/fal-logo-light.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg width="100%" height="100%" viewBox="0 0 89 32" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M52.308 3.07812H57.8465V4.92428H56.0003V6.77043H54.1541V10.4627H57.8465V12.3089H54.1541V25.232H52.308V27.0781H46.7695V25.232H48.6157V12.3089H46.7695V10.4627H48.6157V6.77043H50.4618V4.92428H52.308V3.07812Z" fill="currentColor"></path><path d="M79.3849 23.3858H81.2311V25.232H83.0772V27.0781H88.6157V25.232H86.7695V23.3858H84.9234V4.92428H79.3849V23.3858Z" fill="currentColor"></path><path d="M57.8465 14.155H59.6926V12.3089H61.5388V10.4627H70.7695V12.3089H74.4618V23.3858H76.308V25.232H78.1541V27.0781H72.6157V25.232H70.7695V23.3858H68.9234V14.155H67.0772V12.3089H65.2311V14.155H63.3849V23.3858H65.2311V25.232H67.0772V27.0781H61.5388V25.232H59.6926V23.3858H57.8465V14.155Z" fill="currentColor"></path><path d="M67.0772 25.232V23.3858H68.9234V25.232H67.0772Z" fill="currentColor"></path><rect opacity="0.22" x="7.38477" y="29.5391" width="2.46154" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.85" x="2.46094" y="19.6914" width="12.3077" height="2.46154" fill="#5F4CD9"></rect><rect x="4.92383" y="17.2305" width="9.84615" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.4" x="7.38477" y="27.0781" width="4.92308" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.7" y="22.1562" width="14.7692" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.5" x="7.38477" y="24.6133" width="7.38462" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.22" x="7.38477" y="12.3086" width="2.46154" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.85" x="2.46094" y="2.46094" width="12.3077" height="2.46154" fill="#5F4CD9"></rect><rect x="4.92383" width="9.84615" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.4" x="7.38477" y="9.84375" width="4.92308" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.7" y="4.92188" width="14.7692" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.5" x="7.38477" y="7.38281" width="7.38462" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.22" x="24.6152" y="29.5391" width="2.46154" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.85" x="19.6914" y="19.6914" width="12.3077" height="2.46154" fill="#5F4CD9"></rect><rect x="22.1543" y="17.2305" width="9.84615" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.4" x="24.6152" y="27.0781" width="4.92308" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.7" x="17.2305" y="22.1562" width="14.7692" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.5" x="24.6152" y="24.6133" width="7.38462" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.22" x="24.6152" y="12.3086" width="2.46154" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.85" x="19.6914" y="2.46094" width="12.3077" height="2.46154" fill="#5F4CD9"></rect><rect x="22.1543" width="9.84615" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.4" x="24.6152" y="9.84375" width="4.92308" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.7" x="17.2305" y="4.92188" width="14.7692" height="2.46154" fill="#5F4CD9"></rect><rect opacity="0.5" x="24.6152" y="7.38281" width="7.38462" height="2.46154" fill="#5F4CD9"></rect></svg>
|
After Width: | Height: | Size: 3.1 KiB |
@@ -31,7 +31,11 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="status-bar">
|
<div class="status-bar">
|
||||||
|
<div id="listener-stats-container">
|
||||||
|
<p id="timer-display-label">joined HH:MM</p>
|
||||||
|
<p class="status-bar-listener-separator">·</p>
|
||||||
<p id="listener-count">0 person tuned in</p>
|
<p id="listener-count">0 person tuned in</p>
|
||||||
|
</div>
|
||||||
<div id="volume-slider-container">
|
<div id="volume-slider-container">
|
||||||
<output id="current-volume-label" for="volume-slider">100%</output>
|
<output id="current-volume-label" for="volume-slider">100%</output>
|
||||||
<input id="volume-slider" type="range" min="0" max="100" step="1" />
|
<input id="volume-slider" type="range" min="0" max="100" step="1" />
|
||||||
@@ -51,7 +55,15 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<span>made by kennethnym <3 · </span>
|
made by <a href="https://kennethnym.com">kennethnym</a> <3 · powered by
|
||||||
|
<a class="fal-link" href="https://fal.ai">
|
||||||
|
<picture>
|
||||||
|
<source srcset="./images/fal-logo-light.svg" media="(prefers-color-scheme: light)" />
|
||||||
|
<source srcset="./images/fal-logo-dark.svg" media="(prefers-color-scheme: dark)" />
|
||||||
|
<img class="fal-logo" fill="none" src="./images/fal-logo-dark.svg">
|
||||||
|
</picture>
|
||||||
|
</a>
|
||||||
|
·
|
||||||
<a target="_blank" rel="noopener noreferrer" href="https://github.com/kennethnym/infinifi">github</a>
|
<a target="_blank" rel="noopener noreferrer" href="https://github.com/kennethnym/infinifi">github</a>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
@@ -11,6 +11,7 @@ const heartImg = document.getElementById("heart");
|
|||||||
const volumeSlider = document.getElementById("volume-slider");
|
const volumeSlider = document.getElementById("volume-slider");
|
||||||
const currentVolumeLabel = document.getElementById("current-volume-label");
|
const currentVolumeLabel = document.getElementById("current-volume-label");
|
||||||
const listenerCountLabel = document.getElementById("listener-count");
|
const listenerCountLabel = document.getElementById("listener-count");
|
||||||
|
const timerDisplayLabel = document.getElementById("timer-display-label");
|
||||||
const notificationContainer = document.getElementById("notification");
|
const notificationContainer = document.getElementById("notification");
|
||||||
const notificationTitle = document.getElementById("notification-title");
|
const notificationTitle = document.getElementById("notification-title");
|
||||||
const notificationBody = document.getElementById("notification-body");
|
const notificationBody = document.getElementById("notification-body");
|
||||||
@@ -31,6 +32,8 @@ let saveVolumeTimeout = null;
|
|||||||
let meowCount = 0;
|
let meowCount = 0;
|
||||||
let ws = connectToWebSocket();
|
let ws = connectToWebSocket();
|
||||||
|
|
||||||
|
const joinedTime = new Date();
|
||||||
|
|
||||||
function playAudio() {
|
function playAudio() {
|
||||||
// add a random query parameter at the end to prevent browser caching
|
// add a random query parameter at the end to prevent browser caching
|
||||||
currentAudio = new Audio(`./current.mp3?t=${Date.now()}`);
|
currentAudio = new Audio(`./current.mp3?t=${Date.now()}`);
|
||||||
@@ -229,6 +232,33 @@ function showNotification(title, content, duration) {
|
|||||||
}, duration);
|
}, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dateToHumanTime(dateVal, includeSeconds = false) {
|
||||||
|
// Extract hours, minutes
|
||||||
|
let hours = dateVal.getHours();
|
||||||
|
let minutes = dateVal.getMinutes();
|
||||||
|
let seconds = dateVal.getSeconds();
|
||||||
|
|
||||||
|
// Add leading zeros if the values are less than 10
|
||||||
|
hours = hours < 10 ? '0' + hours : hours;
|
||||||
|
minutes = minutes < 10 ? '0' + minutes : minutes;
|
||||||
|
seconds = seconds < 10 ? '0' + seconds : seconds;
|
||||||
|
|
||||||
|
// Combine into HH:MM format
|
||||||
|
if (includeSeconds) {
|
||||||
|
return `${hours}:${minutes}:${seconds}`;
|
||||||
|
}
|
||||||
|
return `${hours}:${minutes}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadTimerDisplay() {
|
||||||
|
const now = new Date();
|
||||||
|
timerDisplayLabel.innerText = `${dateToHumanTime(now)} | joined ${dateToHumanTime(joinedTime)}`;
|
||||||
|
|
||||||
|
// seconds until next full minutes
|
||||||
|
// + 1 seconds to ensure non null value
|
||||||
|
setTimeout(loadTimerDisplay, (61 - now.getSeconds()) * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
playBtn.onmousedown = () => {
|
playBtn.onmousedown = () => {
|
||||||
clickAudio.play();
|
clickAudio.play();
|
||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
@@ -300,3 +330,4 @@ loadMeowCount();
|
|||||||
loadInitialVolume();
|
loadInitialVolume();
|
||||||
animateCat();
|
animateCat();
|
||||||
enableSpaceBarControl();
|
enableSpaceBarControl();
|
||||||
|
loadTimerDisplay();
|
@@ -72,9 +72,12 @@ main {
|
|||||||
|
|
||||||
footer {
|
footer {
|
||||||
padding: 1rem 0;
|
padding: 1rem 0;
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
color: var(--text);
|
||||||
|
text-align: center;
|
||||||
|
text-wrap: nowrap;
|
||||||
|
overflow: auto;
|
||||||
}
|
}
|
||||||
@media (min-width: 768px) {
|
@media (min-width: 768px) {
|
||||||
footer {
|
footer {
|
||||||
@@ -82,11 +85,6 @@ footer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
footer > span {
|
|
||||||
color: var(--text);
|
|
||||||
opacity: 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: var(--link-accent);
|
color: var(--link-accent);
|
||||||
}
|
}
|
||||||
@@ -117,18 +115,39 @@ a {
|
|||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
z-index: -10;
|
z-index: -10;
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: space-between;
|
|
||||||
padding: 2rem;
|
padding: 2rem;
|
||||||
z-index: 0;
|
z-index: 0;
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-bar > #listener-count {
|
@media (min-width: 460px){
|
||||||
|
.status-bar{
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-bar #listener-stats-container {
|
||||||
|
padding-right: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-bar #listener-stats-container > * {
|
||||||
|
display: inline-block;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
padding-right: 1rem;
|
padding-right: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 650px) {
|
||||||
|
.status-bar #listener-stats-container > * {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-bar #listener-stats-container .status-bar-listener-separator {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
@@ -378,3 +397,12 @@ aside#notification > #notification-title {
|
|||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fal-logo {
|
||||||
|
vertical-align: bottom;
|
||||||
|
height: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fal-link {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user