install.sh for ny maskin + paplay-reserve når PipeWire mangler
Skriptet installerer apt-pakker, uv, Python 3.13, Piper-stemmene og systemd-brukerenheten, og åpner porten i ufw hvis den er aktiv. Avspilling velger pw-play når PipeWire kjører, ellers paplay (Linux Mint 21). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
756a234b13
commit
ad1715838e
3 changed files with 128 additions and 4 deletions
22
announcer.py
22
announcer.py
|
|
@ -15,6 +15,7 @@ import logging
|
|||
import math
|
||||
import os
|
||||
import queue
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import threading
|
||||
|
|
@ -321,6 +322,22 @@ class Item:
|
|||
}
|
||||
|
||||
|
||||
def player_cmd(path: Path) -> list[str]:
|
||||
"""pw-play når PipeWire kjører, ellers paplay (PulseAudio, f.eks. Linux Mint 21)."""
|
||||
runtime = Path(os.environ.get("XDG_RUNTIME_DIR", f"/run/user/{os.getuid()}"))
|
||||
if shutil.which("pw-play") and (runtime / "pipewire-0").exists():
|
||||
cmd = ["pw-play"]
|
||||
if SINK:
|
||||
cmd += ["--target", SINK]
|
||||
elif shutil.which("paplay"):
|
||||
cmd = ["paplay"]
|
||||
if SINK:
|
||||
cmd += ["--device", SINK]
|
||||
else:
|
||||
raise RuntimeError("fant verken pw-play (pipewire-bin) eller paplay (pulseaudio-utils)")
|
||||
return cmd + [str(path)]
|
||||
|
||||
|
||||
class Player:
|
||||
def __init__(self) -> None:
|
||||
self.q: queue.Queue[Item] = queue.Queue()
|
||||
|
|
@ -374,10 +391,7 @@ class Player:
|
|||
self.current = item
|
||||
try:
|
||||
path = synthesize(item.text, item.voice, item.speed, item.chime)
|
||||
cmd = ["pw-play"]
|
||||
if SINK:
|
||||
cmd += ["--target", SINK]
|
||||
cmd.append(str(path))
|
||||
cmd = player_cmd(path)
|
||||
with self.lock:
|
||||
self.proc = subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
|
||||
_, err = self.proc.communicate()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue