mosha255 commited on
Commit
e088c4e
·
unverified ·
1 Parent(s): 53bf901
Files changed (1) hide show
  1. spaces_app.py +10 -2
spaces_app.py CHANGED
@@ -4,6 +4,8 @@ import sys
4
  import logging
5
  import requests
6
 
 
 
7
  # Add the current directory to the path so we can import from app
8
  sys.path.append(os.path.dirname(os.path.abspath(__file__)))
9
 
@@ -17,13 +19,19 @@ logger = logging.getLogger(__name__)
17
  # Function to fetch audio from a URL
18
  def fetch_audio(input_text):
19
  # Replace with the actual backend URL for generating audio
20
- backend_url = "http://127.0.0.1:8080/api/text_to_speech"
21
  response = requests.get(backend_url, params={"text": input_text})
22
  if response.status_code == 200:
 
 
23
  return response.url # Return the URL of the generated audio
24
  else:
25
  return None
26
 
 
 
 
 
27
  # Gradio interface
28
  def create_gradio_interface():
29
  # Create the Gradio interface
@@ -41,7 +49,7 @@ def create_gradio_interface():
41
  output = gr.Audio(label="Generated Audio", type="filepath")
42
 
43
  generate_btn.click(
44
- fn=fetch_audio,
45
  inputs=input_text,
46
  outputs=output
47
  )
 
4
  import logging
5
  import requests
6
 
7
+ from tts import TTS
8
+
9
  # Add the current directory to the path so we can import from app
10
  sys.path.append(os.path.dirname(os.path.abspath(__file__)))
11
 
 
19
  # Function to fetch audio from a URL
20
  def fetch_audio(input_text):
21
  # Replace with the actual backend URL for generating audio
22
+ backend_url = "http://localhost:8080/api/text_to_speech"
23
  response = requests.get(backend_url, params={"text": input_text})
24
  if response.status_code == 200:
25
+ logger.info(f"Generated audio from text: {input_text}")
26
+ logger.info(f"Audio URL: {response.url}")
27
  return response.url # Return the URL of the generated audio
28
  else:
29
  return None
30
 
31
+ def generate_audio(input_text):
32
+ audio_array = TTS.generate(input_text)
33
+ return (44100, audio_array)
34
+
35
  # Gradio interface
36
  def create_gradio_interface():
37
  # Create the Gradio interface
 
49
  output = gr.Audio(label="Generated Audio", type="filepath")
50
 
51
  generate_btn.click(
52
+ fn=generate_audio,
53
  inputs=input_text,
54
  outputs=output
55
  )