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
import asyncio
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.2.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.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tap_sdk_py-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 f2879ba15bcab3ef7535f8e99967ef1910249deb6ed1c88d737d5aa55233d51c
MD5 7de57096d93080c29ebd0419a84a346d
BLAKE2b-256 d08dc31c07d5d0b7d072575c5cd9dd6eb7c4a5fc4c5c8a9758899f653a5cdd2c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tap_sdk_py-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3833dedf9b6ec48dd5d1353f14486578ce8eb9ddbe492586aff82515f15efa48
MD5 337b1e46ffc1abb477ca7603551dbd9d
BLAKE2b-256 894a2eb0dc1ea61541caf867ad56ebfdd8d78964b91d09042fce501ea5346c58

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