Skip to content

Commit

Permalink
Add errors
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam committed Feb 18, 2024
1 parent 89e83d7 commit d0d12de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 1.5.3

- Add `phrase` to wake word model info
- Add tests to CI

## 1.5.2

- Fix missing VERSION file

## 1.5.1

- Add `version` to info artifacts
Expand Down
8 changes: 8 additions & 0 deletions wyoming/http/asr_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""HTTP server for automated speech recognition (ASR)."""

import argparse
import io
import wave
Expand All @@ -10,6 +11,7 @@
from wyoming.asr import Transcribe, Transcript
from wyoming.audio import wav_to_chunks
from wyoming.client import AsyncClient
from wyoming.error import Error
from wyoming.info import Describe, Info

_DIR = Path(__file__).parent
Expand Down Expand Up @@ -66,6 +68,12 @@ async def api_stt() -> Response:
transcript = Transcript.from_event(event)
return jsonify(transcript.to_dict())

if Error.is_type(event.type):
error = Error.from_event(event)
raise RuntimeError(
f"Unexpected error from client: code={error.code}, text={error.text}"
)

@app.route("/api/info", methods=["GET"])
async def api_info():
uri = request.args.get("uri", args.uri)
Expand Down
11 changes: 11 additions & 0 deletions wyoming/http/tts_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from wyoming.audio import AudioChunk, AudioStart, AudioStop
from wyoming.client import AsyncClient
from wyoming.error import Error
from wyoming.info import Describe, Info
from wyoming.tts import Synthesize, SynthesizeVoice

Expand Down Expand Up @@ -77,6 +78,11 @@ async def api_stt() -> Response:
return Response(
wav_io.getvalue(), headers={"Content-Type": "audio/wav"}
)
elif Error.is_type(event.type):
error = Error.from_event(event)
raise RuntimeError(
f"Unexpected error from client: code={error.code}, text={error.text}"
)

@app.route("/api/info", methods=["GET"])
async def api_info():
Expand All @@ -96,6 +102,11 @@ async def api_info():
info = Info.from_event(event)
return jsonify(info.to_dict())

@app.errorhandler(Exception)
async def handle_error(err):
"""Return error as text."""
return (f"{err.__class__.__name__}: {err}", 500)

flask_api_doc(app, config_path=str(CONF_PATH), url_prefix="/api", title="API doc")
app.run(args.host, args.port)

Expand Down

0 comments on commit d0d12de

Please sign in to comment.