Skip to main content

Zako tap server sdk for python

Project description

Logo

Zako Tap SDK py

This is the python sdk package required to create a python tap server responsible for the audio of zako, a discord audio bot.

Requirements

package version
eventemitter 0.2.0
requests 2.32.4
websockets 15.0.1

Quickstart Example

First, you need to download tap-sdk-py on your project.

pip install tap-sdk-py

Then, you can use the sdk. Here is some example.

import io
from zakotap import Client, ClientData, HelloResponse, AudioRequest

streamFile = io.BytesIO(b"test audio data")

clientData: ClientData = {
    "name": "your tap name",
    "token": "your tap token",
    "zakoEndpoint": "zako endpoint (default is https://api.zako.ac)"
}

client = Client(clientData)

def on_ready(data: HelloResponse):
    print("Client is ready. Connected Tab Hub version", data.get("version"))

def on_close(message: str):
    print("Connection closed:", message)

def on_warn(message: str):
    print("Warning:", message)

def on_error(message: str):
    print("Error:", message)

def on_audio_sync(audio_request: AudioRequest):
    print("Audio")
    loop = asyncio.get_event_loop()
    task = loop.create_task(on_audio(audio_request))

async def on_audio(audio_request: AudioRequest):
    print("Received audio request:", audio_request, flush = True)
    await client.send(audio_request.get("id"), streamFile)

client.on("warn", on_warn)
client.on("error", on_error)
client.on("ready", on_ready)
client.on("close", on_close)
client.on("audio", on_audio_sync)

client.connect()

Client Description

1. Create Client and Connect

You can create tap server client by call Client class in zakotap package.

You should put the client data written as ClientData type inside the parentheses of Client.

You can then connect to the tab server using client.connect().

from zakotap import Client, ClientData

clientData: ClientData = {
    "name": "your tap server name",
    "token": "your tap server token",
    "zakoEndpoint": "zako tap hub endpoint (option)"
}

client = Client(clientData)

client.connect()

2. Client Event

Using the client created above, you can use client.on to perform a specific function when the EventEmitter's event is called.

client.on("event name", function)

The types of events are specified in EmitterEvents among the types in the zakotap package.

Emitter Events

  • "ready": This event is called when the zako tap server successfully connects to the zako tap hub.
  • "close": This event is called when the web socket between the zako tap server and tap hub is closed.
  • "audio": This event is called when an audio request is received from the zako tap hub.
  • "warn": This event is called when a warning occurs within the zakotap package that should notify the developer.
  • "error": This event is called when an error occurs within the zakotap package.

3. Send Audio

You can send your audio stream by using client.send() function. You need to put id which you got from the audio request and then you can put your stream file. Also, you should use await to call this function. If not, zakotap package will call warn event to alert it.

await client.send(audio_request.get("id"), "your audio stream")

If you don't send an audio stream, your tap server will be considered offline and you may be disconnected.

Work Flow

sequenceDiagram
    participant TapServer
    participant TapHub

    TapServer->>TapHub: WS TapHello
    TapHub-->>TapServer: WS TapResponse
    Note right of TapServer: Waiting for audio request
    TapHub-->>TapServer: WS AudioRequest
    TapServer->>TapHub: POST AudioStream

Related Documents

Authors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tap_sdk_py-1.0.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tap_sdk_py-1.0.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file tap_sdk_py-1.0.1.tar.gz.

File metadata

  • Download URL: tap_sdk_py-1.0.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for tap_sdk_py-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f8553f284f67be235b6d9f61c52446c1dbfe181bd3b639ea9ed5dfc5c7ddb666
MD5 d8d2af948cd593a0435ad6e62bdbd538
BLAKE2b-256 700814804aaa3e80ca5e4476951cd7e309c9b58ff68937cabd0767b2cd9eb75d

See more details on using hashes here.

File details

Details for the file tap_sdk_py-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: tap_sdk_py-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for tap_sdk_py-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97ad2f53824ba9c720bc003c637f5696e865742161d1de39824dc2ebf25a927a
MD5 52d8a7098faa414e488bcd2cd0528b5e
BLAKE2b-256 e79e493ed94fe5ad1807f68fec4dee2afa1e73c7434a8296becb251e6368b654

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page