"""Run inside OpenWebUI; synthetic audio only, no existing chats or user files read. Usage: python test_audio.py CONNECTION_JSON """ import asyncio from datetime import timedelta import io import json import math from pathlib import Path import struct import sys import tempfile import wave import aiohttp from starlette.requests import Request from starlette.datastructures import UploadFile, Headers from open_webui.models.users import Users from open_webui.routers.files import upload_file_handler from open_webui.utils.auth import create_token from open_webui.utils.middleware import process_tool_result from athena_audio import Tools async def main(): tool = Tools() for files in ([], [{'id': 'a', 'name': 'a.wav'}, {'id': 'b', 'name': 'b.mp3'}]): try: tool._attachment(files, '') except ValueError: pass else: raise AssertionError('Missing/ambiguous attachment accepted') assert tool._attachment([{'id': 'outer', 'file': {'id': 'stored', 'filename': 'song.wav'}}], '') == ('stored', 'song.wav') user = next(u for u in (await Users.get_users())['users'] if u.role == 'admin') token = create_token({'id': user.id}, timedelta(minutes=10)) request = Request({'type': 'http', 'method': 'POST', 'path': '/', 'headers': []}) data = io.BytesIO() with wave.open(data, 'wb') as audio: audio.setnchannels(2);audio.setsampwidth(2);audio.setframerate(44100) audio.writeframes(b''.join(struct.pack('