Update TextGen/router.py
Browse files- TextGen/router.py +14 -25
TextGen/router.py
CHANGED
@@ -17,6 +17,15 @@ from langchain_google_genai import (
|
|
17 |
from TextGen import app
|
18 |
from gradio_client import Client, handle_file
|
19 |
from typing import List
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
class PlayLastMusic(BaseModel):
|
22 |
'''plays the lastest created music '''
|
@@ -159,31 +168,11 @@ async def generate_wav(message: VoiceMessage):
|
|
159 |
raise HTTPException(status_code=500, detail=str(e))
|
160 |
@app.post("/generate_voice")
|
161 |
async def generate_voice(message: VoiceMessage):
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
async def audio_stream():
|
168 |
-
result = predict(
|
169 |
-
prompt=message.input,
|
170 |
-
language=message.language,
|
171 |
-
audio_file_pth=audio_file_pth,
|
172 |
-
mic_file_path=None,
|
173 |
-
use_mic=False,
|
174 |
-
voice_cleanup=False,
|
175 |
-
no_lang_auto_detect=False,
|
176 |
-
agree=True,
|
177 |
-
)
|
178 |
-
for sampling_rate, audio_chunk in result:
|
179 |
-
yield audio_chunk.tobytes()
|
180 |
-
await asyncio.sleep(0) # Yield control to the event loop
|
181 |
-
|
182 |
-
# Return the generated audio as a streaming response
|
183 |
-
return StreamingResponse(audio_stream(), media_type="audio/wav")
|
184 |
-
|
185 |
-
except Exception as e:
|
186 |
-
raise HTTPException(status_code=500, detail=str(e))
|
187 |
|
188 |
@app.get("/generate_song")
|
189 |
async def generate_song(text: str):
|
|
|
17 |
from TextGen import app
|
18 |
from gradio_client import Client, handle_file
|
19 |
from typing import List
|
20 |
+
from elevenlabs.client import ElevenLabs
|
21 |
+
from elevenlabs import stream
|
22 |
+
|
23 |
+
|
24 |
+
Eleven_client = ElevenLabs(
|
25 |
+
api_key=os.environ["ELEVEN_API_KEY"], # Defaults to ELEVEN_API_KEY
|
26 |
+
)
|
27 |
+
|
28 |
+
|
29 |
|
30 |
class PlayLastMusic(BaseModel):
|
31 |
'''plays the lastest created music '''
|
|
|
168 |
raise HTTPException(status_code=500, detail=str(e))
|
169 |
@app.post("/generate_voice")
|
170 |
async def generate_voice(message: VoiceMessage):
|
171 |
+
audio_stream = Eleven_client.generate(
|
172 |
+
text=message.input,
|
173 |
+
stream=True
|
174 |
+
)
|
175 |
+
return audio_stream
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
|
177 |
@app.get("/generate_song")
|
178 |
async def generate_song(text: str):
|