feat(service): no_playback-Flag (nur WAV erzeugen, kein lokales Abspielen)
Fuer Remote-/Gateway-Nutzung: mit no_playback=true generiert der Worker nur die WAV (keep_audio) und startet keinen PlaybackWorker -> der Server spielt nicht laut ab. Default false (lokales Abspielen unveraendert). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
7893c60e53
commit
1ce6540711
1 changed files with 17 additions and 9 deletions
|
|
@ -99,6 +99,7 @@ class SpeakJob:
|
|||
pronunciation_dict: Optional[dict]
|
||||
session_id: Optional[str]
|
||||
keep_audio: bool = False
|
||||
no_playback: bool = False # nur WAV erzeugen, NICHT lokal abspielen (Remote-/Gateway-Nutzung)
|
||||
status: JobStatus = field(default=JobStatus.pending)
|
||||
text_preview: str = field(default="")
|
||||
chunks_total: int = 0
|
||||
|
|
@ -144,13 +145,16 @@ def _worker() -> None:
|
|||
job.chunks_total = len(chunks)
|
||||
job.text_preview = job.text[:80]
|
||||
|
||||
playback = tts.PlaybackWorker(
|
||||
sample_rate=sr,
|
||||
device=job.audio_device or "pulse",
|
||||
speed=job.speed,
|
||||
stop_event=tts.STOP_REQUESTED,
|
||||
)
|
||||
playback.start()
|
||||
# no_playback: nur generieren (kein lokales Abspielen) -> Remote/Gateway.
|
||||
playback = None
|
||||
if not job.no_playback:
|
||||
playback = tts.PlaybackWorker(
|
||||
sample_rate=sr,
|
||||
device=job.audio_device or "pulse",
|
||||
speed=job.speed,
|
||||
stop_event=tts.STOP_REQUESTED,
|
||||
)
|
||||
playback.start()
|
||||
|
||||
wavs: list[torch.Tensor] = []
|
||||
try:
|
||||
|
|
@ -159,10 +163,12 @@ def _worker() -> None:
|
|||
break
|
||||
wav = tts.generate_chunk(model, model_kind, chunk, job.lang, job.voice)
|
||||
wavs.append(wav)
|
||||
playback.put(wav)
|
||||
if playback is not None:
|
||||
playback.put(wav)
|
||||
job.chunks_done += 1
|
||||
finally:
|
||||
playback.stop()
|
||||
if playback is not None:
|
||||
playback.stop()
|
||||
|
||||
if wavs:
|
||||
final = wavs[0] if len(wavs) == 1 else torch.cat(wavs, dim=-1)
|
||||
|
|
@ -215,6 +221,7 @@ class SpeakRequest(BaseModel):
|
|||
session_id: Optional[str] = None
|
||||
pronunciation_dict: Optional[dict] = None
|
||||
keep_audio: bool = False # WAV im Cache behalten für GET /audio/{job_id}
|
||||
no_playback: bool = False # nur generieren (kein lokales Abspielen) -> fuer Remote/Gateway
|
||||
|
||||
|
||||
def _job_to_dict(j: SpeakJob) -> dict:
|
||||
|
|
@ -284,6 +291,7 @@ def speak(req: SpeakRequest):
|
|||
pronunciation_dict=req.pronunciation_dict,
|
||||
session_id=req.session_id,
|
||||
keep_audio=req.keep_audio,
|
||||
no_playback=req.no_playback,
|
||||
)
|
||||
_job_queue.put(job)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue