Update TextGen/router.py
Browse files- 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 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
| 174 |
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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):
|