File tree 1 file changed +32
-0
lines changed 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,38 @@ class ChatResponse(BaseModel):
224
224
audio_path : str
225
225
226
226
227
+ class TextInput (BaseModel ):
228
+ text : str
229
+
230
+
231
+ @app .post ("/speak" )
232
+ @handle_errors
233
+ async def speak_endpoint (input_data : TextInput ):
234
+ """Convert text to speech and return audio file"""
235
+ assistant = VoiceAssistant ()
236
+ try :
237
+ audio_path = await assistant .synthesize_speech (input_data .text )
238
+
239
+ with open (audio_path , 'rb' ) as f :
240
+ audio_content = f .read ()
241
+
242
+ assistant .cleanup ()
243
+
244
+ temp_response_path = tempfile .mktemp (suffix = '.wav' )
245
+ with open (temp_response_path , 'wb' ) as f :
246
+ f .write (audio_content )
247
+
248
+ return FileResponse (
249
+ path = temp_response_path ,
250
+ media_type = "audio/wav" ,
251
+ filename = "speech.wav"
252
+ )
253
+ except Exception as e :
254
+ if assistant :
255
+ assistant .cleanup ()
256
+ raise VoiceAssistantError (f"Speech synthesis failed: { str (e )} " )
257
+
258
+
227
259
@app .get ("/health" )
228
260
async def root ():
229
261
"""Health check endpoint"""
You can’t perform that action at this time.
0 commit comments