hbui commited on
Commit
4cccb66
1 Parent(s): 7b9c7c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -23
app.py CHANGED
@@ -1,31 +1,25 @@
1
- from transformers.utils import logging
2
-
3
- logging.set_verbosity_error()
4
 
5
  from transformers import pipeline
6
-
7
  import gradio as gr
8
- import os
9
 
10
- import soundfile as sf
11
- import numpy as np
12
- import tempfile
13
 
14
- def launch(input_text):
15
- try:
16
- # Assuming `narrator` function returns a numpy array with audio data and a sampling rate.
17
- narrator = pipeline("text-to-speech", model="kakao-enterprise/vits-ljs")
18
- out = narrator(input_text)
19
- audio_data, samplerate = np.array(out["audio"][0]), 22050 # Example: 22050 Hz as common sampling rate
20
 
21
- # Directly return the audio data and sampling rate.
22
- return audio_data, samplerate
23
- except Exception as e:
24
- print(f"An error occurred: {e}")
25
- return None, None
 
26
 
27
- # Create the Gradio interface with the correct audio output handling.
28
- iface = gr.Interface(fn=launch, inputs="text", outputs=gr.Audio(type="numpy", label="Your Audio"))
29
 
30
- # Launch the Gradio app
31
- iface.launch()
 
 
 
 
1
 
2
  from transformers import pipeline
 
3
  import gradio as gr
 
4
 
5
+ # Initialize the text-to-speech pipeline with a model from Hugging Face's Model Hub
6
+ model_name = "kakao-enterprise/vits-ljs"
7
+ text_to_speech_pipeline = pipeline("text-to-speech", model=model_name)
8
 
9
+ def generate_speech(text):
10
+ # Generate speech from the input text
11
+ out = text_to_speech_pipeline(text)
12
+ # The output is a list of tensors, convert to numpy array
13
+ audio_data = out[0]["array"]
14
+ return audio_data, 22050 # Return audio data and sampling rate
15
 
16
+ # Create the Gradio interface
17
+ interface = gr.Interface(fn=generate_speech,
18
+ inputs=gr.Textbox(lines=2, placeholder="Type something here..."),
19
+ outputs=gr.Audio(type="numpy", label="Generated Speech"),
20
+ title="Text-to-Speech with Hugging Face",
21
+ description="Enter text to generate speech using a model from Hugging Face's Model Hub.")
22
 
23
+ # Launch the app
24
+ interface.launch()
25