10
10
11
11
from wyoming .audio import AudioChunk , AudioStart , AudioStop
12
12
from wyoming .client import AsyncClient
13
+ from wyoming .error import Error
13
14
from wyoming .info import Describe , Info
14
15
from wyoming .tts import Synthesize , SynthesizeVoice
15
16
@@ -77,6 +78,11 @@ async def api_stt() -> Response:
77
78
return Response (
78
79
wav_io .getvalue (), headers = {"Content-Type" : "audio/wav" }
79
80
)
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
+ )
80
86
81
87
@app .route ("/api/info" , methods = ["GET" ])
82
88
async def api_info ():
@@ -96,6 +102,11 @@ async def api_info():
96
102
info = Info .from_event (event )
97
103
return jsonify (info .to_dict ())
98
104
105
+ @app .errorhandler (Exception )
106
+ async def handle_error (err ):
107
+ """Return error as text."""
108
+ return (f"{ err .__class__ .__name__ } : { err } " , 500 )
109
+
99
110
flask_api_doc (app , config_path = str (CONF_PATH ), url_prefix = "/api" , title = "API doc" )
100
111
app .run (args .host , args .port )
101
112
0 commit comments