Spaces:
Sleeping
Sleeping
SantosPatazca commited on
Commit ·
7aaffe4
1
Parent(s): 8b0d7a2
add: new changes in tts model
Browse files
src/expon/feedback/infrastructure/services/text_generation_service.py
CHANGED
|
@@ -218,6 +218,7 @@ class TextGenerationService:
|
|
| 218 |
|
| 219 |
# ✅ lista fija simple y estable
|
| 220 |
self.model_list = [
|
|
|
|
| 221 |
"gemini-2.5-flash",
|
| 222 |
"gemini-2.5-pro",
|
| 223 |
"gemini-2.0-flash",
|
|
|
|
| 218 |
|
| 219 |
# ✅ lista fija simple y estable
|
| 220 |
self.model_list = [
|
| 221 |
+
"gemini-3-pro-preview",
|
| 222 |
"gemini-2.5-flash",
|
| 223 |
"gemini-2.5-pro",
|
| 224 |
"gemini-2.0-flash",
|
src/expon/presentation/domain/services/transcription_service.py
CHANGED
|
@@ -17,7 +17,7 @@ class TranscriptionService:
|
|
| 17 |
raise Exception("El archivo está vacío. Verifica que se haya subido correctamente.")
|
| 18 |
|
| 19 |
try:
|
| 20 |
-
|
| 21 |
with open(file_path, "rb") as f:
|
| 22 |
upload_res = requests.post(
|
| 23 |
UPLOAD_URL,
|
|
@@ -27,7 +27,7 @@ class TranscriptionService:
|
|
| 27 |
upload_res.raise_for_status()
|
| 28 |
audio_url = upload_res.json()["upload_url"]
|
| 29 |
|
| 30 |
-
|
| 31 |
transcript_res = requests.post(
|
| 32 |
TRANSCRIBE_URL,
|
| 33 |
json={"audio_url": audio_url, "language_code": "es"},
|
|
@@ -36,7 +36,7 @@ class TranscriptionService:
|
|
| 36 |
transcript_res.raise_for_status()
|
| 37 |
transcript_id = transcript_res.json()["id"]
|
| 38 |
|
| 39 |
-
|
| 40 |
while True:
|
| 41 |
poll_res = requests.get(f"{TRANSCRIBE_URL}/{transcript_id}", headers={"authorization": ASSEMBLYAI_API_KEY})
|
| 42 |
poll_data = poll_res.json()
|
|
|
|
| 17 |
raise Exception("El archivo está vacío. Verifica que se haya subido correctamente.")
|
| 18 |
|
| 19 |
try:
|
| 20 |
+
|
| 21 |
with open(file_path, "rb") as f:
|
| 22 |
upload_res = requests.post(
|
| 23 |
UPLOAD_URL,
|
|
|
|
| 27 |
upload_res.raise_for_status()
|
| 28 |
audio_url = upload_res.json()["upload_url"]
|
| 29 |
|
| 30 |
+
|
| 31 |
transcript_res = requests.post(
|
| 32 |
TRANSCRIBE_URL,
|
| 33 |
json={"audio_url": audio_url, "language_code": "es"},
|
|
|
|
| 36 |
transcript_res.raise_for_status()
|
| 37 |
transcript_id = transcript_res.json()["id"]
|
| 38 |
|
| 39 |
+
|
| 40 |
while True:
|
| 41 |
poll_res = requests.get(f"{TRANSCRIBE_URL}/{transcript_id}", headers={"authorization": ASSEMBLYAI_API_KEY})
|
| 42 |
poll_data = poll_res.json()
|
src/expon/tts/services/gemini_tts_service.py
CHANGED
|
@@ -7,6 +7,15 @@ from typing import Optional, Tuple
|
|
| 7 |
from google import genai
|
| 8 |
from google.genai import types
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
class GeminiTTSService:
|
| 12 |
def __init__(self):
|
|
@@ -37,20 +46,30 @@ class GeminiTTSService:
|
|
| 37 |
voice_name: str = "Umbriel",
|
| 38 |
language_code: str = "es-ES",
|
| 39 |
temperature: float = 1.0,
|
|
|
|
| 40 |
) -> bytes:
|
| 41 |
"""
|
| 42 |
Devuelve audio WAV (bytes) usando Gemini TTS.
|
| 43 |
-
|
| 44 |
"""
|
| 45 |
-
model = "gemini-2.5-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
response = self.client.models.generate_content(
|
| 49 |
model=model,
|
| 50 |
-
contents=
|
| 51 |
config=types.GenerateContentConfig(
|
| 52 |
temperature=temperature,
|
| 53 |
-
response_modalities=["AUDIO"],
|
| 54 |
speech_config=types.SpeechConfig(
|
| 55 |
voice_config=types.VoiceConfig(
|
| 56 |
prebuilt_voice_config=types.PrebuiltVoiceConfig(
|
|
|
|
| 7 |
from google import genai
|
| 8 |
from google.genai import types
|
| 9 |
|
| 10 |
+
STYLE_INSTRUCTIONS_DEFAULT = (
|
| 11 |
+
"Lee el siguiente texto con un tono entusiasta, motivador y profesional, "
|
| 12 |
+
"como un coach académico que brinda retroalimentación positiva. "
|
| 13 |
+
"Habla con energía moderada, claridad y calidez, transmitiendo confianza sin sonar exagerado. "
|
| 14 |
+
"Mantén un acento neutro latinoamericano, sin rasgos marcados de ninguna región específica. "
|
| 15 |
+
"Prioriza un ritmo dinámico y amigable, adecuado para estudiantes universitarios que "
|
| 16 |
+
"buscan mejorar sus habilidades de comunicación. "
|
| 17 |
+
"No leas estas instrucciones en voz alta; solo aplícalas al texto que viene a continuación."
|
| 18 |
+
)
|
| 19 |
|
| 20 |
class GeminiTTSService:
|
| 21 |
def __init__(self):
|
|
|
|
| 46 |
voice_name: str = "Umbriel",
|
| 47 |
language_code: str = "es-ES",
|
| 48 |
temperature: float = 1.0,
|
| 49 |
+
style_instructions: Optional[str] = None,
|
| 50 |
) -> bytes:
|
| 51 |
"""
|
| 52 |
Devuelve audio WAV (bytes) usando Gemini TTS.
|
| 53 |
+
El estilo de voz se controla con instrucciones en el propio prompt.
|
| 54 |
"""
|
| 55 |
+
model = "gemini-2.5-pro-preview-tts"
|
| 56 |
+
|
| 57 |
+
# 1) Tomamos las instrucciones por parámetro o usamos las por defecto
|
| 58 |
+
style = style_instructions or STYLE_INSTRUCTIONS_DEFAULT
|
| 59 |
+
|
| 60 |
+
# 2) Construimos el prompt completo para TTS
|
| 61 |
+
prompt = (
|
| 62 |
+
f"{style}\n\n"
|
| 63 |
+
"Ahora lee únicamente el siguiente texto en español, sin agregar comentarios extra:\n\n"
|
| 64 |
+
f"{text}"
|
| 65 |
+
)
|
| 66 |
|
| 67 |
response = self.client.models.generate_content(
|
| 68 |
model=model,
|
| 69 |
+
contents=prompt,
|
| 70 |
config=types.GenerateContentConfig(
|
| 71 |
temperature=temperature,
|
| 72 |
+
response_modalities=["AUDIO"],
|
| 73 |
speech_config=types.SpeechConfig(
|
| 74 |
voice_config=types.VoiceConfig(
|
| 75 |
prebuilt_voice_config=types.PrebuiltVoiceConfig(
|