Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ from dotenv import load_dotenv
|
|
11 |
load_dotenv()
|
12 |
|
13 |
# API Keys
|
14 |
-
|
15 |
B_KEY = os.getenv("B_KEY")
|
16 |
|
17 |
# URLs
|
@@ -19,33 +19,28 @@ API_URL = os.getenv("API_URL")
|
|
19 |
UPLOAD_URL = os.getenv("UPLOAD_URL")
|
20 |
|
21 |
def get_voices():
|
22 |
-
|
23 |
-
|
24 |
-
"
|
25 |
-
"
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
return [(voice['name'], voice['voice_id']) for voice in response.json().get('voices', [])]
|
32 |
|
33 |
-
def text_to_speech(
|
34 |
-
url =
|
35 |
|
36 |
headers = {
|
37 |
-
"
|
38 |
-
"Content-Type": "application/json"
|
39 |
-
"xi-api-key": A_KEY
|
40 |
}
|
41 |
|
42 |
data = {
|
43 |
-
"
|
44 |
-
"
|
45 |
-
"
|
46 |
-
"stability": 0.5,
|
47 |
-
"similarity_boost": 0.5
|
48 |
-
}
|
49 |
}
|
50 |
|
51 |
response = requests.post(url, json=data, headers=headers)
|
|
|
11 |
load_dotenv()
|
12 |
|
13 |
# API Keys
|
14 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
15 |
B_KEY = os.getenv("B_KEY")
|
16 |
|
17 |
# URLs
|
|
|
19 |
UPLOAD_URL = os.getenv("UPLOAD_URL")
|
20 |
|
21 |
def get_voices():
|
22 |
+
# OpenAI TTS voices
|
23 |
+
return [
|
24 |
+
("alloy", "alloy"),
|
25 |
+
("echo", "echo"),
|
26 |
+
("fable", "fable"),
|
27 |
+
("onyx", "onyx"),
|
28 |
+
("nova", "nova"),
|
29 |
+
("shimmer", "shimmer")
|
30 |
+
]
|
|
|
31 |
|
32 |
+
def text_to_speech(voice, text, session_id):
|
33 |
+
url = "https://api.openai.com/v1/audio/speech"
|
34 |
|
35 |
headers = {
|
36 |
+
"Authorization": f"Bearer {OPENAI_API_KEY}",
|
37 |
+
"Content-Type": "application/json"
|
|
|
38 |
}
|
39 |
|
40 |
data = {
|
41 |
+
"model": "tts-1",
|
42 |
+
"input": text,
|
43 |
+
"voice": voice
|
|
|
|
|
|
|
44 |
}
|
45 |
|
46 |
response = requests.post(url, json=data, headers=headers)
|