Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,40 +6,40 @@ import os
|
|
| 6 |
|
| 7 |
def ghost_ultimate_v7(tu_track, track_ref, intensidad, duda):
|
| 8 |
if tu_track is None:
|
| 9 |
-
return None, "
|
| 10 |
|
| 11 |
try:
|
| 12 |
-
# 1.
|
| 13 |
y, sr = librosa.load(tu_track, duration=30)
|
| 14 |
-
|
| 15 |
-
# Detecci贸n de Nota (Key)
|
| 16 |
chroma = librosa.feature.chroma_cqt(y=y, sr=sr)
|
| 17 |
key_idx = np.argmax(np.mean(chroma, axis=1))
|
| 18 |
-
notas = ["
|
| 19 |
-
|
| 20 |
-
key_detectada = notas[key_idx]
|
| 21 |
|
| 22 |
-
# Energ铆a RMS
|
| 23 |
rms_tu = np.mean(librosa.feature.rms(y=y))
|
| 24 |
-
estilo = "Dark
|
| 25 |
|
| 26 |
# 2. COMPARADOR
|
| 27 |
-
|
| 28 |
if track_ref is not None:
|
| 29 |
y_ref, _ = librosa.load(track_ref, duration=30)
|
| 30 |
rms_ref = np.mean(librosa.feature.rms(y=y_ref))
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
# 3. MASTERING
|
| 35 |
sound = AudioSegment.from_file(tu_track)
|
| 36 |
-
|
| 37 |
-
mastered = sound.apply_gain(
|
| 38 |
-
|
| 39 |
-
mastered.export(
|
| 40 |
|
| 41 |
-
# 4.
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
info_final = f"TONALIDAD: {key_detectada}\nESTILO: {estilo}\n\nCOMPARATIVA: {comparativa}\n\nCONSEJO: En {key_detectada}, el sub debe ser muy preciso
|
|
|
|
| 6 |
|
| 7 |
def ghost_ultimate_v7(tu_track, track_ref, intensidad, duda):
|
| 8 |
if tu_track is None:
|
| 9 |
+
return None, "Sube tu audio.", "Esperando...", "https://images.unsplash.com/photo-1614613535308-eb5fbd3d2c17?q=80&w=500", "Sube audio."
|
| 10 |
|
| 11 |
try:
|
| 12 |
+
# 1. ANALISIS
|
| 13 |
y, sr = librosa.load(tu_track, duration=30)
|
|
|
|
|
|
|
| 14 |
chroma = librosa.feature.chroma_cqt(y=y, sr=sr)
|
| 15 |
key_idx = np.argmax(np.mean(chroma, axis=1))
|
| 16 |
+
notas = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
|
| 17 |
+
key_det = notas[key_idx]
|
|
|
|
| 18 |
|
|
|
|
| 19 |
rms_tu = np.mean(librosa.feature.rms(y=y))
|
| 20 |
+
estilo = "Dark Tech" if rms_tu > 0.12 else "Liquid"
|
| 21 |
|
| 22 |
# 2. COMPARADOR
|
| 23 |
+
comp_txt = "No hay referencia."
|
| 24 |
if track_ref is not None:
|
| 25 |
y_ref, _ = librosa.load(track_ref, duration=30)
|
| 26 |
rms_ref = np.mean(librosa.feature.rms(y=y_ref))
|
| 27 |
+
diff = 20 * np.log10(rms_ref / rms_tu)
|
| 28 |
+
comp_txt = "Diferencia de volumen: " + str(round(diff, 1)) + " dB"
|
| 29 |
|
| 30 |
# 3. MASTERING
|
| 31 |
sound = AudioSegment.from_file(tu_track)
|
| 32 |
+
gain = (intensidad / 10) - 5
|
| 33 |
+
mastered = sound.apply_gain(gain)
|
| 34 |
+
out = "master_v7.wav"
|
| 35 |
+
mastered.export(out, format="wav")
|
| 36 |
|
| 37 |
+
# 4. INFORME (Usando suma de textos para evitar errores de llaves {})
|
| 38 |
+
info = "TONALIDAD: " + key_det + "\n"
|
| 39 |
+
info += "ESTILO: " + estilo + "\n\n"
|
| 40 |
+
info += "COMPARATIVA: " + comp_txt + "\n\n"
|
| 41 |
+
info += "CONSEJO: En " + key_det + " el sub debe ser afinado."
|
| 42 |
+
|
| 43 |
+
prompt = "Cyberpunk DnB Art, Neon, " + estilo + " vibes, " + key_det + " mood."
|
| 44 |
|
| 45 |
+
return out, info, key_det + " | " + estilo
|
|
|