Jofthomas HF staff commited on
Commit
336c637
1 Parent(s): 0345f82

Update TextGen/router.py

Browse files
Files changed (1) hide show
  1. TextGen/router.py +16 -6
TextGen/router.py CHANGED
@@ -166,13 +166,23 @@ async def generate_wav(message: VoiceMessage):
166
 
167
  except Exception as e:
168
  raise HTTPException(status_code=500, detail=str(e))
169
- @app.post("/generate_voice")
170
- def generate_voice(message: VoiceMessage):
171
- def audio_stream():
172
- for chunk in Eleven_client.generate(text=message.input, stream=True):
173
- yield chunk
 
 
174
 
175
- return StreamingResponse(audio_stream(), media_type="audio/wav")
 
 
 
 
 
 
 
 
176
 
177
  @app.get("/generate_song")
178
  async def generate_song(text: str):
 
166
 
167
  except Exception as e:
168
  raise HTTPException(status_code=500, detail=str(e))
169
+
170
+ @app.post("/generate_voice", response_class=StreamingResponse)
171
+ @app.get("/generate_voice", response_class=StreamingResponse)
172
+ def generate_voice(message: VoiceMessage = None):
173
+ if message is None:
174
+ # If GET request without message input, return a default message
175
+ message = VoiceMessage(input="Default test message")
176
 
177
+ def audio_stream():
178
+ try:
179
+ # Generate the audio stream from ElevenLabs
180
+ for chunk in client.generate(text=message.input, stream=True):
181
+ yield chunk
182
+ except Exception as e:
183
+ raise HTTPException(status_code=500, detail=str(e))
184
+
185
+ return StreamingResponse(audio_stream(), media_type="audio/mpeg")
186
 
187
  @app.get("/generate_song")
188
  async def generate_song(text: str):