TRaw commited on
Commit
87f025d
·
1 Parent(s): 3c423e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -18
app.py CHANGED
@@ -1,23 +1,22 @@
1
  from langchain.tools import ElevenLabsText2SpeechTool
2
  from elevenlabs import set_api_key, Voice, generate
3
  import gradio as gr
4
- import os
 
5
 
6
- set_api_key("866c88e3fe83f2b0de18226738445c8f")
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- tts = ElevenLabsText2SpeechTool()
9
-
10
- def generate_speech(text_to_speak):
11
- voice=Voice(
12
- voice_id='mu3rhpR8gxbjSIcSW7fa',
13
- )
14
- return speech_file
15
-
16
- demo = gr.Interface(
17
- fn=generate_speech,
18
- inputs=gr.Textbox(label="Enter Text"),
19
- outputs=gr.Audio(label="Generated Speech"),
20
- )
21
-
22
- if __name__ == "__main__":
23
- demo.launch()
 
1
  from langchain.tools import ElevenLabsText2SpeechTool
2
  from elevenlabs import set_api_key, Voice, generate
3
  import gradio as gr
4
+ import os
5
+ import requests
6
 
7
+ # Define the function that generates the audio
8
+ def generate_audio(text):
9
+ url = "https://api.elevenlabs.io/v1/text-to-speech/mu3rhpR8gxbjSIcSW7fa"
10
+ payload = {
11
+ "model_id": "eleven_turbo_v2",
12
+ "text": text
13
+ }
14
+ headers = {
15
+ "xi-api-key": "866c88e3fe83f2b0de18226738445c8f",
16
+ "Content-Type": "application/json"
17
+ }
18
+ response = requests.request("POST", url, json=payload, headers=headers)
19
+ return response.json()["audio"]
20
 
21
+ # Create the Gradio interface
22
+ gr.Interface(fn=generate_audio, inputs="text", outputs="audio").launch()