diff --git a/docs/experiments/hermes-voice-2026-10-17/README.md b/docs/experiments/hermes-voice-2026-10-17/README.md index e634d7a..5bd818f 100644 --- a/docs/experiments/hermes-voice-2026-10-17/README.md +++ b/docs/experiments/hermes-voice-2026-10-17/README.md @@ -137,3 +137,37 @@ require reviewing/retesting the insertion. To remove the adaptation, remove its startup block and recreate from the pristine upstream image (a simple restart retains modified image-layer files). This remains an optional Docker UI integration; no claim of a native fresh-Debian full restore test is made. + +## Anna reference activation and invalid production-performance inference + +User authorized using Anna or any female voice. A private 12-second excerpt of +existing `legacy-userdata/voice-profiles/Anna.wav` was prepared and transcribed +locally. Audio/transcript are NOT in Git. `speech-voices/Anna/reference.wav` +and `reference.json` plus `speech-voices/default.json` now identify Anna. +The endpoint resolves the saved reference on every OmniVoice request and passes +identical audio/transcript plus seed 42 to the existing backend. Invalid names, +missing/corrupt audio/transcripts and linked reference files fail closed. +Unconfigured installations preserve the previous default behavior. + +Eleven isolated tests passed: eight stored-reference cases, repeated HTTP TTS +calls forwarding the same reference, WAV publication and MP3 negotiation. +Activated image `athena-deck-standalone:strata-0.1.45-anna-20261017` after idle +checks. Activation confirmed selected settings and Strata recipe unchanged and +Deck ready; no previous LLM was loaded. Real Anna generation/playback is NOT yet +accepted. The user challenged the performance-test design during activation; +no subsequent performance run was started. + +**Correction:** the 1.23-second test was GPU OmniVoice with Strata unloaded. +A read-only NVIDIA sample showed OmniVoice about 2870 MiB on RTX 5080 and no +Strata compute process. It is not evidence that OmniVoice fits or performs well +alongside the production Strata profile. CPU performance and coexistence are +unmeasured. Earlier standalone speech success must not be advertised as solving +TTS during Strata operation. + +Restore must preserve the private `speech-voices` tree including its alias, +reference and transcript, with restricted ownership/permissions. The endpoint +change is ordinary Python and has no new native Debian dependency beyond the +existing OmniVoice/FFmpeg stack. Current config-only backup does not include +these recordings automatically; include this tree in the encrypted complete +state backup. Automated reference-management UI, backup integration and a +fresh-host full restore test remain open. Do not claim complete backup coverage. diff --git a/endpoint.py b/endpoint.py index cb18040..be767f8 100644 --- a/endpoint.py +++ b/endpoint.py @@ -38,6 +38,35 @@ def speech_mp3(wav): if result.returncode or not result.stdout:raise APIError('Sprachausgabe konnte nicht als MP3 kodiert werden.',503,'audio_encoding_failed') return result.stdout + +def speech_reference(root, name): + """Resolve operator-installed local OmniVoice speakers; never client paths.""" + folder = Path(root) / 'speech-voices' + try: + if name == 'default': + default = folder / 'default.json' + if not default.exists(): + return {} + name = json.loads(default.read_text())['voice'] + if not isinstance(name, str) or not re.fullmatch(r'[A-Za-z0-9_-]{1,64}', name): + raise ValueError('invalid speaker') + voice = folder / name + # References and transcripts must stay inside the private state folder. + for path in (voice, voice / 'reference.wav', voice / 'reference.json'): + if path.is_symlink(): + raise ValueError('linked speaker') + metadata = json.loads((voice / 'reference.json').read_text()) + text = metadata['text'] + if not isinstance(text, str) or not 1 <= len(text.strip()) <= 64000: + raise ValueError('invalid transcript') + audio_path = voice / 'reference.wav' + if not 0 < audio_path.stat().st_size <= 20 * 1024**2: + raise ValueError('invalid reference size') + from voxcpm_test import validate_reference + return dict(reference=validate_reference(audio_path.read_bytes()), reference_text=text, seed=42) + except (OSError, ValueError, KeyError, TypeError): + raise APIError('Gespeicherte TTS-Stimme fehlt oder ist ungültig.', 400, 'invalid_speech_voice') from None + def chat_upstream_error(status, raw, runtime=None): """Translate verified error formats; never echo arbitrary upstream text.""" backend = {'strata': 'Strata', 'llama': 'llama.cpp'}.get(runtime, 'Modell-Backend') @@ -440,8 +469,9 @@ class APIHandler(BaseHTTPRequestHandler): profile=ep.find_profile(data.get('model'),voice['kind']);backend=ep.voxcpm profile_seconds=time.monotonic()-started omni=profile['model']['repo']=='k2-fsa/OmniVoice' - if data.get('voice','default')!='default' or (not omni and data.get('speed',1)!=1):raise APIError('voice=default verwenden; VoxCPM2 unterstützt hier speed=1. Referenzstimme im Deck-Testbereich.') - try:job=backend.start(profile['id'],data.get('input'),steps=32 if omni else 10,**(dict(speed=data.get('speed',1),language=data.get('language','')) if omni else {}),wait=True) + if not omni and (data.get('voice','default')!='default' or data.get('speed',1)!=1):raise APIError('voice=default verwenden; VoxCPM2 unterstützt hier speed=1. Referenzstimme im Deck-Testbereich.') + reference=speech_reference(ep.root,data.get('voice','default')) if omni else {} + try:job=backend.start(profile['id'],data.get('input'),steps=32 if omni else 10,**(dict(speed=data.get('speed',1),language=data.get('language','')) if omni else {}),**reference,wait=True) except InferenceError as exc:raise APIError(str(exc),503,'tts_resources_unavailable') from None except ValueError as exc:raise APIError(str(exc)) from None else: diff --git a/test_endpoint.py b/test_endpoint.py index b208d46..75a2cfb 100644 --- a/test_endpoint.py +++ b/test_endpoint.py @@ -310,6 +310,18 @@ class EndpointTests(unittest.TestCase): c=http.client.HTTPConnection('127.0.0.1',self.port,timeout=5);c.request('POST','/v1/audio/speech',json.dumps({'model':'audio','input':'hello','language':'English'}),{'Content-Type':'application/json','Authorization':'Bearer '+'A'*32});r=c.getresponse() self.assertEqual(r.status,200);self.assertEqual(r.read(),b'RIFF-test-WAVE');c.close() self.assertEqual(self.ep.tts.start.call_args.kwargs['language'],'English') + def test_omnivoice_reference_is_forwarded_for_every_request(self): + from unittest.mock import patch + self.rows.append(dict(id='omni',name='omni',kind='voice',revision=1,updated_at=1,runnable=True,blockers=[],parameters={},model=dict(kind='voice',repo='k2-fsa/OmniVoice',file='model.safetensors'))) + self.enable('omni');self.ep.tts=Mock();self.ep.voxcpm=Mock();backend=self.ep.voxcpm + backend.start.return_value={'id':'a'*32};backend.status.return_value={'job':{'id':'a'*32,'state':'complete'}};backend.job_status.return_value=None;backend.audio.return_value=b'RIFF-test-WAVE' + reference=dict(reference=b'reference-wav',reference_text='Synthetic reference.',seed=42) + with patch('endpoint.speech_reference',return_value=reference) as stored: + for text in ('Erster Satz.','Zweiter Satz.'): + c=http.client.HTTPConnection('127.0.0.1',self.port,timeout=5);c.request('POST','/v1/audio/speech',json.dumps(dict(model='omni',input=text,voice='Anna')),{'Authorization':'Bearer '+'A'*32,'Content-Type':'application/json'}) + response=c.getresponse();self.assertEqual(response.status,200);self.assertEqual(response.read(),b'RIFF-test-WAVE');c.close() + self.assertEqual(backend.start.call_args.kwargs['reference'],reference['reference']);self.assertEqual(backend.start.call_args.kwargs['reference_text'],reference['reference_text']);self.assertEqual(backend.start.call_args.kwargs['seed'],42) + self.assertEqual(stored.call_count,2) def test_tts_mp3_explicit_and_hermes_accept_header(self): from unittest.mock import patch self.rows[-1].update(runnable=True,blockers=[]);self.enable('audio') diff --git a/test_speech_reference.py b/test_speech_reference.py new file mode 100644 index 0000000..2e62071 --- /dev/null +++ b/test_speech_reference.py @@ -0,0 +1,36 @@ +"""Stored speaker identity survives independent TTS calls; bad names fail closed.""" +import io,json,tempfile,unittest,wave +from pathlib import Path +from endpoint import speech_reference,APIError + +class SpeechReferenceTests(unittest.TestCase): + def setUp(self): + self.tmp=tempfile.TemporaryDirectory();self.addCleanup(self.tmp.cleanup) + self.root=Path(self.tmp.name);self.folder=self.root/'speech-voices';self.voice=self.folder/'Anna';self.voice.mkdir(parents=True) + b=io.BytesIO() + with wave.open(b,'wb') as w:w.setnchannels(1);w.setsampwidth(2);w.setframerate(24000);w.writeframes(b'\0\0'*48000) + (self.voice/'reference.wav').write_bytes(b.getvalue());(self.voice/'reference.json').write_text(json.dumps({'text':'Synthetischer Test.'})) + (self.folder/'default.json').write_text(json.dumps({'voice':'Anna'})) + def test_same_identity_across_independent_calls(self): + first=speech_reference(self.root,'default');second=speech_reference(self.root,'Anna') + self.assertEqual(first,second);self.assertEqual(first['reference_text'],'Synthetischer Test.');self.assertEqual(first['seed'],42) + def test_unconfigured_default_preserves_previous_behavior(self): + (self.folder/'default.json').unlink();self.assertEqual(speech_reference(self.root,'default'),{}) + def test_names_cannot_escape(self): + for name in ('../Anna','/tmp/Anna','',None,{},'Anna/reference.wav'): + with self.subTest(name=name),self.assertRaises(APIError):speech_reference(self.root,name) + def test_missing_voice(self): + with self.assertRaises(APIError):speech_reference(self.root,'Missing') + def test_corrupt_default(self): + (self.folder/'default.json').write_text('null') + with self.assertRaises(APIError):speech_reference(self.root,'default') + def test_corrupt_audio(self): + (self.voice/'reference.wav').write_bytes(b'not audio') + with self.assertRaises(APIError):speech_reference(self.root,'Anna') + def test_transcript_required(self): + (self.voice/'reference.json').write_text('{"text":""}') + with self.assertRaises(APIError):speech_reference(self.root,'Anna') + def test_symlink_rejected(self): + (self.voice/'reference.wav').unlink();(self.voice/'reference.wav').symlink_to('/etc/passwd') + with self.assertRaises(APIError):speech_reference(self.root,'Anna') +if __name__=='__main__':unittest.main()