Skip to content

Commit

Permalink
Improve Fish Audio API error handling
Browse files Browse the repository at this point in the history
update tool version
  • Loading branch information
41tair committed Jan 4, 2025
1 parent 7200087 commit 97e3f6f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions tools/fishaudio/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ meta:
entrypoint: main
language: python
version: '3.12'
version: 0.0.1
version: 0.0.2
name: fishaudio_tool
plugins:
tools:
Expand All @@ -27,4 +27,4 @@ resource:
tags:
- utilities
type: plugin
version: 0.0.1
version: 0.0.2
22 changes: 12 additions & 10 deletions tools/fishaudio/tools/fishaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ def tts(self, content, voice, latency, audio_format) -> Generator[bytes, None, N
reference_id=voice,
latency=latency,
)
with httpx.stream(
"POST",
self.url_base + "/v1/tts",
content=ormsgpack.packb(request, option=ormsgpack.OPT_SERIALIZE_PYDANTIC),
headers=self.headers(),
timeout=None,
) as response:
if response.status_code != 200:
raise InvokeBadRequestError(f"Error: {response.status_code} - {response.text}")
yield from response.iter_bytes()
try:
with httpx.stream(
"POST",
self.url_base + "/v1/tts",
content=ormsgpack.packb(request, option=ormsgpack.OPT_SERIALIZE_PYDANTIC),
headers=self.headers(),
timeout=None,
) as response:
response.raise_for_status()
yield from response.iter_bytes()
except httpx.HTTPStatusError as e:
raise InvokeBadRequestError(f"{e.response.status_code} - {str(e)}")

def model_list(self, page_number):
params = {
Expand Down
4 changes: 2 additions & 2 deletions tools/fishaudio/tools/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessag
try:
data = self._tts(content, voice_id, audio_format)
yield self.create_blob_message(blob=data, meta={"mime_type": f"audio/{audio_format}"})
except Exception:
yield self.create_text_message("Text to speech service error, please check the network")
except Exception as e:
yield self.create_text_message(f"Text to speech service error, please check the network; error: {e}")

def _tts(self, content: str, voice_id: str, audio_format: str) -> bytes:
api_key = self.runtime.credentials.get("api_key")
Expand Down

0 comments on commit 97e3f6f

Please sign in to comment.