Lukeetah commited on
Commit
1ecbe3f
verified
1 Parent(s): f05043d

Update helpers.py

Browse files
Files changed (1) hide show
  1. helpers.py +111 -48
helpers.py CHANGED
@@ -1,12 +1,21 @@
1
  from PIL import Image, ImageDraw, ImageFilter, ImageFont
2
  import hashlib
3
  import numpy as np
4
- from pydub import AudioSegment
5
- from gtts import gTTS
6
  from io import BytesIO
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  def analyze_voice_energy(audio_path):
9
- # (Esta funci贸n se mantiene igual que la v4.0)
10
  if not audio_path: return {"peak_dbfs": 0.5, "duration_s": 1.0}
11
  try:
12
  sound = AudioSegment.from_file(audio_path)
@@ -15,71 +24,125 @@ def analyze_voice_energy(audio_path):
15
  return {"peak_dbfs": max(0.1, min(1.0, peak_normalized)), "duration_s": max(1.0, min(30.0, duration_s))}
16
  except Exception: return {"peak_dbfs": 0.5, "duration_s": 1.0}
17
 
18
- def generate_sonic_glyph(text_seed, sonic_seed, mode, size=512):
19
- # (Similar a la v4.0, pero ahora el 'modo' cambia el color)
20
- palette = {
21
- "Crisol": (180, 50, 255), # P煤rpura para transmutaci贸n
22
- "Forja": (255, 180, 50) # Naranja/Dorado para creaci贸n
23
- }[mode]
24
-
25
  full_seed_str = f"{text_seed}-{sonic_seed['peak_dbfs']}-{sonic_seed['duration_s']}"
26
  hash_object = hashlib.sha256(full_seed_str.encode('utf-8'))
27
  seed = [int(c, 16) for c in hash_object.hexdigest()]
28
-
29
  img = Image.new('RGB', (size, size), (5, 2, 8))
30
  draw = ImageDraw.Draw(img)
31
  center_x, center_y = size // 2, size // 2
32
-
33
  num_lines = int(10 + (seed[0] % 10) * sonic_seed['duration_s'] / 5)
34
  base_radius = size * 0.1 + size * 0.3 * sonic_seed['peak_dbfs']
35
 
36
  for i in range(num_lines):
37
- # (L贸gica de dibujo similar a la anterior)
38
  s_idx = (i * 4) % len(seed)
39
  angle = (sum(seed[s_idx:s_idx+4]) / 60) * 2 * np.pi * (-1 if i % 2 else 1)
40
  radius = base_radius * (seed[i % len(seed)] / 15)
41
  point1 = (center_x + radius * np.cos(angle), center_y + radius * np.sin(angle))
42
  point2 = (center_x + radius * np.cos(angle + np.pi/2), center_y + radius * np.sin(angle + np.pi/2))
43
  draw.line([point1, point2], fill=palette, width=int(1 + sonic_seed['peak_dbfs'] * 2))
44
-
45
  glow = img.filter(ImageFilter.GaussianBlur(radius=size*0.03))
46
  return Image.alpha_composite(img.convert('RGBA'), glow.convert('RGBA')).convert('RGB')
47
 
48
- def generate_protocol_audio(enunciado, mode, duration_s=180):
49
- """
50
- Genera el Subliminal S贸nico.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  """
52
- # 1. Generar la pista base de ondas cerebrales
53
- freq, vol = (100, -22) if mode == "Crisol" else (150, -24) # Theta o Alpha
54
- binaural_beat = AudioSegment.silent(duration=duration_s * 1000, frame_rate=44100)
55
- beat = AudioSegment.sine(freq, duration=duration_s * 1000).fade_in(2000).fade_out(5000)
56
- binaural_beat = binaural_beat.overlay(beat, position=0)
57
 
58
- # 2. Generar el habla subliminal con gTTS
59
- try:
60
- tts = gTTS(text=enunciado, lang='es', slow=True)
61
- speech_fp = BytesIO()
62
- tts.write_to_fp(speech_fp)
63
- speech_fp.seek(0)
64
- subliminal_speech = AudioSegment.from_file(speech_fp, format="mp3")
65
-
66
- # 3. Preparar la pista subliminal
67
- # Bajar mucho el volumen y repetir hasta llenar la duraci贸n
68
- subliminal_track = subliminal_speech - 26 # Volumen sub-audible
69
- final_subliminal = AudioSegment.silent(duration=duration_s * 1000)
 
 
 
 
 
 
70
 
71
- cursor = 0
72
- while cursor < len(final_subliminal):
73
- final_subliminal = final_subliminal.overlay(subliminal_track, position=cursor)
74
- cursor += len(subliminal_track) + 2000 # A帽adir 2s de silencio entre repeticiones
75
-
76
- # 4. Combinar la base y el subliminal
77
- final_audio = binaural_beat.overlay(final_subliminal)
78
- except Exception as e:
79
- print(f"Error generando subliminal, se usar谩 solo la base. Raz贸n: {e}")
80
- final_audio = binaural_beat
81
-
82
- # 5. Exportar y devolver la ruta
83
- filename = "Protocolo_Sonico.wav"
84
- final_audio.export(filename, format="wav")
85
  return filename
 
1
  from PIL import Image, ImageDraw, ImageFilter, ImageFont
2
  import hashlib
3
  import numpy as np
 
 
4
  from io import BytesIO
5
+ from reportlab.pdfgen import canvas
6
+ from reportlab.lib.pagesizes import letter
7
+ from reportlab.lib.units import inch
8
+ from reportlab.lib.styles import getSampleStyleSheet
9
+ from reportlab.platypus import Paragraph
10
+ from reportlab.lib.colors import Color
11
+
12
+ # --- COLORES Y ESTILOS ---
13
+ PRIMARY_COLOR = Color(0.76, 0.61, 1.0) # #C39CFF
14
+ BACKGROUND_COLOR = Color(0.04, 0.02, 0.06) # #0A050F
15
+ TEXT_COLOR = Color(0.92, 0.89, 1.0) # #EAE2FF
16
 
17
  def analyze_voice_energy(audio_path):
18
+ from pydub import AudioSegment
19
  if not audio_path: return {"peak_dbfs": 0.5, "duration_s": 1.0}
20
  try:
21
  sound = AudioSegment.from_file(audio_path)
 
24
  return {"peak_dbfs": max(0.1, min(1.0, peak_normalized)), "duration_s": max(1.0, min(30.0, duration_s))}
25
  except Exception: return {"peak_dbfs": 0.5, "duration_s": 1.0}
26
 
27
+ def generate_sonic_glyph(text_seed, sonic_seed, mode, size=1024):
28
+ palette = {"Crisol": (180, 50, 255), "Forja": (255, 180, 50)}[mode]
 
 
 
 
 
29
  full_seed_str = f"{text_seed}-{sonic_seed['peak_dbfs']}-{sonic_seed['duration_s']}"
30
  hash_object = hashlib.sha256(full_seed_str.encode('utf-8'))
31
  seed = [int(c, 16) for c in hash_object.hexdigest()]
 
32
  img = Image.new('RGB', (size, size), (5, 2, 8))
33
  draw = ImageDraw.Draw(img)
34
  center_x, center_y = size // 2, size // 2
 
35
  num_lines = int(10 + (seed[0] % 10) * sonic_seed['duration_s'] / 5)
36
  base_radius = size * 0.1 + size * 0.3 * sonic_seed['peak_dbfs']
37
 
38
  for i in range(num_lines):
 
39
  s_idx = (i * 4) % len(seed)
40
  angle = (sum(seed[s_idx:s_idx+4]) / 60) * 2 * np.pi * (-1 if i % 2 else 1)
41
  radius = base_radius * (seed[i % len(seed)] / 15)
42
  point1 = (center_x + radius * np.cos(angle), center_y + radius * np.sin(angle))
43
  point2 = (center_x + radius * np.cos(angle + np.pi/2), center_y + radius * np.sin(angle + np.pi/2))
44
  draw.line([point1, point2], fill=palette, width=int(1 + sonic_seed['peak_dbfs'] * 2))
 
45
  glow = img.filter(ImageFilter.GaussianBlur(radius=size*0.03))
46
  return Image.alpha_composite(img.convert('RGBA'), glow.convert('RGBA')).convert('RGB')
47
 
48
+ def create_protocol_dossier(glyph_img, protocol, sonic_energy, mode):
49
+ filename = "Protocolo_Infinito.pdf"
50
+ c = canvas.Canvas(filename, pagesize=letter)
51
+ width, height = letter
52
+
53
+ # --- Estilos de P谩rrafo ---
54
+ styles = getSampleStyleSheet()
55
+ style_body = styles['BodyText']
56
+ style_body.fontName = 'Helvetica'
57
+ style_body.fontSize = 12
58
+ style_body.textColor = TEXT_COLOR
59
+ style_body.leading = 16
60
+
61
+ style_heading = styles['h2']
62
+ style_heading.fontName = 'Helvetica-Bold'
63
+ style_heading.fontSize = 18
64
+ style_heading.textColor = PRIMARY_COLOR
65
+
66
+ def draw_page_template(page_num, title):
67
+ c.saveState()
68
+ c.setFillColor(BACKGROUND_COLOR)
69
+ c.rect(0, 0, width, height, fill=1)
70
+ c.setStrokeColor(PRIMARY_COLOR)
71
+ c.setLineWidth(2)
72
+ c.line(0.5*inch, height - 0.5*inch, width - 0.5*inch, height - 0.5*inch)
73
+ c.line(0.5*inch, 0.5*inch, width - 0.5*inch, 0.5*inch)
74
+ c.setFillColor(PRIMARY_COLOR)
75
+ c.setFont('Helvetica-Bold', 24)
76
+ c.drawCentredString(width / 2, height - 1*inch, f"Protocolo: {protocol['titulo']}")
77
+ c.setFont('Helvetica', 10)
78
+ c.drawString(0.5*inch, 0.6*inch, f"Crisol Infinito // Motor de la Noosfera // P谩gina {page_num}")
79
+ c.drawRightString(width - 0.5*inch, 0.6*inch, title)
80
+ c.restoreState()
81
+
82
+ # --- P脕GINA 1: Glifo y Enunciado ---
83
+ draw_page_template(1, "Firma Energ茅tica y C贸digo Fuente")
84
+ temp_glyph_path = "temp_glyph.png"
85
+ glyph_img.save(temp_glyph_path)
86
+ c.drawImage(temp_glyph_path, width/2 - 2*inch, height - 5.5*inch, width=4*inch, height=4*inch)
87
+
88
+ p = Paragraph("El Enunciado (C贸digo Fuente PNL)", style_heading)
89
+ p.wrapOn(c, width - 2*inch, 1*inch)
90
+ p.drawOn(c, 1*inch, height - 6.5*inch)
91
+ p = Paragraph(protocol['enunciado'], style_body)
92
+ p.wrapOn(c, width - 2*inch, 2*inch)
93
+ p.drawOn(c, 1*inch, height - 7.5*inch)
94
+ c.showPage()
95
+
96
+ # --- P脕GINA 2: Circuito Vibracional ---
97
+ draw_page_template(2, "Manual de Operaci贸n Diaria")
98
+ p = Paragraph("El Circuito Vibracional (Kybalion)", style_heading)
99
+ p.wrapOn(c, width - 2*inch, 1*inch)
100
+ p.drawOn(c, 1*inch, height - 2*inch)
101
+ p = Paragraph(protocol['circuito'].replace("\n", "<br/>"), style_body)
102
+ p.wrapOn(c, width - 2*inch, 8*inch)
103
+ p.drawOn(c, 1*inch, height - 8*inch)
104
+ c.showPage()
105
+
106
+ # --- P脕GINA 3: Directiva On铆rica y Espectro S贸nico ---
107
+ draw_page_template(3, "Programaci贸n Subconsciente")
108
+ p = Paragraph("La Directiva On铆rica", style_heading)
109
+ p.wrapOn(c, width - 2*inch, 1*inch)
110
+ p.drawOn(c, 1*inch, height - 2*inch)
111
+ p = Paragraph(protocol['directiva'], style_body)
112
+ p.wrapOn(c, width - 2*inch, 2*inch)
113
+ p.drawOn(c, 1*inch, height - 3*inch)
114
+
115
+ p = Paragraph("An谩lisis del Espectro S贸nico", style_heading)
116
+ p.wrapOn(c, width - 2*inch, 1*inch)
117
+ p.drawOn(c, 1*inch, height - 5*inch)
118
+
119
+ sonic_text = f"""
120
+ Intensidad de la Traza (Pico Normalizado): {sonic_energy['peak_dbfs']:.2f} / 1.0<br/>
121
+ Duraci贸n del Campo (Segundos): {sonic_energy['duration_s']:.2f} s<br/><br/>
122
+ <b>Interpretaci贸n:</b> La <i>intensidad</i> de tu voz modula el brillo y la complejidad del Glifo. La <i>duraci贸n</i> modula su escala y n煤mero de componentes. Esta firma es un reflejo directo de la energ铆a que impartiste en la operaci贸n.
123
  """
124
+ p = Paragraph(sonic_text, style_body)
125
+ p.wrapOn(c, width - 2*inch, 4*inch)
126
+ p.drawOn(c, 1*inch, height - 7*inch)
127
+ c.showPage()
 
128
 
129
+ # --- P脕GINA 4: Bit谩cora del Operador ---
130
+ draw_page_template(4, "Registro de Sincronizaci贸n")
131
+ p = Paragraph("Bit谩cora del Operador", style_heading)
132
+ p.wrapOn(c, width - 2*inch, 1*inch)
133
+ p.drawOn(c, 1*inch, height - 2*inch)
134
+ p = Paragraph("Usa este espacio para registrar observaciones, sue帽os, sincronicidades y resultados derivados de la aplicaci贸n de este protocolo.", style_body)
135
+ p.wrapOn(c, width - 2*inch, 2*inch)
136
+ p.drawOn(c, 1*inch, height - 3*inch)
137
+
138
+ c.setStrokeColorRGB(0.5, 0.5, 0.5)
139
+ c.setDash(3, 3)
140
+ for y in range(int(height - 4*inch), int(1*inch), int(-0.25*inch)):
141
+ c.line(1*inch, y, width - 1*inch, y)
142
+ c.save()
143
+
144
+ import os
145
+ if os.path.exists("temp_glyph.png"):
146
+ os.remove("temp_glyph.png")
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  return filename