sheikhed commited on
Commit
2bce8ff
·
verified ·
1 Parent(s): a23ccb7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -22
app.py CHANGED
@@ -11,7 +11,7 @@ from dotenv import load_dotenv
11
  load_dotenv()
12
 
13
  # API Keys
14
- A_KEY = os.getenv("A_KEY")
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
- url = "https://api.elevenlabs.io/v1/voices"
23
- headers = {
24
- "Accept": "application/json",
25
- "xi-api-key": A_KEY
26
- }
27
-
28
- response = requests.get(url, headers=headers)
29
- if response.status_code != 200:
30
- return []
31
- return [(voice['name'], voice['voice_id']) for voice in response.json().get('voices', [])]
32
 
33
- def text_to_speech(voice_id, text, session_id):
34
- url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}"
35
 
36
  headers = {
37
- "Accept": "audio/mpeg",
38
- "Content-Type": "application/json",
39
- "xi-api-key": A_KEY
40
  }
41
 
42
  data = {
43
- "text": text,
44
- "model_id": "eleven_turbo_v2_5",
45
- "voice_settings": {
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)