Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
IliaLarchenko
commited on
Commit
•
33727a3
1
Parent(s):
9b71b82
Fixed error handling
Browse files- api/audio.py +1 -14
api/audio.py
CHANGED
@@ -37,14 +37,7 @@ class STTManager:
|
|
37 |
if self.config.stt.type == "OPENAI_API":
|
38 |
data = ("temp.wav", audio, "audio/wav")
|
39 |
client = OpenAI(base_url=self.config.stt.url, api_key=self.config.stt.key)
|
40 |
-
|
41 |
-
if not response.success:
|
42 |
-
raise APIError(
|
43 |
-
"STT Error: OpenAI API error",
|
44 |
-
status_code=response.status_code,
|
45 |
-
details=response.error.get("message", "No error message provided"),
|
46 |
-
)
|
47 |
-
transcription = response.data
|
48 |
elif self.config.stt.type == "HF_API":
|
49 |
headers = {"Authorization": "Bearer " + self.config.stt.key}
|
50 |
response = requests.post(self.config.stt.url, headers=headers, data=audio)
|
@@ -71,12 +64,6 @@ class TTSManager:
|
|
71 |
if self.config.tts.type == "OPENAI_API":
|
72 |
client = OpenAI(base_url=self.config.tts.url, api_key=self.config.tts.key)
|
73 |
response = client.audio.speech.create(model=self.config.tts.name, voice="alloy", response_format="opus", input=text)
|
74 |
-
if not response.success:
|
75 |
-
raise APIError(
|
76 |
-
"TTS Error: OpenAI API error",
|
77 |
-
status_code=response.status_code,
|
78 |
-
details=response.error.get("message", "No error message provided"),
|
79 |
-
)
|
80 |
elif self.config.tts.type == "HF_API":
|
81 |
headers = {"Authorization": "Bearer " + self.config.tts.key}
|
82 |
response = requests.post(self.config.tts.url, headers=headers, json={"inputs": text})
|
|
|
37 |
if self.config.stt.type == "OPENAI_API":
|
38 |
data = ("temp.wav", audio, "audio/wav")
|
39 |
client = OpenAI(base_url=self.config.stt.url, api_key=self.config.stt.key)
|
40 |
+
transcription = client.audio.transcriptions.create(model=self.config.stt.name, file=data, response_format="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
elif self.config.stt.type == "HF_API":
|
42 |
headers = {"Authorization": "Bearer " + self.config.stt.key}
|
43 |
response = requests.post(self.config.stt.url, headers=headers, data=audio)
|
|
|
64 |
if self.config.tts.type == "OPENAI_API":
|
65 |
client = OpenAI(base_url=self.config.tts.url, api_key=self.config.tts.key)
|
66 |
response = client.audio.speech.create(model=self.config.tts.name, voice="alloy", response_format="opus", input=text)
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
elif self.config.tts.type == "HF_API":
|
68 |
headers = {"Authorization": "Bearer " + self.config.tts.key}
|
69 |
response = requests.post(self.config.tts.url, headers=headers, json={"inputs": text})
|