mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-26 23:51:14 +02:00
fix: avoid blocking audio writes
TTS responses were written synchronously from the async presentation pipeline, blocking concurrent requests. Offload byte writes to a worker thread and add a regression test that keeps the event loop responsive.
This commit is contained in:
parent
32bb099025
commit
5cc05d90f0
3 changed files with 38 additions and 2 deletions
|
|
@ -17,6 +17,7 @@ from app.config import config as app_config
|
|||
from app.services.kokoro_tts_service import get_kokoro_tts_service
|
||||
from app.services.llm_service import get_agent_llm
|
||||
from app.utils.content_utils import extract_text_content, strip_markdown_fences
|
||||
from app.utils.file_io import write_bytes
|
||||
|
||||
from .configuration import Configuration
|
||||
from .prompts import (
|
||||
|
|
@ -137,8 +138,7 @@ async def create_slide_audio(state: State, config: RunnableConfig) -> dict[str,
|
|||
kwargs["api_base"] = app_config.TTS_SERVICE_API_BASE
|
||||
|
||||
response = await aspeech(**kwargs)
|
||||
with open(chunk_path, "wb") as f:
|
||||
f.write(response.content)
|
||||
await write_bytes(chunk_path, response.content)
|
||||
|
||||
return chunk_path
|
||||
|
||||
|
|
|
|||
7
surfsense_backend/app/utils/file_io.py
Normal file
7
surfsense_backend/app/utils/file_io.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
async def write_bytes(path: str, content: bytes) -> None:
|
||||
"""Write bytes without blocking the event loop."""
|
||||
await asyncio.to_thread(Path(path).write_bytes, content)
|
||||
Loading…
Add table
Add a link
Reference in a new issue