diff --git a/integrations/openwebui/README.md b/integrations/openwebui/README.md index 32c9e5e..baa70fa 100644 --- a/integrations/openwebui/README.md +++ b/integrations/openwebui/README.md @@ -86,6 +86,21 @@ die Kombination mit allen vorhandenen Modellprompts ohne Modellgenerierung. Offizielle Grundlage: [OpenWebUI Default Interface Settings](https://docs.openwebui.com/features/administration/interface-defaults/). +## Athena-Spracherkennung und Sprachausgabe + +`install_speech.py` verbindet innerhalb des OpenWebUI-Containers die beiden +OpenAI-kompatiblen Audioanbieter mit der vorhandenen Athena-Verbindung. +Der bestehende API-Key wird intern wiederverwendet und nicht ausgegeben. +Die Profile werden vor der Änderung über ihre jeweiligen Modelllisten geprüft: + +- STT: `qwen3-asr-stt`, Multipart-Anfragen an `/v1/audio/transcriptions`. +- TTS: `qwen-tts`, Stimme `Ryan`, `response_format=wav` an `/v1/audio/speech`. +- Satzweise Wiedergabe: `SPLIT_ON=punctuation`. + +Andere Audioeinstellungen bleiben erhalten. Die Installation prüft anschließend +die gespeicherten Einstellungen; sie führt keinen GPU-Auftrag und keinen echten +Mikrofontest durch. Kein Containerneustart erforderlich. Browser neu laden. + ## To-do - [ ] Beim Audio-Upload zwischen „Audio bearbeiten/trennen“ (direkt bereitstellen, diff --git a/integrations/openwebui/install_speech.py b/integrations/openwebui/install_speech.py new file mode 100644 index 0000000..a13c9d4 --- /dev/null +++ b/integrations/openwebui/install_speech.py @@ -0,0 +1,62 @@ +"""Connect OpenWebUI audio to the existing Athena API without exporting keys.""" +import asyncio +from datetime import timedelta +import json + +import aiohttp +from open_webui.models.config import Config +from open_webui.models.users import Users +from open_webui.utils.auth import create_token + + +async def main(): + urls = await Config.get('openai.api_base_urls') or [] + keys = await Config.get('openai.api_keys') or [] + configs = await Config.get('openai.api_configs') or {} + candidates = [(i, url) for i, url in enumerate(urls) if '192.168.1.212:8120' in url] + if len(candidates) != 1: + raise RuntimeError('Athena connection is not uniquely identified') + index, url = candidates[0] + connection = configs.get(str(index)) or configs.get(url) or {} + key = connection.get('key') or keys[index] + admins = [u for u in (await Users.get_users())['users'] if u.role == 'admin'] + if len(admins) != 1: + raise RuntimeError('Expected one administrator') + token = create_token({'id': admins[0].id}, timedelta(minutes=5)) + async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=30)) as session: + for route, expected in [('speech', 'qwen-tts'), ('transcriptions', 'qwen3-asr-stt')]: + async with session.get(url.rstrip('/') + '/audio/' + route + '/models', + headers={'Authorization': 'Bearer ' + key}) as response: + response.raise_for_status() + listing = await response.json() + if expected not in [m['id'] for m in listing['data']]: + raise RuntimeError('Required speech profile is not exposed') + headers = {'Authorization': 'Bearer ' + token} + base = 'http://127.0.0.1:8080/api/v1/audio' + async with session.get(base + '/config', headers=headers) as response: + response.raise_for_status() + config = await response.json() + config['tts'].update(ENGINE='openai', OPENAI_API_BASE_URL=url.rstrip('/'), + OPENAI_API_KEY=key, MODEL='qwen-tts', VOICE='Ryan', SPLIT_ON='punctuation') + config['tts']['OPENAI_PARAMS'] = {**(config['tts'].get('OPENAI_PARAMS') or {}), + 'response_format': 'wav'} + config['stt'].update(ENGINE='openai', OPENAI_API_BASE_URL=url.rstrip('/'), + OPENAI_API_KEY=key, MODEL='qwen3-asr-stt', OPENAI_API_REQUEST_FORMAT='multipart') + async with session.post(base + '/config/update', headers=headers, json=config) as response: + response.raise_for_status() + await response.json() + async with session.get(base + '/config', headers=headers) as response: + response.raise_for_status() + saved = await response.json() + for section in ('tts', 'stt'): + for field in ('ENGINE', 'MODEL', 'OPENAI_API_BASE_URL', 'OPENAI_API_KEY'): + assert saved[section][field] == config[section][field] + assert saved['tts']['OPENAI_PARAMS']['response_format'] == 'wav' + assert saved['tts']['VOICE'] == 'Ryan' + assert saved['tts']['SPLIT_ON'] == 'punctuation' + print(json.dumps({'tts': saved['tts']['MODEL'], 'stt': saved['stt']['MODEL'], + 'format': 'wav', 'voice': 'Ryan', 'verified': True})) + + +if __name__ == '__main__': + asyncio.run(main())