Spaces:
Paused
Paused
Update TextGen/router.py
Browse files- TextGen/router.py +27 -0
TextGen/router.py
CHANGED
@@ -8,6 +8,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
8 |
from langchain.chains import LLMChain
|
9 |
from langchain.prompts import PromptTemplate
|
10 |
from TextGen.suno import custom_generate_audio, get_audio_information
|
|
|
11 |
from langchain_google_genai import (
|
12 |
ChatGoogleGenerativeAI,
|
13 |
HarmBlockThreshold,
|
@@ -156,7 +157,33 @@ async def generate_wav(message: VoiceMessage):
|
|
156 |
|
157 |
except Exception as e:
|
158 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
@app.get("/generate_song")
|
162 |
async def generate_song(text: str):
|
|
|
8 |
from langchain.chains import LLMChain
|
9 |
from langchain.prompts import PromptTemplate
|
10 |
from TextGen.suno import custom_generate_audio, get_audio_information
|
11 |
+
from TextGen.coqui import predict
|
12 |
from langchain_google_genai import (
|
13 |
ChatGoogleGenerativeAI,
|
14 |
HarmBlockThreshold,
|
|
|
157 |
|
158 |
except Exception as e:
|
159 |
raise HTTPException(status_code=500, detail=str(e))
|
160 |
+
@app.post("/generate_voice")
|
161 |
+
async def generate_voice(message: VoiceMessage):
|
162 |
+
try:
|
163 |
+
voice = determine_vocie_from_npc(message.npc, message.genre)
|
164 |
+
audio_file_pth = handle_file(voice)
|
165 |
|
166 |
+
# Generator function to yield audio chunks
|
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):
|