Skip to content

Commit d0d12de

Browse files
committed
Add errors
1 parent 89e83d7 commit d0d12de

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 1.5.3
4+
5+
- Add `phrase` to wake word model info
6+
- Add tests to CI
7+
8+
## 1.5.2
9+
10+
- Fix missing VERSION file
11+
312
## 1.5.1
413

514
- Add `version` to info artifacts

wyoming/http/asr_server.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""HTTP server for automated speech recognition (ASR)."""
2+
23
import argparse
34
import io
45
import wave
@@ -10,6 +11,7 @@
1011
from wyoming.asr import Transcribe, Transcript
1112
from wyoming.audio import wav_to_chunks
1213
from wyoming.client import AsyncClient
14+
from wyoming.error import Error
1315
from wyoming.info import Describe, Info
1416

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

71+
if Error.is_type(event.type):
72+
error = Error.from_event(event)
73+
raise RuntimeError(
74+
f"Unexpected error from client: code={error.code}, text={error.text}"
75+
)
76+
6977
@app.route("/api/info", methods=["GET"])
7078
async def api_info():
7179
uri = request.args.get("uri", args.uri)

wyoming/http/tts_server.py

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from wyoming.audio import AudioChunk, AudioStart, AudioStop
1212
from wyoming.client import AsyncClient
13+
from wyoming.error import Error
1314
from wyoming.info import Describe, Info
1415
from wyoming.tts import Synthesize, SynthesizeVoice
1516

@@ -77,6 +78,11 @@ async def api_stt() -> Response:
7778
return Response(
7879
wav_io.getvalue(), headers={"Content-Type": "audio/wav"}
7980
)
81+
elif Error.is_type(event.type):
82+
error = Error.from_event(event)
83+
raise RuntimeError(
84+
f"Unexpected error from client: code={error.code}, text={error.text}"
85+
)
8086

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

105+
@app.errorhandler(Exception)
106+
async def handle_error(err):
107+
"""Return error as text."""
108+
return (f"{err.__class__.__name__}: {err}", 500)
109+
99110
flask_api_doc(app, config_path=str(CONF_PATH), url_prefix="/api", title="API doc")
100111
app.run(args.host, args.port)
101112

0 commit comments

Comments
 (0)