kiosk-c library is a C99 client for the Humain Kiosk Device API. It requires
libcurl >= 7.68.0 and provides both blocking and streaming message APIs.
Source and prebuilt binaries: github.com/humain/kiosk-c
Build and install
Dependencies
Dependencies
libkiosk and libcurl:
Minimal complete example
Streaming example
Error handling
kiosk_config_t fields
Device API credential in the form
hk_live_XXXXXXXXXXXXXXXXXX (production) or
hk_test_XXXXXXXXXXXXXXXXXX (sandbox — see Sandbox mode). Read
from an environment variable — never hard-code in source files.Override the API base URL. There is no separate sandbox host — sandbox behavior comes from
using an
hk_test_ credential against this same URL. Leave as NULL unless you’re pointing
at a self-hosted deployment.HTTP request timeout in milliseconds. Set to
0 to use the default (30 000 ms).
Streaming requests use this timeout per chunk, not for the entire stream.Maximum number of automatic retries for
KIOSK_ERR_NETWORK and KIOSK_ERR_TIMEOUT errors.
Retries use exponential back-off with jitter capped at 30 seconds. Set to 0 to disable
automatic retries.When non-zero, routes all requests to the sandbox endpoint regardless of
base_url. Sandbox
responses are instant and consume no AI credits.Error codes
Voice sessions
Voice session functions are only available when built with
-DKIOSK_WITH_VOICE=ON.
They are not available on FreeRTOS or Zephyr targets.kiosk_voice_config_t fields
Audio capture callback. Called from the library’s internal audio thread at
frame_ms
intervals. Fill the provided buffer with 16-bit signed PCM (16 kHz, mono) and return
the number of frames written.Must be real-time safe — no heap allocation, no blocking mutex calls, no stdio.
Any violation causes audio glitches and WebRTC packet loss.Audio playback callback. Called with synthesised speech PCM received from the AI.
Write the provided samples to your speaker hardware.
Voice activity detection callback. Called with
speaking = 1 on speech onset and
speaking = 0 on silence detection. Use for UI feedback — for example, showing a
“listening” indicator. Pass NULL to disable.Lifecycle event callback. Called on transitions between
KIOSK_VOICE_CONNECTING,
KIOSK_VOICE_LISTENING, KIOSK_VOICE_PROCESSING, KIOSK_VOICE_SPEAKING, and
KIOSK_VOICE_ENDED. Pass NULL to disable.Audio sample rate in Hz. Must match your audio hardware. Gemini Live performs best
at 16 000 Hz or 48 000 Hz.
Capture frame duration in milliseconds. Determines how often
capture_fn is invoked.
20 ms is the standard WebRTC frame size.ALSA example
Complete voice session using the built-in ALSA helper (-DKIOSK_WITH_ALSA=ON):
Custom audio hardware
For teams not using ALSA — implementcapture_fn and playback_fn directly for your
platform’s audio driver:
Audio thread requirements
Audio thread requirements
The capture callback runs on an internal real-time audio thread. It must complete
within
frame_ms (default 20 ms). Violations cause audio glitches and WebRTC packet
loss.Requirements:- No dynamic memory allocation (
malloc,free,new) - No blocking mutex calls
- No stdio (
printf,fwrite)
buf — the copy should take under 1 ms.For USB audio: use ALSA’s snd_pcm_readi with a pre-allocated buffer. Set the
capture thread to SCHED_FIFO priority to avoid scheduler jitter.ICE and NAT traversal
ICE and NAT traversal
The library uses STUN to discover the device’s public address. The default STUN server
is Google’s public STUN (
stun.l.google.com:19302).No TURN server is required in most network configurations — the Humain Kiosk platform
handles the server-side connectivity. If the device is behind a symmetric NAT, contact
support@humain.ai to enable TURN relay credentials for
your workspace.Memory model
Memory model
Memory model
Client and session handles — the library allocates these internally.
kiosk_client_destroy() frees the client; kiosk_session_close() frees the session.
Never free these pointers yourself.Response buffers — for kiosk_session_message(), the caller provides a stack- or
heap-allocated buffer. The library writes the NUL-terminated response into it and never
allocates additional memory for the response. If the response does not fit,
KIOSK_ERR_OUT_OF_MEMORY is returned and the buffer contains a partial response.Recommended buffer sizes:Streaming —
kiosk_session_stream() allocates only a small internal CURL write buffer.
The chunk pointer passed to your callback is valid only for the duration of that callback
invocation; copy it if you need to retain the data.kiosk_config_t — the struct is copied by kiosk_client_create(). You may free or
reuse the config struct immediately after that call returns. The credential and base_url
strings are copied — you do not need to keep them alive.Thread safety
Thread safety
Thread safety
To handle concurrent conversations, open one session per conversation (not one session per
thread). Multiple sessions can be open simultaneously on a single client.
kiosk_session_stream() is safe to cancel from another thread by returning a non-zero value
from the callback — but the callback itself is always invoked on the thread that called
kiosk_session_stream().