Files
ESP32_ZACUS/plip_voice/main/turn_client.h
T
clement aa7ae277ed
CI / platformio (pull_request) Failing after 4m0s
CI / platformio (push) Failing after 14m58s
feat(plip): voice loop + DTMF + ring cadence
- hook polarity active-HIGH + auto-resync (was LOW)
- ring cadence FT 1.5s ON / 3.5s OFF
- DTMF Goertzel decoder (dtmf.c/h) + rotary debounce
- LISTEN half-duplex: capture → /v1/voice/reply → play
- WAV playback buffered PSRAM + mono→stereo upmix
- SPIFFS mount at boot for pre-loaded greetings
- ES8388: DAC digital vol + mic PGA + GPIO INPUT_OUTPUT
- turn_client multipart + 90s timeout + fixed routing
- debug endpoints: vol/dacvol/offhook/getfile/hookmon
2026-06-15 21:12:33 +02:00

67 lines
2.2 KiB
C

#pragma once
/*
* turn_client.h — POST /v1/voice/turn to the NPC gateway and retrieve a WAV response.
*
* Stage 2: greeting fetch (kind="greeting").
* Stage 3: reply fetch via /v1/voice/reply (multipart/form-data with captured WAV).
*/
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* turn_client_greeting — POST /v1/voice/turn with kind="greeting".
*
* Sends: { "session_id": session_id, "number": number, "kind": "greeting" }
* Bearer: CONFIG_PLIP_GATEWAY_TOKEN (skipped if empty)
* URL: CONFIG_PLIP_GATEWAY_URL/v1/voice/turn
*
* On success (HTTP 200, body > 44 bytes written to out_path):
* - Streams the binary WAV response into fopen(out_path, "wb").
* - Returns true.
*
* On failure (network error, non-200, short body):
* - Logs a warning and returns false.
* - Does not crash; caller may proceed silently.
*/
bool turn_client_greeting(const char *session_id,
const char *number,
const char *out_path);
/*
* turn_client_reply — POST /v1/voice/reply as multipart/form-data.
*
* Endpoint: CONFIG_PLIP_GATEWAY_URL/v1/voice/reply
* Method: POST multipart/form-data
* Fields: session_id (text), number (text), audio (file, "rec.wav", audio/wav)
* Bearer: CONFIG_PLIP_GATEWAY_TOKEN (skipped if empty)
*
* The function builds the multipart body in three segments:
* preamble = boundary + session_id part + boundary + number part +
* boundary + audio file header
* wav data = wav bytes (wav_len bytes, sent in 4 KB chunks)
* epilogue = CRLF + closing boundary
*
* Content-Length = len(preamble) + wav_len + len(epilogue)
* The response body (WAV 16 kHz) is streamed into out_path.
*
* Response headers X-Zacus-Heard and X-Zacus-Said are logged at INFO level.
*
* Returns ESP_OK if HTTP 200 and a valid WAV (> 44 bytes) was written.
* On any failure: logs a warning and returns an ESP error code.
*/
esp_err_t turn_client_reply(const char *session_id,
const char *number,
const uint8_t *wav,
size_t wav_len,
const char *out_path);
#ifdef __cplusplus
}
#endif