Spaces:
Running
Running
CrazyMonkey0 commited on
Commit ·
c56327c
1
Parent(s): 431435a
fix(tts): improve performance of send_audio function by avoiding repeated np.concatenate
Browse files- app/main.py +1 -1
- app/routes/tts.py +4 -3
app/main.py
CHANGED
|
@@ -14,7 +14,7 @@ async def startup_event():
|
|
| 14 |
try:
|
| 15 |
app.state.model_nlp, app.state.tokenizer_nlp = load_model_nlp()
|
| 16 |
app.state.model_trans, app.state.tokenizer_trans = load_model_translation()
|
| 17 |
-
app.state.model_tts= load_model_tts()
|
| 18 |
app.state.model_asr = load_model_asr()
|
| 19 |
except Exception as e:
|
| 20 |
print("[ERROR] Failed to load models:", e)
|
|
|
|
| 14 |
try:
|
| 15 |
app.state.model_nlp, app.state.tokenizer_nlp = load_model_nlp()
|
| 16 |
app.state.model_trans, app.state.tokenizer_trans = load_model_translation()
|
| 17 |
+
app.state.model_tts = load_model_tts()
|
| 18 |
app.state.model_asr = load_model_asr()
|
| 19 |
except Exception as e:
|
| 20 |
print("[ERROR] Failed to load models:", e)
|
app/routes/tts.py
CHANGED
|
@@ -19,13 +19,14 @@ def load_model_tts():
|
|
| 19 |
def send_audio(request: Request, text: str, voice: str = "af_heart") -> str:
|
| 20 |
pipeline = request.app.state.model_tts
|
| 21 |
|
| 22 |
-
|
| 23 |
|
| 24 |
generator = pipeline(text, voice=voice)
|
| 25 |
for _, _, audio in generator:
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
# zapis WAV do RAM (tak jak wcześniej)
|
| 29 |
buffer = io.BytesIO()
|
| 30 |
sf.write(buffer, audio_total, samplerate=24000, format="WAV")
|
| 31 |
buffer.seek(0)
|
|
|
|
| 19 |
def send_audio(request: Request, text: str, voice: str = "af_heart") -> str:
|
| 20 |
pipeline = request.app.state.model_tts
|
| 21 |
|
| 22 |
+
audio_chunks = []
|
| 23 |
|
| 24 |
generator = pipeline(text, voice=voice)
|
| 25 |
for _, _, audio in generator:
|
| 26 |
+
audio_chunks.append(audio)
|
| 27 |
+
|
| 28 |
+
audio_total = np.concatenate(audio_chunks)
|
| 29 |
|
|
|
|
| 30 |
buffer = io.BytesIO()
|
| 31 |
sf.write(buffer, audio_total, samplerate=24000, format="WAV")
|
| 32 |
buffer.seek(0)
|