#ifndef TRANSCRIBE_H
#define TRANSCRIBE_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define TRANSCRIBE_VERSION_MAJOR 0
#define TRANSCRIBE_VERSION_MINOR 0
#define TRANSCRIBE_VERSION_PATCH 5
#define TRANSCRIBE_VERSION_STRINGIZE_(x) #x
#define TRANSCRIBE_VERSION_STRINGIZE(x) TRANSCRIBE_VERSION_STRINGIZE_(x)
#define TRANSCRIBE_VERSION \
TRANSCRIBE_VERSION_STRINGIZE(TRANSCRIBE_VERSION_MAJOR) "." \
TRANSCRIBE_VERSION_STRINGIZE(TRANSCRIBE_VERSION_MINOR) "." \
TRANSCRIBE_VERSION_STRINGIZE(TRANSCRIBE_VERSION_PATCH)
#define TRANSCRIBE_VERSION_NUMBER \
(TRANSCRIBE_VERSION_MAJOR * 10000 + TRANSCRIBE_VERSION_MINOR * 100 + TRANSCRIBE_VERSION_PATCH)
#ifndef TRANSCRIBE_API
# if defined(_WIN32) && !defined(__GNUC__)
# if defined(TRANSCRIBE_STATIC)
# define TRANSCRIBE_API
# elif defined(TRANSCRIBE_BUILD)
# define TRANSCRIBE_API __declspec(dllexport)
# else
# define TRANSCRIBE_API __declspec(dllimport)
# endif
# else
# define TRANSCRIBE_API __attribute__((visibility("default")))
# endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
TRANSCRIBE_OK = 0,
TRANSCRIBE_ERR_INVALID_ARG = 1,
TRANSCRIBE_ERR_NOT_IMPLEMENTED = 2,
TRANSCRIBE_ERR_FILE_NOT_FOUND = 3,
TRANSCRIBE_ERR_GGUF = 4,
TRANSCRIBE_ERR_UNSUPPORTED_ARCH = 5,
TRANSCRIBE_ERR_UNSUPPORTED_VARIANT = 6,
TRANSCRIBE_ERR_OOM = 7,
TRANSCRIBE_ERR_BACKEND = 8,
TRANSCRIBE_ERR_SAMPLE_RATE = 9,
TRANSCRIBE_ERR_UNSUPPORTED_LANGUAGE = 10,
TRANSCRIBE_ERR_UNSUPPORTED_TASK = 11,
TRANSCRIBE_ERR_UNSUPPORTED_TIMESTAMPS = 12,
TRANSCRIBE_ERR_ABORTED = 13,
TRANSCRIBE_ERR_BAD_STRUCT_SIZE = 14,
TRANSCRIBE_ERR_UNSUPPORTED_PNC = 15,
TRANSCRIBE_ERR_UNSUPPORTED_ITN = 16,
TRANSCRIBE_ERR_INPUT_TOO_LONG = 17,
TRANSCRIBE_ERR_OUTPUT_TRUNCATED = 18,
} transcribe_status;
TRANSCRIBE_API const char * transcribe_status_string(int status);
TRANSCRIBE_API const char * transcribe_version(void);
TRANSCRIBE_API const char * transcribe_version_commit(void);
typedef enum {
TRANSCRIBE_ABI_MODEL_LOAD_PARAMS = 0,
TRANSCRIBE_ABI_SESSION_PARAMS = 1,
TRANSCRIBE_ABI_RUN_PARAMS = 2,
TRANSCRIBE_ABI_STREAM_PARAMS = 3,
TRANSCRIBE_ABI_CAPABILITIES = 4,
TRANSCRIBE_ABI_TIMINGS = 5,
TRANSCRIBE_ABI_SEGMENT = 6,
TRANSCRIBE_ABI_WORD = 7,
TRANSCRIBE_ABI_TOKEN = 8,
TRANSCRIBE_ABI_STREAM_UPDATE = 9,
TRANSCRIBE_ABI_STREAM_TEXT = 10,
TRANSCRIBE_ABI_SESSION_LIMITS = 11,
TRANSCRIBE_ABI_EXT = 12,
TRANSCRIBE_ABI_BACKEND_DEVICE = 13,
} transcribe_abi_struct;
TRANSCRIBE_API size_t transcribe_abi_struct_size(transcribe_abi_struct which);
TRANSCRIBE_API size_t transcribe_abi_struct_align(transcribe_abi_struct which);
typedef enum {
TRANSCRIBE_LOG_LEVEL_NONE = 0,
TRANSCRIBE_LOG_LEVEL_INFO = 1,
TRANSCRIBE_LOG_LEVEL_WARN = 2,
TRANSCRIBE_LOG_LEVEL_ERROR = 3,
TRANSCRIBE_LOG_LEVEL_DEBUG = 4,
TRANSCRIBE_LOG_LEVEL_CONT = 5,
} transcribe_log_level;
typedef void (*transcribe_log_callback)(
transcribe_log_level level,
const char * msg,
void * userdata);
TRANSCRIBE_API void transcribe_log_set(transcribe_log_callback cb, void * userdata);
typedef enum {
TRANSCRIBE_TASK_TRANSCRIBE = 0,
TRANSCRIBE_TASK_TRANSLATE = 1,
} transcribe_task;
typedef enum {
TRANSCRIBE_TIMESTAMPS_NONE = 0,
TRANSCRIBE_TIMESTAMPS_AUTO = 1,
TRANSCRIBE_TIMESTAMPS_SEGMENT = 2,
TRANSCRIBE_TIMESTAMPS_WORD = 3,
TRANSCRIBE_TIMESTAMPS_TOKEN = 4,
} transcribe_timestamp_kind;
typedef enum {
TRANSCRIBE_KV_TYPE_AUTO = 0,
TRANSCRIBE_KV_TYPE_F32 = 1,
TRANSCRIBE_KV_TYPE_F16 = 2,
} transcribe_kv_type;
enum transcribe_pnc_mode {
TRANSCRIBE_PNC_MODE_DEFAULT = 0,
TRANSCRIBE_PNC_MODE_OFF = 1,
TRANSCRIBE_PNC_MODE_ON = 2,
};
enum transcribe_itn_mode {
TRANSCRIBE_ITN_MODE_DEFAULT = 0,
TRANSCRIBE_ITN_MODE_OFF = 1,
TRANSCRIBE_ITN_MODE_ON = 2,
};
struct transcribe_model;
struct transcribe_session;
struct transcribe_ext {
uint64_t size;
uint32_t kind;
};
TRANSCRIBE_API transcribe_status transcribe_ext_check(
const struct transcribe_ext * ext,
uint32_t expected_kind,
uint64_t min_size);
typedef enum {
TRANSCRIBE_EXT_SLOT_RUN = 0,
TRANSCRIBE_EXT_SLOT_STREAM = 1,
} transcribe_ext_slot;
TRANSCRIBE_API bool transcribe_model_accepts_ext_kind(
const struct transcribe_model * model,
transcribe_ext_slot slot,
uint32_t kind);
typedef enum {
TRANSCRIBE_BACKEND_AUTO = 0,
TRANSCRIBE_BACKEND_CPU = 1,
TRANSCRIBE_BACKEND_METAL = 2,
TRANSCRIBE_BACKEND_VULKAN = 3,
TRANSCRIBE_BACKEND_CPU_ACCEL = 4,
TRANSCRIBE_BACKEND_CUDA = 5,
} transcribe_backend_request;
TRANSCRIBE_API transcribe_status transcribe_init_backends(
const char * artifact_dir);
TRANSCRIBE_API transcribe_status transcribe_init_backends_default(void);
TRANSCRIBE_API int transcribe_backend_device_count(void);
typedef enum {
TRANSCRIBE_DEVICE_TYPE_CPU = 0,
TRANSCRIBE_DEVICE_TYPE_GPU = 1,
TRANSCRIBE_DEVICE_TYPE_IGPU = 2,
TRANSCRIBE_DEVICE_TYPE_ACCEL = 3,
} transcribe_device_type;
struct transcribe_backend_device {
uint64_t struct_size;
const char * name;
const char * description;
const char * kind;
const char * device_id;
uint64_t memory_total;
uint64_t memory_free;
transcribe_device_type device_type;
};
TRANSCRIBE_API void transcribe_backend_device_init(
struct transcribe_backend_device * p);
TRANSCRIBE_API transcribe_status transcribe_get_backend_device(
int index,
struct transcribe_backend_device * out);
TRANSCRIBE_API bool transcribe_backend_available(
transcribe_backend_request kind);
TRANSCRIBE_API transcribe_status transcribe_model_get_device(
const struct transcribe_model * model,
struct transcribe_backend_device * out);
struct transcribe_model_load_params {
uint64_t struct_size;
transcribe_backend_request backend;
int gpu_device;
};
TRANSCRIBE_API void transcribe_model_load_params_init(
struct transcribe_model_load_params * params);
struct transcribe_session_params {
uint64_t struct_size;
int n_threads;
transcribe_kv_type kv_type;
int32_t n_ctx;
};
TRANSCRIBE_API void transcribe_session_params_init(
struct transcribe_session_params * params);
struct transcribe_run_params {
uint64_t struct_size;
transcribe_task task;
transcribe_timestamp_kind timestamps;
enum transcribe_pnc_mode pnc;
enum transcribe_itn_mode itn;
const char * language;
const char * target_language;
bool keep_special_tags;
const struct transcribe_ext * family;
int32_t spec_k_drafts;
};
TRANSCRIBE_API void transcribe_run_params_init(
struct transcribe_run_params * params);
struct transcribe_capabilities {
uint64_t struct_size;
int32_t native_sample_rate;
int n_languages;
const char * const * languages;
transcribe_timestamp_kind max_timestamp_kind;
bool supports_language_detect;
bool supports_translate;
bool supports_streaming;
bool supports_spec_decode;
int64_t max_audio_ms;
};
TRANSCRIBE_API void transcribe_capabilities_init(
struct transcribe_capabilities * out);
TRANSCRIBE_API transcribe_status transcribe_model_get_capabilities(
const struct transcribe_model * model,
struct transcribe_capabilities * out_caps);
typedef enum {
TRANSCRIBE_FEATURE_INITIAL_PROMPT = 0,
TRANSCRIBE_FEATURE_TEMPERATURE_FALLBACK = 1,
TRANSCRIBE_FEATURE_LONG_FORM = 2,
TRANSCRIBE_FEATURE_CANCELLATION = 3,
TRANSCRIBE_FEATURE_PNC = 4,
TRANSCRIBE_FEATURE_ITN = 5,
} transcribe_feature;
TRANSCRIBE_API bool transcribe_model_supports(
const struct transcribe_model * model,
transcribe_feature feature);
TRANSCRIBE_API const char * transcribe_model_arch_string(const struct transcribe_model * model);
TRANSCRIBE_API const char * transcribe_model_variant_string(const struct transcribe_model * model);
TRANSCRIBE_API const char * transcribe_model_backend(const struct transcribe_model * model);
TRANSCRIBE_API transcribe_status transcribe_model_load_file(
const char * path,
const struct transcribe_model_load_params * params,
struct transcribe_model ** out_model);
TRANSCRIBE_API void transcribe_model_free(struct transcribe_model * model);
TRANSCRIBE_API transcribe_status transcribe_session_init(
struct transcribe_model * model,
const struct transcribe_session_params * params,
struct transcribe_session ** out_session);
TRANSCRIBE_API void transcribe_session_free(struct transcribe_session * session);
TRANSCRIBE_API transcribe_status transcribe_open(
const char * path,
const struct transcribe_model_load_params * load_params,
const struct transcribe_session_params * session_params,
struct transcribe_session ** out_session);
TRANSCRIBE_API void transcribe_close(struct transcribe_session * session);
TRANSCRIBE_API const struct transcribe_model * transcribe_get_model(
const struct transcribe_session * session);
TRANSCRIBE_API transcribe_status transcribe_run(
struct transcribe_session * session,
const float * pcm,
int n_samples,
const struct transcribe_run_params * params);
TRANSCRIBE_API transcribe_status transcribe_run_batch(
struct transcribe_session * session,
const float * const * pcm,
const int * n_samples,
int n,
const struct transcribe_run_params * params);
typedef bool (*transcribe_abort_callback)(void * user_data);
TRANSCRIBE_API void transcribe_set_abort_callback(
struct transcribe_session * session,
transcribe_abort_callback cb,
void * user_data);
TRANSCRIBE_API bool transcribe_was_aborted(const struct transcribe_session * session);
TRANSCRIBE_API bool transcribe_was_truncated(const struct transcribe_session * session);
struct transcribe_session_limits {
uint64_t struct_size;
int32_t effective_n_ctx;
int64_t effective_max_audio_ms;
int64_t max_kv_bytes;
};
TRANSCRIBE_API void transcribe_session_limits_init(
struct transcribe_session_limits * out);
TRANSCRIBE_API transcribe_status transcribe_session_get_limits(
const struct transcribe_session * session,
struct transcribe_session_limits * out);
enum transcribe_stream_state {
TRANSCRIBE_STREAM_IDLE = 0,
TRANSCRIBE_STREAM_ACTIVE = 1,
TRANSCRIBE_STREAM_FINISHED = 2,
TRANSCRIBE_STREAM_FAILED = 3,
};
typedef enum {
TRANSCRIBE_STREAM_COMMIT_AUTO = 0,
TRANSCRIBE_STREAM_COMMIT_ON_FINALIZE = 1,
TRANSCRIBE_STREAM_COMMIT_STABLE_PREFIX = 2,
} transcribe_stream_commit_policy;
struct transcribe_stream_params {
uint64_t struct_size;
const struct transcribe_ext * family;
transcribe_stream_commit_policy commit_policy;
uint32_t stable_prefix_agreement_n;
};
TRANSCRIBE_API void transcribe_stream_params_init(
struct transcribe_stream_params * params);
struct transcribe_stream_update {
uint64_t struct_size;
bool result_changed;
bool is_final;
int32_t revision;
int64_t input_received_ms;
int64_t audio_committed_ms;
int64_t buffered_ms;
bool committed_changed;
bool tentative_changed;
};
TRANSCRIBE_API void transcribe_stream_update_init(
struct transcribe_stream_update * out);
struct transcribe_stream_text {
uint64_t struct_size;
const char * full_text;
uint64_t full_text_bytes;
const char * committed_text;
uint64_t committed_text_bytes;
const char * tentative_text;
uint64_t tentative_text_bytes;
uint64_t raw_tentative_start_bytes;
};
TRANSCRIBE_API void transcribe_stream_text_init(
struct transcribe_stream_text * out);
TRANSCRIBE_API transcribe_status transcribe_stream_get_text(
const struct transcribe_session * session,
struct transcribe_stream_text * out);
TRANSCRIBE_API transcribe_status transcribe_stream_begin(
struct transcribe_session * session,
const struct transcribe_run_params * run_params,
const struct transcribe_stream_params * stream_params);
TRANSCRIBE_API transcribe_status transcribe_stream_feed(
struct transcribe_session * session,
const float * pcm,
int n_samples,
struct transcribe_stream_update * update);
TRANSCRIBE_API transcribe_status transcribe_stream_finalize(
struct transcribe_session * session,
struct transcribe_stream_update * update);
TRANSCRIBE_API void transcribe_stream_reset(
struct transcribe_session * session);
TRANSCRIBE_API enum transcribe_stream_state
transcribe_stream_get_state(const struct transcribe_session * session);
TRANSCRIBE_API int transcribe_stream_revision(
const struct transcribe_session * session);
TRANSCRIBE_API int transcribe_stream_n_committed_segments(
const struct transcribe_session * session);
TRANSCRIBE_API int transcribe_stream_n_committed_words(
const struct transcribe_session * session);
TRANSCRIBE_API int transcribe_stream_n_committed_tokens(
const struct transcribe_session * session);
TRANSCRIBE_API transcribe_status transcribe_stream_last_status(
const struct transcribe_session * session);
TRANSCRIBE_API int transcribe_tokenize(
const struct transcribe_model * model,
const char * text,
int32_t * tokens,
size_t n_max);
struct transcribe_timings {
uint64_t struct_size;
float load_ms;
float mel_ms;
float encode_ms;
float decode_ms;
};
TRANSCRIBE_API void transcribe_timings_init(struct transcribe_timings * out);
TRANSCRIBE_API transcribe_status transcribe_get_timings(
const struct transcribe_session * session,
struct transcribe_timings * out_timings);
TRANSCRIBE_API void
transcribe_print_timings(const struct transcribe_session * session);
TRANSCRIBE_API void
transcribe_reset_timings(struct transcribe_session * session);
TRANSCRIBE_API const char * transcribe_full_text(const struct transcribe_session * session);
TRANSCRIBE_API transcribe_timestamp_kind transcribe_returned_timestamp_kind(const struct transcribe_session * session);
TRANSCRIBE_API int transcribe_n_segments(const struct transcribe_session * session);
TRANSCRIBE_API int transcribe_n_words(const struct transcribe_session * session);
TRANSCRIBE_API int transcribe_n_tokens(const struct transcribe_session * session);
TRANSCRIBE_API const char * transcribe_detected_language(const struct transcribe_session * session);
struct transcribe_segment {
uint64_t struct_size;
int64_t t0_ms;
int64_t t1_ms;
int first_word;
int n_words;
int first_token;
int n_tokens;
const char * text;
};
TRANSCRIBE_API void transcribe_segment_init(struct transcribe_segment * out);
struct transcribe_word {
uint64_t struct_size;
int64_t t0_ms;
int64_t t1_ms;
int seg_index;
int first_token;
int n_tokens;
const char * text;
};
TRANSCRIBE_API void transcribe_word_init(struct transcribe_word * out);
struct transcribe_token {
uint64_t struct_size;
int id;
float p;
int64_t t0_ms;
int64_t t1_ms;
int seg_index;
int word_index;
const char * text;
};
TRANSCRIBE_API void transcribe_token_init(struct transcribe_token * out);
TRANSCRIBE_API transcribe_status transcribe_get_segment(
const struct transcribe_session * session,
int i,
struct transcribe_segment * out);
TRANSCRIBE_API transcribe_status transcribe_get_word(
const struct transcribe_session * session,
int i,
struct transcribe_word * out);
TRANSCRIBE_API transcribe_status transcribe_get_token(
const struct transcribe_session * session,
int i,
struct transcribe_token * out);
TRANSCRIBE_API int transcribe_batch_n_results(
const struct transcribe_session * session);
TRANSCRIBE_API transcribe_status transcribe_batch_status(
const struct transcribe_session * session,
int i);
TRANSCRIBE_API const char * transcribe_batch_full_text(
const struct transcribe_session * session,
int i);
TRANSCRIBE_API transcribe_timestamp_kind transcribe_batch_returned_timestamp_kind(
const struct transcribe_session * session,
int i);
TRANSCRIBE_API const char * transcribe_batch_detected_language(
const struct transcribe_session * session,
int i);
TRANSCRIBE_API int transcribe_batch_n_segments(
const struct transcribe_session * session,
int i);
TRANSCRIBE_API int transcribe_batch_n_words(
const struct transcribe_session * session,
int i);
TRANSCRIBE_API int transcribe_batch_n_tokens(
const struct transcribe_session * session,
int i);
TRANSCRIBE_API transcribe_status transcribe_batch_get_segment(
const struct transcribe_session * session,
int i,
int j,
struct transcribe_segment * out);
TRANSCRIBE_API transcribe_status transcribe_batch_get_word(
const struct transcribe_session * session,
int i,
int j,
struct transcribe_word * out);
TRANSCRIBE_API transcribe_status transcribe_batch_get_token(
const struct transcribe_session * session,
int i,
int j,
struct transcribe_token * out);
TRANSCRIBE_API transcribe_status transcribe_batch_get_timings(
const struct transcribe_session * session,
int i,
struct transcribe_timings * out);
#ifdef __cplusplus
}
#endif
#endif