gnosticdev commited on
Commit
b992489
·
verified ·
1 Parent(s): e6fe746

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -17,7 +17,7 @@ async def synthesize(article_url, text_input, language):
17
  config = ConversationConfig()
18
  converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
19
 
20
- # Voces humanizadas (inglés) o español
21
  voices = {
22
  "en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"),
23
  "es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural")
@@ -25,11 +25,20 @@ async def synthesize(article_url, text_input, language):
25
  voice1, voice2 = voices.get(language, voices["en"])
26
 
27
  if text_input:
28
- output_file, conversation = await converter.text_to_audio(text_input, voice1, voice2)
 
 
 
 
 
 
 
 
29
  else:
30
- output_file, conversation = await converter.url_to_audio(article_url, voice1, voice2)
 
31
 
32
- return conversation, output_file
33
  except Exception as e:
34
  return f"Error: {str(e)}", None
35
 
@@ -43,7 +52,7 @@ with gr.Blocks(theme='gstaff/sketch') as demo:
43
 
44
  with gr.Row():
45
  conv_display = gr.Textbox(label="Conversation", interactive=False, lines=10)
46
- aud = gr.Audio(label="Podcast", interactive=False)
47
 
48
  btn.click(
49
  synthesize_sync,
 
17
  config = ConversationConfig()
18
  converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
19
 
20
+ # Voces (originales humanizadas en inglés o español)
21
  voices = {
22
  "en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"),
23
  "es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural")
 
25
  voice1, voice2 = voices.get(language, voices["en"])
26
 
27
  if text_input:
28
+ # Procesamiento directo de texto (nuevo)
29
+ conversation_json = converter.extract_conversation(text_input)
30
+ conversation_text = "\n".join(
31
+ f"{turn['speaker']}: {turn['text']}"
32
+ for turn in conversation_json["conversation"]
33
+ )
34
+ audio_files, _ = await converter.text_to_speech(conversation_json, voice1, voice2)
35
+ output_file = os.path.join("combined_output.wav")
36
+ converter.combine_audio_files(audio_files, output_file)
37
  else:
38
+ # Procesamiento de URL (original)
39
+ output_file, conversation_text = await converter.url_to_audio(article_url, voice1, voice2)
40
 
41
+ return conversation_text, output_file
42
  except Exception as e:
43
  return f"Error: {str(e)}", None
44
 
 
52
 
53
  with gr.Row():
54
  conv_display = gr.Textbox(label="Conversation", interactive=False, lines=10)
55
+ aud = gr.Audio(label="Generated Podcast", interactive=False)
56
 
57
  btn.click(
58
  synthesize_sync,