Peca33 commited on
Commit
f00a82c
verified
1 Parent(s): ee71922
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -10,24 +10,26 @@ from transformers import MarianMTModel, MarianTokenizer
10
 
11
 
12
  # Cargar el modelo Whisper-small y bark
13
- transcribir = pipeline("automatic-speech-recognition", model="openai/whisper-small")
14
  """bark = pipeline("text-to-speech", model="suno/bark")"""
15
 
16
 
17
  # Cargar el tokenizador y el modelo para espa帽ol a ingl茅s
18
- model_name = "Helsinki-NLP/opus-mt-es-en"
19
- tokenizer = MarianTokenizer.from_pretrained(model_name)
20
- model = MarianMTModel.from_pretrained(model_name)
21
 
22
 
23
  # Funci贸n para transcribir el audio y traducir el audio de entrada
24
  def transcribir_audio(audio):
25
  # Usamos el pipeline de Hugging Face para la transcripci贸n
26
- result = transcribir_audio(audio_file, task="translate")
 
27
  return result["text"]
28
 
29
 
30
  def traducir_texto(texto):
 
 
 
31
  # Tokenizar el texto
32
  inputs = tokenizer(texto, return_tensors="pt", padding=True, truncation=True)
33
  # Generar la traducci贸n
@@ -46,9 +48,20 @@ def generar_audio(text):
46
  temp_wav = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
47
  write(temp_wav.name, 24000, (audio_array * 32767).astype(np.int16))
48
  return temp_wav.name
49
-
50
 
51
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  def process_audio(audio_file):
53
  try:
54
  # Paso 1: Transcripci贸n con Whisper
 
10
 
11
 
12
  # Cargar el modelo Whisper-small y bark
13
+
14
  """bark = pipeline("text-to-speech", model="suno/bark")"""
15
 
16
 
17
  # Cargar el tokenizador y el modelo para espa帽ol a ingl茅s
18
+
 
 
19
 
20
 
21
  # Funci贸n para transcribir el audio y traducir el audio de entrada
22
  def transcribir_audio(audio):
23
  # Usamos el pipeline de Hugging Face para la transcripci贸n
24
+ transcribir = pipeline("automatic-speech-recognition", model="openai/whisper-small")
25
+ result = transcribir(audio)
26
  return result["text"]
27
 
28
 
29
  def traducir_texto(texto):
30
+ model_name = "Helsinki-NLP/opus-mt-es-en"
31
+ tokenizer = MarianTokenizer.from_pretrained(model_name)
32
+ model = MarianMTModel.from_pretrained(model_name)
33
  # Tokenizar el texto
34
  inputs = tokenizer(texto, return_tensors="pt", padding=True, truncation=True)
35
  # Generar la traducci贸n
 
48
  temp_wav = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
49
  write(temp_wav.name, 24000, (audio_array * 32767).astype(np.int16))
50
  return temp_wav.name
 
51
 
52
 
53
+ """def process_audio(audio_file):
54
+ try:
55
+ # Paso 1: Transcripci贸n y traducci贸n con Whisper
56
+ transcripcion_traducida = transcribir_audio(audio_file)
57
+
58
+ # Paso 2: Generaci贸n de audio con Bark
59
+ audio_sintetizado = generar_audio(transcripcion_traducida)
60
+
61
+ return transcripcion_traducida, audio_sintetizado
62
+ except Exception as e:
63
+ return str(e), None"""
64
+
65
  def process_audio(audio_file):
66
  try:
67
  # Paso 1: Transcripci贸n con Whisper