Spaces:
Sleeping
Sleeping
feat: update AudioUploadService
Browse files
src/expon/presentation/application/internal/commandservices/audio_upload_service.py
CHANGED
@@ -24,28 +24,33 @@ class AudioUploadService:
|
|
24 |
self.repository = repository
|
25 |
|
26 |
def upload_and_analyze(self, file: UploadFile, user_id: UUID = UUID("00000000-0000-0000-0000-000000000000")):
|
27 |
-
# 1.
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
full_path = os.path.join(self.storage_service.base_path, filename)
|
30 |
-
|
31 |
-
#
|
32 |
result = self.transcription_service.transcribe(full_path)
|
33 |
-
|
34 |
transcript = result["text"]
|
35 |
confidence = result.get("confidence", 1.0)
|
36 |
-
|
37 |
-
#
|
38 |
metadata = AudioMetadata(
|
39 |
duration=0.0,
|
40 |
sample_rate=16000,
|
41 |
language="es"
|
42 |
)
|
43 |
-
|
44 |
-
#
|
45 |
emotion_data = self.sentiment_service.analyze(transcript)
|
46 |
print("[DEBUG] Transcripci贸n exitosa. Texto:", transcript[:50])
|
47 |
-
|
48 |
-
#
|
49 |
presentation = Presentation(
|
50 |
id=uuid4(),
|
51 |
user_id=user_id,
|
@@ -57,14 +62,14 @@ class AudioUploadService:
|
|
57 |
metadata=metadata,
|
58 |
created_at=datetime.now(timezone.utc)
|
59 |
)
|
60 |
-
|
61 |
-
#
|
62 |
self.repository.save(presentation)
|
63 |
-
|
64 |
-
#
|
65 |
try:
|
66 |
os.remove(full_path)
|
67 |
except Exception as e:
|
68 |
print(f"[WARNING] No se pudo eliminar el archivo temporal: {e}")
|
69 |
-
|
70 |
return presentation
|
|
|
24 |
self.repository = repository
|
25 |
|
26 |
def upload_and_analyze(self, file: UploadFile, user_id: UUID = UUID("00000000-0000-0000-0000-000000000000")):
|
27 |
+
# 1. Determinar nombre personalizado con extensi贸n
|
28 |
+
existing_presentations = self.repository.get_all_by_user(user_id)
|
29 |
+
presentation_number = len(existing_presentations) + 1
|
30 |
+
ext = os.path.splitext(file.filename)[1]
|
31 |
+
custom_filename = f"presentacion_{presentation_number}{ext}"
|
32 |
+
|
33 |
+
# 2. Guardar archivo con nombre personalizado
|
34 |
+
filename = self.storage_service.save(file, custom_filename)
|
35 |
full_path = os.path.join(self.storage_service.base_path, filename)
|
36 |
+
|
37 |
+
# 3. Transcribir audio
|
38 |
result = self.transcription_service.transcribe(full_path)
|
|
|
39 |
transcript = result["text"]
|
40 |
confidence = result.get("confidence", 1.0)
|
41 |
+
|
42 |
+
# 4. Metadata simulada
|
43 |
metadata = AudioMetadata(
|
44 |
duration=0.0,
|
45 |
sample_rate=16000,
|
46 |
language="es"
|
47 |
)
|
48 |
+
|
49 |
+
# 5. An谩lisis emocional
|
50 |
emotion_data = self.sentiment_service.analyze(transcript)
|
51 |
print("[DEBUG] Transcripci贸n exitosa. Texto:", transcript[:50])
|
52 |
+
|
53 |
+
# 6. Crear entidad Presentation
|
54 |
presentation = Presentation(
|
55 |
id=uuid4(),
|
56 |
user_id=user_id,
|
|
|
62 |
metadata=metadata,
|
63 |
created_at=datetime.now(timezone.utc)
|
64 |
)
|
65 |
+
|
66 |
+
# 7. Guardar en base de datos
|
67 |
self.repository.save(presentation)
|
68 |
+
|
69 |
+
# 8. Eliminar archivo temporal
|
70 |
try:
|
71 |
os.remove(full_path)
|
72 |
except Exception as e:
|
73 |
print(f"[WARNING] No se pudo eliminar el archivo temporal: {e}")
|
74 |
+
|
75 |
return presentation
|