# Authentication

Diese API ermöglicht das Erstellen von angepassten Song-Covern mittels KI. Der Benutzer kann den Originalsong, die Zielstimme und die Tonhöhe spezifizieren. Der Endpunkt nutzt WebSockets für Echtzeit-Kommunikation.

# Endpoint URL

VC_URI = wss://voiceshiftde.site:8765

# Authentifizierung

Um die Kommunikation zu starten, ist eine Authentifizierung notwendig. Hierfür muss ein JSON-String mit dem API-Token gesendet werden.

# Authentifizierungsanfrage

import websockets
import json
import asyncio
from dotenv import load_env
import os

load_dotenv()

VC_URI = os.load.env('VC_URI')

async def connect_and_authenticate():
    uri = VC_URI
    
    async with websockets.connect(uri) as websocket:
        auth_request = await websocket.recv()
        auth_request_data = json.loads(auth_request)

        if auth_request_data.get("type") != "auth_required":
            raise ValueError("Unerwartete Antwort vom Server")

        auth_data = {"token": "YOUR_API_TOKEN"}
        await websocket.send(json.dumps(auth_data))

        auth_response = await websocket.recv()
        auth_response_data = json.loads(auth_response)

        if auth_response_data.get("type") != "auth_success":
            raise PermissionError("Authentifizierung fehlgeschlagen. Überprüfen Sie Ihren API-Token.")

        print("Authentifizierung erfolgreich")
        return websocket

async def main():
    websocket = await connect_and_authenticate()
    # Hier können Sie weitere Aktionen mit dem authentifizierten WebSocket durchführen

asyncio.get_event_loop().run_until_complete(main())
const WebSocket = require('ws');

function connectAndAuthenticate() {
    return new Promise((resolve, reject) => {
        const ws = new WebSocket("wss://voiceshiftde.site:8765");

        ws.on('open', function open() {
            console.log('WebSocket-Verbindung hergestellt');
        });

        ws.on('message', function incoming(data) {
            const message = JSON.parse(data);
            
            if (message.type === "auth_required") {
                const authData = { token: "YOUR_API_TOKEN" };
                ws.send(JSON.stringify(authData));
            } else if (message.type === "auth_success") {
                console.log("Authentifizierung erfolgreich");
                resolve(ws);
            } else {
                reject(new Error("Unerwartete Antwort vom Server"));
            }
        });

        ws.on('error', function error(err) {
            reject(err);
        });
    });
}

// Beispiel für die Verwendung
connectAndAuthenticate()
    .then(websocket => {
        // REQUEST
    })
    .catch(error => {
        console.error('Fehler bei der Authentifizierung:', error);
    });

# Authentifizierungsantwort

  • Bei Erfolg: {"type":"auth_success"}
  • Bei Misserfolg: WebSocket wird mit Statuscode 4001 (Unauthorized) geschlossen.

# Song-Cover-Anfrage

# Request-Typen

  • cover: Startet die Erstellung eines Song-Covers.