Update TextGen/router.py
Browse files- TextGen/router.py +11 -7
TextGen/router.py
CHANGED
@@ -26,7 +26,7 @@ Eleven_client = ElevenLabs(
|
|
26 |
)
|
27 |
|
28 |
|
29 |
-
|
30 |
class PlayLastMusic(BaseModel):
|
31 |
'''plays the lastest created music '''
|
32 |
Desicion: str = Field(
|
@@ -167,19 +167,23 @@ async def generate_wav(message: VoiceMessage):
|
|
167 |
except Exception as e:
|
168 |
raise HTTPException(status_code=500, detail=str(e))
|
169 |
|
170 |
-
def audio_stream(message):
|
171 |
-
|
172 |
-
# Generate the audio stream from ElevenLabs
|
173 |
-
for chunk in Eleven_client.generate(text=message.input, stream=True):
|
174 |
-
yield chunk
|
175 |
|
|
|
176 |
@app.post("/generate_voice", response_class=StreamingResponse)
|
177 |
def generate_voice(message: VoiceMessage = None):
|
178 |
print("message",message)
|
|
|
|
|
|
|
|
|
|
|
179 |
|
|
|
|
|
|
|
180 |
|
181 |
|
182 |
-
return StreamingResponse(audio_stream(
|
183 |
|
184 |
@app.get("/generate_song")
|
185 |
async def generate_song(text: str):
|
|
|
26 |
)
|
27 |
|
28 |
|
29 |
+
Last_message=None
|
30 |
class PlayLastMusic(BaseModel):
|
31 |
'''plays the lastest created music '''
|
32 |
Desicion: str = Field(
|
|
|
167 |
except Exception as e:
|
168 |
raise HTTPException(status_code=500, detail=str(e))
|
169 |
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
+
@app.get("/generate_voice", response_class=StreamingResponse)
|
172 |
@app.post("/generate_voice", response_class=StreamingResponse)
|
173 |
def generate_voice(message: VoiceMessage = None):
|
174 |
print("message",message)
|
175 |
+
if message is None:
|
176 |
+
message=Last_message
|
177 |
+
else:
|
178 |
+
Last_message=message
|
179 |
+
def audio_stream():
|
180 |
|
181 |
+
# Generate the audio stream from ElevenLabs
|
182 |
+
for chunk in Eleven_client.generate(text=message.input, stream=True):
|
183 |
+
yield chunk
|
184 |
|
185 |
|
186 |
+
return StreamingResponse(audio_stream(), media_type="audio/mpeg")
|
187 |
|
188 |
@app.get("/generate_song")
|
189 |
async def generate_song(text: str):
|