dongsiqie commited on
Commit
d608468
·
1 Parent(s): fa1355e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
2
  import os
3
  import tempfile
4
  from openai import OpenAI
 
 
5
 
6
 
7
  def tts(text, model, voice, api_key):
@@ -9,14 +11,18 @@ def tts(text, model, voice, api_key):
9
  raise gr.Error('Please enter your OpenAI API Key')
10
  else:
11
  try:
12
- client = OpenAI(api_key=api_key)
13
-
14
- response = client.audio.speech.create(
15
- model=model, # "tts-1","tts-1-hd"
16
- voice=voice, # 'alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'
17
- input=text,
18
- )
19
-
 
 
 
 
20
  except Exception as error:
21
  # Handle any exception that occurs
22
  raise gr.Error("An error occurred while generating speech. Please check your API key and try again.")
 
2
  import os
3
  import tempfile
4
  from openai import OpenAI
5
+ import requests
6
+ import json
7
 
8
 
9
  def tts(text, model, voice, api_key):
 
11
  raise gr.Error('Please enter your OpenAI API Key')
12
  else:
13
  try:
14
+ headers = {'Authorization': f'Bearer sk-ztrcLG06AudTIErn3OsNbxmtXatSL7AHCokpnCwk6TvgvYwI',
15
+ 'Content-Type':'application/json'}
16
+ url = "https://openkey.cloud/v1/audio/speech"
17
+ input_text = text
18
+ query = {
19
+ "model":model,# "tts-1","tts-1-hd"
20
+ "input":input_text,
21
+ "voice":voice,# 'alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'
22
+ "response_format":"mp3",
23
+ "speed":1,
24
+ }
25
+ response = requests.post(url=url, data=json.dumps(query), headers=headers)
26
  except Exception as error:
27
  # Handle any exception that occurs
28
  raise gr.Error("An error occurred while generating speech. Please check your API key and try again.")