Add tested native German TTS service on AT-Helper
This commit is contained in:
1 parent
5b70e9bb33
commit
d042c5b1f1
15 files changed
+417
No files matched your search
@@ -0,0 +1,86 @@
|
||||
# AT-Helper TTS — 2026-10-13
|
||||
|
||||
Separate native speech service on `at-helper.scc.kit.edu` (172.21.117.203).
|
||||
Athena Deck/Strata, their profiles and audio policies were not modified.
|
||||
|
||||
## Tested hardware and decision
|
||||
|
||||
Debian 13.7, Xeon X3450 (4C/8T, no AVX), 8 GiB RAM, RX470 8 GiB,
|
||||
RADV Polaris10 Mesa25.0.7. Vulkan device0 is the GPU; software device1 is not used.
|
||||
|
||||
The pinned KoboldCpp oldpc binary starts with `--failsafe --usevulkan 0`.
|
||||
`--noavx2` alone crashed with SIGILL, so it must not replace `--failsafe` here.
|
||||
Transformer and vocoder both confirmed Vulkan0. About2.65 GiB GPU memory
|
||||
was used during the synthetic request. RX470 has no native fp16 shader support.
|
||||
|
||||
Same German text, two runs:
|
||||
|
||||
| Engine | Model load | Generate | Audio | RTF |
|
||||
|---|---:|---:|---:|---:|
|
||||
| Qwen3-TTS0.6B F16 Vulkan |2.42s*|30.69s|6.62s|4.64|
|
||||
| Qwen3-TTS0.6B F16 Vulkan warm |—|24.44s|6.94s|3.52|
|
||||
| Piper Thorsten-medium CPU |2.86s|0.76s|5.96s|0.128|
|
||||
| Piper Thorsten-medium CPU warm |—|0.72s|5.67s|0.126|
|
||||
|
||||
*Qwen model-load timing excludes ~8seconds self-extraction and initial runtime startup.
|
||||
RTF <1 is faster than realtime. These are two synthetic samples, not a voice-quality
|
||||
benchmark. Qwen WAVs had nonzero waveform peaks; no subjective listening score claimed.
|
||||
|
||||
**Default:** Piper CPU, German Thorsten voice, persistent model.
|
||||
**Qwen:** installed, optional service present, disabled/not running because too slow.
|
||||
No voice cloning or custom private voice files used. Piper does not offer Qwen's
|
||||
cloning/style features. GPU is freed after the completed Qwen test.
|
||||
|
||||
## API
|
||||
|
||||
`http://172.21.117.203:8099/v1/audio/speech`
|
||||
Bearer key stored only on Helper at `/etc/athena-helper-tts/api-key` (root:athena-tts640).
|
||||
Do not print it, put it in Git, CLI arguments, screenshots or application logs.
|
||||
Transfer internally to the eventual consuming application or enter through its secret field.
|
||||
Traffic is HTTP on the KIT interface; use a TLS reverse proxy or encrypted tunnel before
|
||||
using this endpoint through an untrusted network. No all-interface bind, no public TTS UI.
|
||||
|
||||
- `model`: `tts-1`, `tts-1-hd`, `piper`, `de_DE-thorsten-medium` all select the same model.
|
||||
- `voice`: `thorsten`, `alloy` alias.
|
||||
- `language`: default German; other languages rejected.
|
||||
- `input`: nonempty text; maxJSON32MiB.
|
||||
- `response_format`: mp3(default), wav, pcm, flac, opus, aac.
|
||||
- `speed`:0.25–4.0 (default1).
|
||||
- Authenticated `GET /health`, `/v1/audio/voices`.
|
||||
- Requests serialized for one loaded model; request content/authentication never logged.
|
||||
|
||||
This is not yet wired into Deck/LibreChat/OpenWebUI. Final API check: authenticated health/voices200, unauthenticated401; Athena-to-Helper
|
||||
connectivity confirmed via401. WAV0.800s for6.026s, MP31.468s for6.061s audio.
|
||||
API service memory221773824bytes (~212MiB); GPU residual5.2MiB after stopping Qwen.
|
||||
|
||||
Client credentials/settings
|
||||
and a real frontend playback check remain separate integration work.
|
||||
|
||||
## Install / restore
|
||||
|
||||
Official sources:
|
||||
- https://github.com/LostRuins/koboldcpp/releases/tag/v1.122.1
|
||||
- https://koboldcpp.net/docs/features/text-to-speech/
|
||||
- https://github.com/OHF-Voice/piper1-gpl
|
||||
- https://huggingface.co/rhasspy/piper-voices
|
||||
|
||||
Run `sudo ./install.sh` from this directory on a matching Debian13 host.
|
||||
`manifest.json`, `piper-manifest.json` pin revisions and SHA256; `restore_models.py`
|
||||
downloads/verifies public binaries/models. `requirements.txt` freezes tested Python packages.
|
||||
Debian dependencies: python3-venv, ffmpeg, libvulkan1, mesa-vulkan-drivers;
|
||||
existing video/render groups are required for optional Vulkan. Python3.13 tested.
|
||||
|
||||
- `/opt/athena-helper-tts`: public models, binaries, venv, gateway.
|
||||
- `/var/lib/athena-helper-tts`: runtime user's home/cache.
|
||||
- `/etc/athena-helper-tts/api-key`: secret, preserve in encrypted backup to retain client access.
|
||||
- `athena-helper-tts-api.service`: Piper API, enabled onboot.
|
||||
- `athena-helper-tts.service`: optional Qwen localhost18099; NOT enabled onboot.
|
||||
|
||||
Adjust API unit's LISTEN_HOST for another host. The installer must only run on Helper;
|
||||
it starts this service but never restarts Deck or other applications.
|
||||
For updates, schedule an idle window before restarting the TTS service.
|
||||
Fresh-host full restore and post-reboot startup were not tested; enabled state and
|
||||
actual dedicated-user service startup were tested on this host.
|
||||
|
||||
Own measurement scripts and JSON outputs contain only synthetic test information.
|
||||
No model weights, private audio or credentials are committed.
|
||||
@@ -0,0 +1,48 @@
|
||||
[
|
||||
{
|
||||
"path": "/health",
|
||||
"status": 200,
|
||||
"metadata": {
|
||||
"status": "ok",
|
||||
"engine": "piper",
|
||||
"device": "cpu",
|
||||
"voice": "thorsten",
|
||||
"language": "de",
|
||||
"model_load_seconds": 2.945
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/v1/audio/voices",
|
||||
"status": 200,
|
||||
"metadata": {
|
||||
"voices": [
|
||||
"thorsten",
|
||||
"alloy"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"unauthenticated": "/health",
|
||||
"status": 401
|
||||
},
|
||||
{
|
||||
"unauthenticated": "/tts_to_audio",
|
||||
"status": 401
|
||||
},
|
||||
{
|
||||
"format": "wav",
|
||||
"content_type": "audio/wav",
|
||||
"elapsed_seconds": 0.8,
|
||||
"audio_seconds": 6.025578,
|
||||
"rtf": 0.133,
|
||||
"bytes": 265772
|
||||
},
|
||||
{
|
||||
"format": "mp3",
|
||||
"content_type": "audio/mpeg",
|
||||
"elapsed_seconds": 1.468,
|
||||
"audio_seconds": 6.0605,
|
||||
"rtf": 0.242,
|
||||
"bytes": 24286
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,19 @@
|
||||
[Unit]
|
||||
Description=Authenticated AT-Helper speech API
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
[Service]
|
||||
User=athena-tts
|
||||
Group=athena-tts
|
||||
Environment=LISTEN_HOST=172.21.117.203
|
||||
Environment=LISTEN_PORT=8099
|
||||
Environment=TOKEN_FILE=/etc/athena-helper-tts/api-key
|
||||
ExecStart=/opt/athena-helper-tts/piper-venv/bin/python3 /opt/athena-helper-tts/gateway.py
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,20 @@
|
||||
[Unit]
|
||||
Description=AT-Helper Qwen3-TTS on RX470 Vulkan
|
||||
After=network.target
|
||||
[Service]
|
||||
User=athena-tts
|
||||
Group=athena-tts
|
||||
SupplementaryGroups=render video
|
||||
WorkingDirectory=/opt/athena-helper-tts
|
||||
Environment=PYTHONUNBUFFERED=1
|
||||
Environment=HOME=/var/lib/athena-helper-tts
|
||||
ExecStart=/opt/athena-helper-tts/koboldcpp --nomodel --usevulkan 0 --failsafe --host 127.0.0.1 --port 18099 --threads 4 --ttsthreads 4 --ttsmodel /opt/athena-helper-tts/models/qwen3-tts-0.6b-f16.gguf --ttswavtokenizer /opt/athena-helper-tts/models/qwen3-tts-tokenizer-f16.gguf --ttsgpu --quiet
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
ReadWritePaths=/var/lib/athena-helper-tts
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,21 @@
|
||||
import pathlib,urllib.request,hashlib,json,os
|
||||
root=pathlib.Path('/opt/athena-helper-tts');root.mkdir(exist_ok=True)
|
||||
files=[('koboldcpp','https://github.com/LostRuins/koboldcpp/releases/download/v1.122.1/koboldcpp-linux-x64-oldpc','04716cc1e871803e41b1475a4471655a8390b102086741f8d107ceda74c6cdbe'),('models/qwen3-tts-0.6b-f16.gguf','https://huggingface.co/koboldcpp/tts/resolve/36c114d8b20004a020d8192e9433a787911487bc/qwen3-tts-0.6b-f16.gguf','0b89770118463af8f2467d824a8de57d96df6a09f927a9769a3f7b7fffa7087d'),('models/qwen3-tts-tokenizer-f16.gguf','https://huggingface.co/koboldcpp/tts/resolve/36c114d8b20004a020d8192e9433a787911487bc/qwen3-tts-tokenizer-f16.gguf','d1ad9660bd99343f4851d5a4b17e31f65648feb3559f6ea062ae6575e5cd9d90')]
|
||||
for name,url,expected in files:
|
||||
target=root/name;target.parent.mkdir(exist_ok=True);part=target.with_suffix('.part');h=hashlib.sha256()
|
||||
if target.exists():
|
||||
with target.open('rb')as f:
|
||||
for block in iter(lambda:f.read(8*1024*1024),b''):h.update(block)
|
||||
if h.hexdigest()!=expected:raise RuntimeError('Existing file mismatch: '+name)
|
||||
continue
|
||||
(root/'download-status.json').write_text(json.dumps({'phase':'downloading','file':name}))
|
||||
with urllib.request.urlopen(url,timeout=120)as r,part.open('wb')as f:
|
||||
while True:
|
||||
block=r.read(8*1024*1024)
|
||||
if not block:break
|
||||
f.write(block);h.update(block)
|
||||
if h.hexdigest()!=expected:raise RuntimeError('Checksum mismatch: '+name)
|
||||
part.replace(target);print(json.dumps({'verified':name}),flush=True)
|
||||
(root/'koboldcpp').chmod(0o755)
|
||||
(root/'download-status.json').write_text(json.dumps({'phase':'complete'}))
|
||||
(root/'manifest.json').write_text(json.dumps({'version':'1.122.1','model_revision':'36c114d8b20004a020d8192e9433a787911487bc','files':[{'path':n,'url':u,'sha256':h}for n,u,h in files]},indent=2))
|
||||
@@ -0,0 +1,53 @@
|
||||
"""Authenticated OpenAI-compatible German speech API. No request logging."""
|
||||
import hmac,io,json,os,pathlib,subprocess,threading,time,wave
|
||||
from http.server import BaseHTTPRequestHandler,ThreadingHTTPServer
|
||||
from piper import PiperVoice
|
||||
TOKEN=pathlib.Path(os.environ.get('TOKEN_FILE','/etc/athena-helper-tts/api-key')).read_text().strip()
|
||||
START=time.monotonic()
|
||||
VOICE=PiperVoice.load('/opt/athena-helper-tts/models/de_DE-thorsten-medium.onnx')
|
||||
LOAD_SECONDS=round(time.monotonic()-START,3)
|
||||
LOCK=threading.Lock()
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def log_message(self,*args): pass
|
||||
def reply(self,status,body,ctype='application/json'):
|
||||
self.send_response(status);self.send_header('Content-Type',ctype)
|
||||
self.send_header('Content-Length',str(len(body)));self.end_headers();self.wfile.write(body)
|
||||
def authorized(self):
|
||||
return hmac.compare_digest(self.headers.get('Authorization',''),'Bearer '+TOKEN)
|
||||
def do_GET(self):
|
||||
if not self.authorized(): return self.reply(401,b'{"error":"authentication required"}')
|
||||
if self.path=='/health':
|
||||
return self.reply(200,json.dumps({'status':'ok','engine':'piper','device':'cpu','voice':'thorsten','language':'de','model_load_seconds':LOAD_SECONDS}).encode())
|
||||
if self.path=='/v1/audio/voices': return self.reply(200,b'{"voices":["thorsten","alloy"]}')
|
||||
self.reply(404,b'{"error":"not found"}')
|
||||
def do_POST(self):
|
||||
if not self.authorized(): return self.reply(401,b'{"error":"authentication required"}')
|
||||
if self.path!='/v1/audio/speech': return self.reply(404,b'{"error":"not found"}')
|
||||
try:
|
||||
length=int(self.headers.get('Content-Length','0'))
|
||||
if not 0<length<=32*1024*1024: return self.reply(413,b'{"error":"JSON request must fit 32 MiB"}')
|
||||
req=json.loads(self.rfile.read(length))
|
||||
if not isinstance(req,dict) or not isinstance(req.get('input'),str) or not req['input'].strip(): raise ValueError()
|
||||
if req.get('voice','thorsten') not in ('thorsten','alloy'): return self.reply(400,b'{"error":"available voice: thorsten (alias alloy)"}')
|
||||
if req.get('language','de') not in ('de','de-DE','German','german'): return self.reply(400,b'{"error":"German voice only"}')
|
||||
if req.get('model','tts-1') not in ('tts-1','tts-1-hd','piper','de_DE-thorsten-medium'): return self.reply(400,b'{"error":"model not available"}')
|
||||
speed=float(req.get('speed',1.0))
|
||||
if not 0.25<=speed<=4.0: return self.reply(400,b'{"error":"speed must be 0.25 through 4.0"}')
|
||||
fmt=req.get('response_format','mp3')
|
||||
if fmt not in ('wav','mp3','pcm','flac','opus','aac'): return self.reply(400,b'{"error":"unsupported response_format"}')
|
||||
except (ValueError,TypeError): return self.reply(400,b'{"error":"valid JSON speech input required"}')
|
||||
try:
|
||||
from piper import SynthesisConfig
|
||||
with LOCK:
|
||||
out=io.BytesIO()
|
||||
with wave.open(out,'wb') as wav: VOICE.synthesize_wav(req['input'],wav,syn_config=SynthesisConfig(length_scale=1.0/speed))
|
||||
result=out.getvalue()
|
||||
mime={'wav':'audio/wav','mp3':'audio/mpeg','pcm':'application/octet-stream','flac':'audio/flac','opus':'audio/ogg','aac':'audio/aac'}[fmt]
|
||||
if fmt=='pcm':
|
||||
with wave.open(io.BytesIO(result)) as wav: result=wav.readframes(wav.getnframes())
|
||||
elif fmt!='wav':
|
||||
args={'mp3':['-c:a','libmp3lame','-f','mp3'],'flac':['-c:a','flac','-f','flac'],'opus':['-c:a','libopus','-f','ogg'],'aac':['-c:a','aac','-f','adts']}[fmt]
|
||||
result=subprocess.run(['/usr/bin/ffmpeg','-nostdin','-loglevel','error','-i','pipe:0',*args,'pipe:1'],input=result,stdout=subprocess.PIPE,stderr=subprocess.DEVNULL,check=True).stdout
|
||||
self.reply(200,result,mime)
|
||||
except Exception: self.reply(500,b'{"error":"speech synthesis failed"}')
|
||||
ThreadingHTTPServer((os.environ.get('LISTEN_HOST','127.0.0.1'),int(os.environ.get('LISTEN_PORT','8099'))),Handler).serve_forever()
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
[ "$(id -u)" = 0 ] || { echo 'Run as root'; exit 1; }
|
||||
base=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends python3-venv ffmpeg libvulkan1 mesa-vulkan-drivers
|
||||
getent passwd athena-tts >/dev/null || useradd --system --user-group --home-dir /var/lib/athena-helper-tts --shell /usr/sbin/nologin athena-tts
|
||||
usermod -a -G video,render athena-tts
|
||||
install -d -m 755 /opt/athena-helper-tts
|
||||
install -d -o athena-tts -g athena-tts -m 750 /var/lib/athena-helper-tts
|
||||
install -d -o root -g athena-tts -m 750 /etc/athena-helper-tts
|
||||
if [ "$base" != /opt/athena-helper-tts ]; then
|
||||
install -m 644 "$base/gateway.py" /opt/athena-helper-tts/gateway.py
|
||||
fi
|
||||
python3 "$base/restore_models.py"
|
||||
python3 -m venv /opt/athena-helper-tts/piper-venv
|
||||
/opt/athena-helper-tts/piper-venv/bin/pip install -r "$base/requirements.txt"
|
||||
python3 - <<'PY'
|
||||
import pathlib,secrets,os,pwd,grp
|
||||
p=pathlib.Path('/etc/athena-helper-tts/api-key')
|
||||
if not p.exists():
|
||||
fd=os.open(p,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0o640)
|
||||
with os.fdopen(fd,'w') as f: f.write(secrets.token_urlsafe(48)+'\n')
|
||||
os.chown(p,0,grp.getgrnam('athena-tts').gr_gid);p.chmod(0o640)
|
||||
PY
|
||||
install -m 644 "$base/athena-helper-tts.service" /etc/systemd/system/
|
||||
install -m 644 "$base/athena-helper-tts-api.service" /etc/systemd/system/
|
||||
systemctl daemon-reload
|
||||
# Do not start the slow GPU engine automatically.
|
||||
systemctl enable --now athena-helper-tts-api.service
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"version": "1.122.1",
|
||||
"model_revision": "36c114d8b20004a020d8192e9433a787911487bc",
|
||||
"files": [
|
||||
{
|
||||
"path": "koboldcpp",
|
||||
"url": "https://github.com/LostRuins/koboldcpp/releases/download/v1.122.1/koboldcpp-linux-x64-oldpc",
|
||||
"sha256": "04716cc1e871803e41b1475a4471655a8390b102086741f8d107ceda74c6cdbe"
|
||||
},
|
||||
{
|
||||
"path": "models/qwen3-tts-0.6b-f16.gguf",
|
||||
"url": "https://huggingface.co/koboldcpp/tts/resolve/36c114d8b20004a020d8192e9433a787911487bc/qwen3-tts-0.6b-f16.gguf",
|
||||
"sha256": "0b89770118463af8f2467d824a8de57d96df6a09f927a9769a3f7b7fffa7087d"
|
||||
},
|
||||
{
|
||||
"path": "models/qwen3-tts-tokenizer-f16.gguf",
|
||||
"url": "https://huggingface.co/koboldcpp/tts/resolve/36c114d8b20004a020d8192e9433a787911487bc/qwen3-tts-tokenizer-f16.gguf",
|
||||
"sha256": "d1ad9660bd99343f4851d5a4b17e31f65648feb3559f6ea062ae6575e5cd9d90"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import json,time,urllib.request,wave,io,math,array,pathlib
|
||||
root=pathlib.Path('/opt/athena-helper-tts')
|
||||
results=[]
|
||||
for n in range(2):
|
||||
data=json.dumps({'model':'tts-1','input':'Hallo Michael. Die Sprachausgabe läuft jetzt auf dem separaten Rechner. Athena bleibt dabei unverändert.','voice':'kobo','language':'de','response_format':'wav'}).encode()
|
||||
start=time.monotonic()
|
||||
with urllib.request.urlopen(urllib.request.Request('http://127.0.0.1:18099/v1/audio/speech',data=data,headers={'Content-Type':'application/json'}),timeout=300) as r:
|
||||
blob=r.read()
|
||||
elapsed=time.monotonic()-start
|
||||
(root/f'test-{n+1}.wav').write_bytes(blob)
|
||||
with wave.open(io.BytesIO(blob)) as w:
|
||||
duration=w.getnframes()/w.getframerate()
|
||||
frames=w.readframes(w.getnframes());width=w.getsampwidth()
|
||||
vals=array.array('h',frames) if width==2 else []
|
||||
row={'run':n+1,'elapsed_seconds':round(elapsed,3),'audio_seconds':round(duration,3),'real_time_factor':round(elapsed/duration,3),'bytes':len(blob),'sample_width':width,'peak':max(map(abs,vals)) if vals else None}
|
||||
results.append(row);(root/'measurements.json').write_text(json.dumps(results,indent=2));print(json.dumps(row),flush=True)
|
||||
@@ -0,0 +1,20 @@
|
||||
[
|
||||
{
|
||||
"run": 1,
|
||||
"elapsed_seconds": 30.694,
|
||||
"audio_seconds": 6.617,
|
||||
"real_time_factor": 4.639,
|
||||
"bytes": 317654,
|
||||
"sample_width": 2,
|
||||
"peak": 15140
|
||||
},
|
||||
{
|
||||
"run": 2,
|
||||
"elapsed_seconds": 24.437,
|
||||
"audio_seconds": 6.937,
|
||||
"real_time_factor": 3.523,
|
||||
"bytes": 333014,
|
||||
"sample_width": 2,
|
||||
"peak": 13404
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"revision": "c10ece1aade47bb51c153c893d14e5bf8e5b7117",
|
||||
"files": [
|
||||
{
|
||||
"path": "de_DE-thorsten-medium.onnx",
|
||||
"url": "https://huggingface.co/rhasspy/piper-voices/resolve/c10ece1aade47bb51c153c893d14e5bf8e5b7117/de/de_DE/thorsten/medium/de_DE-thorsten-medium.onnx",
|
||||
"sha256": "7e64762d8e5118bb578f2eea6207e1a35a8e0c30595010b666f983fc87bb7819"
|
||||
},
|
||||
{
|
||||
"path": "de_DE-thorsten-medium.onnx.json",
|
||||
"url": "https://huggingface.co/rhasspy/piper-voices/resolve/c10ece1aade47bb51c153c893d14e5bf8e5b7117/de/de_DE/thorsten/medium/de_DE-thorsten-medium.onnx.json",
|
||||
"sha256": "974adee790533adb273a1ac88f49027d2a1b8f0f2cf4905954a4791e79264e85"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
[
|
||||
{
|
||||
"run": 1,
|
||||
"load_seconds": 2.855,
|
||||
"elapsed_seconds": 0.76,
|
||||
"audio_seconds": 5.956,
|
||||
"real_time_factor": 0.128
|
||||
},
|
||||
{
|
||||
"run": 2,
|
||||
"load_seconds": 2.855,
|
||||
"elapsed_seconds": 0.716,
|
||||
"audio_seconds": 5.666,
|
||||
"real_time_factor": 0.126
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,7 @@
|
||||
flatbuffers==25.12.19
|
||||
numpy==2.5.4
|
||||
onnxruntime==1.31.0
|
||||
packaging==26.3
|
||||
pathvalidate==3.3.1
|
||||
piper-tts==1.4.2
|
||||
protobuf==7.36.2
|
||||
@@ -0,0 +1,25 @@
|
||||
"""Restore public artifacts only, pinned by revision and SHA256."""
|
||||
import hashlib,json,pathlib,urllib.request
|
||||
base=pathlib.Path(__file__).resolve().parent
|
||||
root=pathlib.Path('/opt/athena-helper-tts');root.mkdir(exist_ok=True)
|
||||
for manifest in ('manifest.json','piper-manifest.json'):
|
||||
for row in json.loads((base/manifest).read_text())['files']:
|
||||
name=row['path'] if manifest=='manifest.json' else 'models/'+row['path']
|
||||
target=root/name;target.parent.mkdir(exist_ok=True)
|
||||
def checksum(path):
|
||||
h=hashlib.sha256()
|
||||
with path.open('rb') as f:
|
||||
for block in iter(lambda:f.read(8*1024*1024),b''): h.update(block)
|
||||
return h.hexdigest()
|
||||
if target.exists():
|
||||
if checksum(target)!=row['sha256']:raise RuntimeError('Existing artifact differs: '+name)
|
||||
continue
|
||||
part=target.with_suffix(target.suffix+'.part')
|
||||
with urllib.request.urlopen(row['url'],timeout=120) as r,part.open('wb') as f:
|
||||
while True:
|
||||
block=r.read(8*1024*1024)
|
||||
if not block:break
|
||||
f.write(block)
|
||||
if checksum(part)!=row['sha256']:raise RuntimeError('Checksum mismatch: '+name)
|
||||
part.replace(target)
|
||||
(root/'koboldcpp').chmod(0o755)
|
||||
@@ -0,0 +1,20 @@
|
||||
"""Run synthetic probes on Helper. Read API key internally, never print it."""
|
||||
import io,json,pathlib,time,urllib.request,urllib.error,wave,subprocess
|
||||
key=pathlib.Path('/etc/athena-helper-tts/api-key').read_text().strip()
|
||||
base='http://172.21.117.203:8099'
|
||||
rows=[]
|
||||
for path in ('/health','/v1/audio/voices'):
|
||||
with urllib.request.urlopen(urllib.request.Request(base+path,headers={'Authorization':'Bearer '+key}),timeout=20) as r: rows.append({'path':path,'status':r.status,'metadata':json.load(r)})
|
||||
for path in ('/health','/tts_to_audio'):
|
||||
try: urllib.request.urlopen(base+path,timeout=20)
|
||||
except urllib.error.HTTPError as e: rows.append({'unauthenticated':path,'status':e.code})
|
||||
for fmt in ('wav','mp3'):
|
||||
data=json.dumps({'model':'tts-1','voice':'alloy','input':'Hallo Michael. Die Sprachausgabe läuft jetzt auf dem separaten Rechner. Athena bleibt dabei unverändert.','response_format':fmt}).encode()
|
||||
s=time.monotonic()
|
||||
with urllib.request.urlopen(urllib.request.Request(base+'/v1/audio/speech',data=data,headers={'Content-Type':'application/json','Authorization':'Bearer '+key}),timeout=90) as r:
|
||||
audio=r.read();ctype=r.headers.get('Content-Type')
|
||||
elapsed=time.monotonic()-s
|
||||
target=pathlib.Path('/opt/athena-helper-tts')/('api-test.'+fmt);target.write_bytes(audio)
|
||||
duration=float(subprocess.check_output(['/usr/bin/ffprobe','-v','error','-show_entries','format=duration','-of','default=noprint_wrappers=1:nokey=1',str(target)]))
|
||||
rows.append({'format':fmt,'content_type':ctype,'elapsed_seconds':round(elapsed,3),'audio_seconds':duration,'rtf':round(elapsed/duration,3),'bytes':len(audio)})
|
||||
pathlib.Path('/opt/athena-helper-tts/api-measurements.json').write_text(json.dumps(rows,indent=2));print(json.dumps(rows,indent=2))
|
||||
Reference in new issue
Block a user