whisper.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. #ifndef WHISPER_H
  2. #define WHISPER_H
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. #include <stdbool.h>
  6. #ifdef WHISPER_SHARED
  7. # ifdef _WIN32
  8. # ifdef WHISPER_BUILD
  9. # define WHISPER_API __declspec(dllexport)
  10. # else
  11. # define WHISPER_API __declspec(dllimport)
  12. # endif
  13. # else
  14. # define WHISPER_API __attribute__ ((visibility ("default")))
  15. # endif
  16. #else
  17. # define WHISPER_API
  18. #endif
  19. #define WHISPER_SAMPLE_RATE 16000
  20. #define WHISPER_N_FFT 400
  21. #define WHISPER_N_MEL 80
  22. #define WHISPER_HOP_LENGTH 160
  23. #define WHISPER_CHUNK_SIZE 30
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. //
  28. // C interface
  29. //
  30. // The following interface is thread-safe as long as the sample whisper_context is not used by multiple threads
  31. // concurrently.
  32. //
  33. // Basic usage:
  34. //
  35. // #include "whisper.h"
  36. //
  37. // ...
  38. //
  39. // struct whisper_context * ctx = whisper_init_from_file("/path/to/ggml-base.en.bin");
  40. //
  41. // if (whisper_full(ctx, wparams, pcmf32.data(), pcmf32.size()) != 0) {
  42. // fprintf(stderr, "failed to process audio\n");
  43. // return 7;
  44. // }
  45. //
  46. // const int n_segments = whisper_full_n_segments(ctx);
  47. // for (int i = 0; i < n_segments; ++i) {
  48. // const char * text = whisper_full_get_segment_text(ctx, i);
  49. // printf("%s", text);
  50. // }
  51. //
  52. // whisper_free(ctx);
  53. //
  54. // ...
  55. //
  56. // This is a demonstration of the most straightforward usage of the library.
  57. // "pcmf32" contains the RAW audio data in 32-bit floating point format.
  58. //
  59. // The interface also allows for more fine-grained control over the computation, but it requires a deeper
  60. // understanding of how the model works.
  61. //
  62. struct whisper_context;
  63. struct whisper_state;
  64. struct whisper_full_params;
  65. typedef int whisper_token;
  66. typedef struct whisper_token_data {
  67. whisper_token id; // token id
  68. whisper_token tid; // forced timestamp token id
  69. float p; // probability of the token
  70. float plog; // log probability of the token
  71. float pt; // probability of the timestamp token
  72. float ptsum; // sum of probabilities of all timestamp tokens
  73. // token-level timestamp data
  74. // do not use if you haven't computed token-level timestamps
  75. int64_t t0; // start time of the token
  76. int64_t t1; // end time of the token
  77. float vlen; // voice length of the token
  78. } whisper_token_data;
  79. typedef struct whisper_model_loader {
  80. void * context;
  81. size_t (*read)(void * ctx, void * output, size_t read_size);
  82. bool (*eof)(void * ctx);
  83. void (*close)(void * ctx);
  84. } whisper_model_loader;
  85. // Various functions for loading a ggml whisper model.
  86. // Allocate (almost) all memory needed for the model.
  87. // Return NULL on failure
  88. WHISPER_API struct whisper_context * whisper_init_from_file(const char * path_model);
  89. WHISPER_API struct whisper_context * whisper_init_from_buffer(void * buffer, size_t buffer_size);
  90. WHISPER_API struct whisper_context * whisper_init(struct whisper_model_loader * loader);
  91. // These are the same as the above, but the internal state of the context is not allocated automatically
  92. // It is the responsibility of the caller to allocate the state using whisper_init_state() (#523)
  93. WHISPER_API struct whisper_context * whisper_init_from_file_no_state(const char * path_model);
  94. WHISPER_API struct whisper_context * whisper_init_from_buffer_no_state(void * buffer, size_t buffer_size);
  95. WHISPER_API struct whisper_context * whisper_init_no_state(struct whisper_model_loader * loader);
  96. WHISPER_API struct whisper_state * whisper_init_state(struct whisper_context * ctx);
  97. // Given a context, enable use of OpenVINO for encode inference.
  98. // model_path: Optional path to OpenVINO encoder IR model. If set to nullptr,
  99. // the path will be generated from the ggml model path that was passed
  100. // in to whisper_init_from_file. For example, if 'path_model' was
  101. // "/path/to/ggml-base.en.bin", then OpenVINO IR model path will be
  102. // assumed to be "/path/to/ggml-base.en-encoder-openvino.xml".
  103. // device: OpenVINO device to run inference on ("CPU", "GPU", etc.)
  104. // cache_dir: Optional cache directory that can speed up init time, especially for
  105. // GPU, by caching compiled 'blobs' there.
  106. // Set to nullptr if not used.
  107. // Returns 0 on success. If OpenVINO is not enabled in build, this simply returns 1.
  108. WHISPER_API int whisper_ctx_init_openvino_encoder(
  109. struct whisper_context * ctx,
  110. const char * model_path,
  111. const char * device,
  112. const char * cache_dir);
  113. // Frees all allocated memory
  114. WHISPER_API void whisper_free (struct whisper_context * ctx);
  115. WHISPER_API void whisper_free_state(struct whisper_state * state);
  116. WHISPER_API void whisper_free_params(struct whisper_full_params * params);
  117. // Convert RAW PCM audio to log mel spectrogram.
  118. // The resulting spectrogram is stored inside the default state of the provided whisper context.
  119. // Returns 0 on success
  120. WHISPER_API int whisper_pcm_to_mel(
  121. struct whisper_context * ctx,
  122. const float * samples,
  123. int n_samples,
  124. int n_threads);
  125. WHISPER_API int whisper_pcm_to_mel_with_state(
  126. struct whisper_context * ctx,
  127. struct whisper_state * state,
  128. const float * samples,
  129. int n_samples,
  130. int n_threads);
  131. // Convert RAW PCM audio to log mel spectrogram but applies a Phase Vocoder to speed up the audio x2.
  132. // The resulting spectrogram is stored inside the default state of the provided whisper context.
  133. // Returns 0 on success
  134. WHISPER_API int whisper_pcm_to_mel_phase_vocoder(
  135. struct whisper_context * ctx,
  136. const float * samples,
  137. int n_samples,
  138. int n_threads);
  139. WHISPER_API int whisper_pcm_to_mel_phase_vocoder_with_state(
  140. struct whisper_context * ctx,
  141. struct whisper_state * state,
  142. const float * samples,
  143. int n_samples,
  144. int n_threads);
  145. // This can be used to set a custom log mel spectrogram inside the default state of the provided whisper context.
  146. // Use this instead of whisper_pcm_to_mel() if you want to provide your own log mel spectrogram.
  147. // n_mel must be 80
  148. // Returns 0 on success
  149. WHISPER_API int whisper_set_mel(
  150. struct whisper_context * ctx,
  151. const float * data,
  152. int n_len,
  153. int n_mel);
  154. WHISPER_API int whisper_set_mel_with_state(
  155. struct whisper_context * ctx,
  156. struct whisper_state * state,
  157. const float * data,
  158. int n_len,
  159. int n_mel);
  160. // Run the Whisper encoder on the log mel spectrogram stored inside the default state in the provided whisper context.
  161. // Make sure to call whisper_pcm_to_mel() or whisper_set_mel() first.
  162. // offset can be used to specify the offset of the first frame in the spectrogram.
  163. // Returns 0 on success
  164. WHISPER_API int whisper_encode(
  165. struct whisper_context * ctx,
  166. int offset,
  167. int n_threads);
  168. WHISPER_API int whisper_encode_with_state(
  169. struct whisper_context * ctx,
  170. struct whisper_state * state,
  171. int offset,
  172. int n_threads);
  173. // Run the Whisper decoder to obtain the logits and probabilities for the next token.
  174. // Make sure to call whisper_encode() first.
  175. // tokens + n_tokens is the provided context for the decoder.
  176. // n_past is the number of tokens to use from previous decoder calls.
  177. // Returns 0 on success
  178. // TODO: add support for multiple decoders
  179. WHISPER_API int whisper_decode(
  180. struct whisper_context * ctx,
  181. const whisper_token * tokens,
  182. int n_tokens,
  183. int n_past,
  184. int n_threads);
  185. WHISPER_API int whisper_decode_with_state(
  186. struct whisper_context * ctx,
  187. struct whisper_state * state,
  188. const whisper_token * tokens,
  189. int n_tokens,
  190. int n_past,
  191. int n_threads);
  192. // Convert the provided text into tokens.
  193. // The tokens pointer must be large enough to hold the resulting tokens.
  194. // Returns the number of tokens on success, no more than n_max_tokens
  195. // Returns -1 on failure
  196. // TODO: not sure if correct
  197. WHISPER_API int whisper_tokenize(
  198. struct whisper_context * ctx,
  199. const char * text,
  200. whisper_token * tokens,
  201. int n_max_tokens);
  202. // Largest language id (i.e. number of available languages - 1)
  203. WHISPER_API int whisper_lang_max_id();
  204. // Return the id of the specified language, returns -1 if not found
  205. // Examples:
  206. // "de" -> 2
  207. // "german" -> 2
  208. WHISPER_API int whisper_lang_id(const char * lang);
  209. // Return the short string of the specified language id (e.g. 2 -> "de"), returns nullptr if not found
  210. WHISPER_API const char * whisper_lang_str(int id);
  211. // Use mel data at offset_ms to try and auto-detect the spoken language
  212. // Make sure to call whisper_pcm_to_mel() or whisper_set_mel() first
  213. // Returns the top language id or negative on failure
  214. // If not null, fills the lang_probs array with the probabilities of all languages
  215. // The array must be whisper_lang_max_id() + 1 in size
  216. // ref: https://github.com/openai/whisper/blob/main/whisper/decoding.py#L18-L69
  217. WHISPER_API int whisper_lang_auto_detect(
  218. struct whisper_context * ctx,
  219. int offset_ms,
  220. int n_threads,
  221. float * lang_probs);
  222. WHISPER_API int whisper_lang_auto_detect_with_state(
  223. struct whisper_context * ctx,
  224. struct whisper_state * state,
  225. int offset_ms,
  226. int n_threads,
  227. float * lang_probs);
  228. WHISPER_API int whisper_n_len (struct whisper_context * ctx); // mel length
  229. WHISPER_API int whisper_n_len_from_state(struct whisper_state * state); // mel length
  230. WHISPER_API int whisper_n_vocab (struct whisper_context * ctx);
  231. WHISPER_API int whisper_n_text_ctx (struct whisper_context * ctx);
  232. WHISPER_API int whisper_n_audio_ctx (struct whisper_context * ctx);
  233. WHISPER_API int whisper_is_multilingual (struct whisper_context * ctx);
  234. WHISPER_API int whisper_model_n_vocab (struct whisper_context * ctx);
  235. WHISPER_API int whisper_model_n_audio_ctx (struct whisper_context * ctx);
  236. WHISPER_API int whisper_model_n_audio_state(struct whisper_context * ctx);
  237. WHISPER_API int whisper_model_n_audio_head (struct whisper_context * ctx);
  238. WHISPER_API int whisper_model_n_audio_layer(struct whisper_context * ctx);
  239. WHISPER_API int whisper_model_n_text_ctx (struct whisper_context * ctx);
  240. WHISPER_API int whisper_model_n_text_state (struct whisper_context * ctx);
  241. WHISPER_API int whisper_model_n_text_head (struct whisper_context * ctx);
  242. WHISPER_API int whisper_model_n_text_layer (struct whisper_context * ctx);
  243. WHISPER_API int whisper_model_n_mels (struct whisper_context * ctx);
  244. WHISPER_API int whisper_model_ftype (struct whisper_context * ctx);
  245. WHISPER_API int whisper_model_type (struct whisper_context * ctx);
  246. // Token logits obtained from the last call to whisper_decode()
  247. // The logits for the last token are stored in the last row
  248. // Rows: n_tokens
  249. // Cols: n_vocab
  250. WHISPER_API float * whisper_get_logits (struct whisper_context * ctx);
  251. WHISPER_API float * whisper_get_logits_from_state(struct whisper_state * state);
  252. // Token Id -> String. Uses the vocabulary in the provided context
  253. WHISPER_API const char * whisper_token_to_str(struct whisper_context * ctx, whisper_token token);
  254. WHISPER_API const char * whisper_model_type_readable(struct whisper_context * ctx);
  255. // Special tokens
  256. WHISPER_API whisper_token whisper_token_eot (struct whisper_context * ctx);
  257. WHISPER_API whisper_token whisper_token_sot (struct whisper_context * ctx);
  258. WHISPER_API whisper_token whisper_token_solm(struct whisper_context * ctx);
  259. WHISPER_API whisper_token whisper_token_prev(struct whisper_context * ctx);
  260. WHISPER_API whisper_token whisper_token_nosp(struct whisper_context * ctx);
  261. WHISPER_API whisper_token whisper_token_not (struct whisper_context * ctx);
  262. WHISPER_API whisper_token whisper_token_beg (struct whisper_context * ctx);
  263. WHISPER_API whisper_token whisper_token_lang(struct whisper_context * ctx, int lang_id);
  264. // Task tokens
  265. WHISPER_API whisper_token whisper_token_translate (struct whisper_context * ctx);
  266. WHISPER_API whisper_token whisper_token_transcribe(struct whisper_context * ctx);
  267. // Performance information from the default state.
  268. WHISPER_API void whisper_print_timings(struct whisper_context * ctx);
  269. WHISPER_API void whisper_reset_timings(struct whisper_context * ctx);
  270. // Print system information
  271. WHISPER_API const char * whisper_print_system_info(void);
  272. ////////////////////////////////////////////////////////////////////////////
  273. // Available sampling strategies
  274. enum whisper_sampling_strategy {
  275. WHISPER_SAMPLING_GREEDY, // similar to OpenAI's GreedyDecoder
  276. WHISPER_SAMPLING_BEAM_SEARCH, // similar to OpenAI's BeamSearchDecoder
  277. };
  278. // Text segment callback
  279. // Called on every newly generated text segment
  280. // Use the whisper_full_...() functions to obtain the text segments
  281. typedef void (*whisper_new_segment_callback)(struct whisper_context * ctx, struct whisper_state * state, int n_new, void * user_data);
  282. // Progress callback
  283. typedef void (*whisper_progress_callback)(struct whisper_context * ctx, struct whisper_state * state, int progress, void * user_data);
  284. // Encoder begin callback
  285. // If not NULL, called before the encoder starts
  286. // If it returns false, the computation is aborted
  287. typedef bool (*whisper_encoder_begin_callback)(struct whisper_context * ctx, struct whisper_state * state, void * user_data);
  288. // Logits filter callback
  289. // Can be used to modify the logits before sampling
  290. // If not NULL, called after applying temperature to logits
  291. typedef void (*whisper_logits_filter_callback)(
  292. struct whisper_context * ctx,
  293. struct whisper_state * state,
  294. const whisper_token_data * tokens,
  295. int n_tokens,
  296. float * logits,
  297. void * user_data);
  298. // Parameters for the whisper_full() function
  299. // If you change the order or add new parameters, make sure to update the default values in whisper.cpp:
  300. // whisper_full_default_params()
  301. struct whisper_full_params {
  302. enum whisper_sampling_strategy strategy;
  303. int n_threads;
  304. int n_max_text_ctx; // max tokens to use from past text as prompt for the decoder
  305. int offset_ms; // start offset in ms
  306. int duration_ms; // audio duration to process in ms
  307. bool translate;
  308. bool no_context; // do not use past transcription (if any) as initial prompt for the decoder
  309. bool single_segment; // force single segment output (useful for streaming)
  310. bool print_special; // print special tokens (e.g. <SOT>, <EOT>, <BEG>, etc.)
  311. bool print_progress; // print progress information
  312. bool print_realtime; // print results from within whisper.cpp (avoid it, use callback instead)
  313. bool print_timestamps; // print timestamps for each text segment when printing realtime
  314. // [EXPERIMENTAL] token-level timestamps
  315. bool token_timestamps; // enable token-level timestamps
  316. float thold_pt; // timestamp token probability threshold (~0.01)
  317. float thold_ptsum; // timestamp token sum probability threshold (~0.01)
  318. int max_len; // max segment length in characters
  319. bool split_on_word; // split on word rather than on token (when used with max_len)
  320. int max_tokens; // max tokens per segment (0 = no limit)
  321. // [EXPERIMENTAL] speed-up techniques
  322. // note: these can significantly reduce the quality of the output
  323. bool speed_up; // speed-up the audio by 2x using Phase Vocoder
  324. bool debug_mode; // enable debug_mode provides extra info (eg. Dump log_mel)
  325. int audio_ctx; // overwrite the audio context size (0 = use default)
  326. // [EXPERIMENTAL] [TDRZ] tinydiarize
  327. bool tdrz_enable; // enable tinydiarize speaker turn detection
  328. // tokens to provide to the whisper decoder as initial prompt
  329. // these are prepended to any existing text context from a previous call
  330. const char * initial_prompt;
  331. const whisper_token * prompt_tokens;
  332. int prompt_n_tokens;
  333. // for auto-detection, set to nullptr, "" or "auto"
  334. const char * language;
  335. bool detect_language;
  336. // common decoding parameters:
  337. bool suppress_blank; // ref: https://github.com/openai/whisper/blob/f82bc59f5ea234d4b97fb2860842ed38519f7e65/whisper/decoding.py#L89
  338. bool suppress_non_speech_tokens; // ref: https://github.com/openai/whisper/blob/7858aa9c08d98f75575035ecd6481f462d66ca27/whisper/tokenizer.py#L224-L253
  339. float temperature; // initial decoding temperature, ref: https://ai.stackexchange.com/a/32478
  340. float max_initial_ts; // ref: https://github.com/openai/whisper/blob/f82bc59f5ea234d4b97fb2860842ed38519f7e65/whisper/decoding.py#L97
  341. float length_penalty; // ref: https://github.com/openai/whisper/blob/f82bc59f5ea234d4b97fb2860842ed38519f7e65/whisper/transcribe.py#L267
  342. // fallback parameters
  343. // ref: https://github.com/openai/whisper/blob/f82bc59f5ea234d4b97fb2860842ed38519f7e65/whisper/transcribe.py#L274-L278
  344. float temperature_inc;
  345. float entropy_thold; // similar to OpenAI's "compression_ratio_threshold"
  346. float logprob_thold;
  347. float no_speech_thold; // TODO: not implemented
  348. struct {
  349. int best_of; // ref: https://github.com/openai/whisper/blob/f82bc59f5ea234d4b97fb2860842ed38519f7e65/whisper/transcribe.py#L264
  350. } greedy;
  351. struct {
  352. int beam_size; // ref: https://github.com/openai/whisper/blob/f82bc59f5ea234d4b97fb2860842ed38519f7e65/whisper/transcribe.py#L265
  353. float patience; // TODO: not implemented, ref: https://arxiv.org/pdf/2204.05424.pdf
  354. } beam_search;
  355. // called for every newly generated text segment
  356. whisper_new_segment_callback new_segment_callback;
  357. void * new_segment_callback_user_data;
  358. // called on each progress update
  359. whisper_progress_callback progress_callback;
  360. void * progress_callback_user_data;
  361. // called each time before the encoder starts
  362. whisper_encoder_begin_callback encoder_begin_callback;
  363. void * encoder_begin_callback_user_data;
  364. // called by each decoder to filter obtained logits
  365. whisper_logits_filter_callback logits_filter_callback;
  366. void * logits_filter_callback_user_data;
  367. };
  368. // NOTE: this function allocates memory, and it is the responsibility of the caller to free the pointer - see whisper_free_params()
  369. WHISPER_API struct whisper_full_params * whisper_full_default_params_by_ref(enum whisper_sampling_strategy strategy);
  370. WHISPER_API struct whisper_full_params whisper_full_default_params(enum whisper_sampling_strategy strategy);
  371. // Run the entire model: PCM -> log mel spectrogram -> encoder -> decoder -> text
  372. // Not thread safe for same context
  373. // Uses the specified decoding strategy to obtain the text.
  374. WHISPER_API int whisper_full(
  375. struct whisper_context * ctx,
  376. struct whisper_full_params params,
  377. const float * samples,
  378. int n_samples);
  379. WHISPER_API int whisper_full_with_state(
  380. struct whisper_context * ctx,
  381. struct whisper_state * state,
  382. struct whisper_full_params params,
  383. const float * samples,
  384. int n_samples);
  385. // Split the input audio in chunks and process each chunk separately using whisper_full_with_state()
  386. // Result is stored in the default state of the context
  387. // Not thread safe if executed in parallel on the same context.
  388. // It seems this approach can offer some speedup in some cases.
  389. // However, the transcription accuracy can be worse at the beginning and end of each chunk.
  390. WHISPER_API int whisper_full_parallel(
  391. struct whisper_context * ctx,
  392. struct whisper_full_params params,
  393. const float * samples,
  394. int n_samples,
  395. int n_processors);
  396. // Number of generated text segments
  397. // A segment can be a few words, a sentence, or even a paragraph.
  398. WHISPER_API int whisper_full_n_segments (struct whisper_context * ctx);
  399. WHISPER_API int whisper_full_n_segments_from_state(struct whisper_state * state);
  400. // Language id associated with the context's default state
  401. WHISPER_API int whisper_full_lang_id(struct whisper_context * ctx);
  402. // Language id associated with the provided state
  403. WHISPER_API int whisper_full_lang_id_from_state(struct whisper_state * state);
  404. // Get the start and end time of the specified segment
  405. WHISPER_API int64_t whisper_full_get_segment_t0 (struct whisper_context * ctx, int i_segment);
  406. WHISPER_API int64_t whisper_full_get_segment_t0_from_state(struct whisper_state * state, int i_segment);
  407. WHISPER_API int64_t whisper_full_get_segment_t1 (struct whisper_context * ctx, int i_segment);
  408. WHISPER_API int64_t whisper_full_get_segment_t1_from_state(struct whisper_state * state, int i_segment);
  409. // Get whether the next segment is predicted as a speaker turn
  410. WHISPER_API bool whisper_full_get_segment_speaker_turn_next(struct whisper_context * ctx, int i_segment);
  411. // Get the text of the specified segment
  412. WHISPER_API const char * whisper_full_get_segment_text (struct whisper_context * ctx, int i_segment);
  413. WHISPER_API const char * whisper_full_get_segment_text_from_state(struct whisper_state * state, int i_segment);
  414. // Get number of tokens in the specified segment
  415. WHISPER_API int whisper_full_n_tokens (struct whisper_context * ctx, int i_segment);
  416. WHISPER_API int whisper_full_n_tokens_from_state(struct whisper_state * state, int i_segment);
  417. // Get the token text of the specified token in the specified segment
  418. WHISPER_API const char * whisper_full_get_token_text (struct whisper_context * ctx, int i_segment, int i_token);
  419. WHISPER_API const char * whisper_full_get_token_text_from_state(struct whisper_context * ctx, struct whisper_state * state, int i_segment, int i_token);
  420. WHISPER_API whisper_token whisper_full_get_token_id (struct whisper_context * ctx, int i_segment, int i_token);
  421. WHISPER_API whisper_token whisper_full_get_token_id_from_state(struct whisper_state * state, int i_segment, int i_token);
  422. // Get token data for the specified token in the specified segment
  423. // This contains probabilities, timestamps, etc.
  424. WHISPER_API whisper_token_data whisper_full_get_token_data (struct whisper_context * ctx, int i_segment, int i_token);
  425. WHISPER_API whisper_token_data whisper_full_get_token_data_from_state(struct whisper_state * state, int i_segment, int i_token);
  426. // Get the probability of the specified token in the specified segment
  427. WHISPER_API float whisper_full_get_token_p (struct whisper_context * ctx, int i_segment, int i_token);
  428. WHISPER_API float whisper_full_get_token_p_from_state(struct whisper_state * state, int i_segment, int i_token);
  429. ////////////////////////////////////////////////////////////////////////////
  430. // Temporary helpers needed for exposing ggml interface
  431. WHISPER_API int whisper_bench_memcpy (int n_threads);
  432. WHISPER_API const char * whisper_bench_memcpy_str (int n_threads);
  433. WHISPER_API int whisper_bench_ggml_mul_mat (int n_threads);
  434. WHISPER_API const char * whisper_bench_ggml_mul_mat_str(int n_threads);
  435. // Control logging output; default behavior is to print to stderr
  436. typedef void (*whisper_log_callback)(const char * line);
  437. WHISPER_API void whisper_set_log_callback(whisper_log_callback callback);
  438. #ifdef __cplusplus
  439. }
  440. #endif
  441. #endif