-
Notifications
You must be signed in to change notification settings - Fork 0
/
binding.go
2131 lines (1682 loc) · 98 KB
/
binding.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) seasonjs. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
package whisper
import (
"github.com/ebitengine/purego"
"unsafe"
)
const (
WHISPER_SAMPLE_RATE int = 16000
WHISPER_N_FFT = 400
WHISPER_HOP_LENGTH = 160
WHISPER_CHUNK_SIZE = 30
)
const (
//=============================================whisper.h============================================================
//cWhisperInitFromFileWithParams = "whisper_init_from_file_with_params"
//cWhisperInitFromBufferWithParams = "whisper_init_from_buffer_with_params"
//cWhisperInitWithParams = "whisper_init_with_params"
//
//cWhisperInitFromFileWithParamsNoState = "whisper_init_from_file_with_params_no_state"
//cWhisperInitFromBufferWithParamsNoState = "whisper_init_from_buffer_with_params_no_state"
//cWhisperInitWithParamsNoState = "whisper_init_with_params_no_state"
cWhisperInitState = "whisper_init_state"
cWhisperCtxInitOpenvinoEncoder = "whisper_ctx_init_openvino_encoder"
cWhisperFree = "whisper_free"
cWhisperFreeState = "whisper_free_state"
cWhisperFreeParams = "whisper_free_params"
cWhisperFreeContextParams = "whisper_free_context_params"
cWhisperPcmToMel = "whisper_pcm_to_mel"
cWhisperPcmToMelWithState = "whisper_pcm_to_mel_with_state"
cWhisperPcmToMelPhaseVocoder = "whisper_pcm_to_mel_phase_vocoder"
cWhisperPcmToMelPhaseVocoderWithState = "whisper_pcm_to_mel_phase_vocoder_with_state"
cWhisperSetMel = "whisper_set_mel"
cWhisperSetMelWithState = "whisper_set_mel_with_state"
cWhisperEncode = "whisper_encode"
cWhisperEncodeWithState = "whisper_encode_with_state"
cWhisperDecode = "whisper_decode"
cWhisperDecodeWithState = "whisper_decode_with_state"
cWhisperTokenize = "whisper_tokenize"
cWhisperLangMaxId = "whisper_lang_max_id"
cWhisperLangId = "whisper_lang_id"
cWhisperLangStr = "whisper_lang_str"
cWhisperLangAutoDetect = "whisper_lang_auto_detect"
cWhisperLangAutoDetectWithState = "whisper_lang_auto_detect_with_state"
cWhisperNLen = "whisper_n_len_from_state"
cWhisperNLenFromState = "whisper_n_len_from_state"
cWhisperNVocab = "whisper_n_vocab"
cWhisperNTextCtx = "whisper_n_text_ctx"
cWhisperNAudioCtx = "whisper_n_audio_ctx"
cWhisperIsMultilingual = "whisper_is_multilingual"
cWhisperModelNVocab = "whisper_model_n_vocab"
cWhisperModelNAudioCtx = "whisper_model_n_audio_ctx"
cWhisperModelNAudioState = "whisper_model_n_audio_state"
cWhisperModelNAudioHead = "whisper_model_n_audio_head"
cWhisperModelNAudioLayer = "whisper_model_n_audio_layer"
cWhisperModelNTextCtx = "whisper_model_n_text_ctx"
cWhisperModelNTextState = "whisper_model_n_text_state"
cWhisperModelNTextHead = "whisper_model_n_text_head"
cWhisperModelNTextLayer = "whisper_model_n_text_layer"
cWhisperModelNMels = "whisper_model_n_mels"
cWhisperModelFtype = "whisper_model_ftype"
cWhisperModelType = "whisper_model_type"
cWhisperGetLogits = "whisper_get_logits"
cWhisperGetLogitsFromState = "whisper_get_logits_from_state"
cWhisperTokenToStr = "whisper_token_to_str"
cWhisperModelTypeReadable = "whisper_model_type_readable"
cWhisperTokenEot = "whisper_token_eot"
cWhisperTokenSot = "whisper_token_sot"
cWhisperTokenSolm = "whisper_token_solm"
cWhisperTokenPrev = "whisper_token_prev"
cWhisperTokenNosp = "whisper_token_nosp"
cWhisperTokenNot = "whisper_token_not"
cWhisperTokenBeg = "whisper_token_beg"
cWhisperTokenLang = "whisper_token_lang"
cWhisperTokenTranslate = "whisper_token_translate"
cWhisperTokenTranscribe = "whisper_token_transcribe"
cWhisperPrintTimings = "whisper_print_timings"
cWhisperResetTimings = "whisper_reset_timings"
cWhisperPrintSystemInfo = "whisper_print_system_info"
cWhisperContextDefaultParamsByRef = "whisper_context_default_params_by_ref"
cWhisperContextDefaultParams = "whisper_context_default_params"
cWhisperFullDefaultParamsByRef = "whisper_full_default_params_by_ref"
cWhisperFullDefaultParams = "whisper_full_default_params"
//cWhisperFull = "whisper_full"
//cWhisperFullWithState = "whisper_full_with_state"
//
//cWhisperFullParallel = "whisper_full_parallel"
cWhisperFullNSegments = "whisper_full_n_segments"
cWhisperFullNSegmentsFromState = "whisper_full_n_segments_from_state"
cWhisperFullLangId = "whisper_full_lang_id"
cWhisperFullLangIdFromState = "whisper_full_lang_id_from_state"
cWhisperFullGetSegmentT0 = "whisper_full_get_segment_t0"
cWhisperFullGetSegmentT0FromState = "whisper_full_get_segment_t0_from_state"
cWhisperFullGetSegmentT1 = "whisper_full_get_segment_t1"
cWhisperFullGetSegmentT1FromState = "whisper_full_get_segment_t1_from_state"
cWhisperFullGetSegmentSpeakerTurnNext = "whisper_full_get_segment_speaker_turn_next"
cWhisperFullGetSegmentSpeakerTurnNextFromState = "whisper_full_get_segment_speaker_turn_next_from_state"
cWhisperFullGetSegmentText = "whisper_full_get_segment_text"
cWhisperFullGetSegmentTextFromState = "whisper_full_get_segment_text_from_state"
cWhisperFullNTokens = "whisper_full_n_tokens"
cWhisperFullNTokensFromState = "whisper_full_n_tokens_from_state"
cWhisperFullGetTokenText = "whisper_full_get_token_text"
cWhisperFullGetTokenTextFromState = "whisper_full_get_token_text_from_state"
cWhisperFullGetTokenId = "whisper_full_get_token_id"
cWhisperFullGetTokenIdFromState = "whisper_full_get_token_id_from_state"
//cWhisperFullGetTokenData = "whisper_full_get_token_data"
//cWhisperFullGetTokenDataFromState = "whisper_full_get_token_data_from_state"
cWhisperFullGetTokenP = "whisper_full_get_token_p"
cWhisperFullGetTokenPFromState = "whisper_full_get_token_p_from_state"
//=============================================whisper_abi.h========================================================
cWhisperContextParamsSetUseGpu = "whisper_context_params_set_use_gpu"
cWhisperFullParamsSetStrategy = "whisper_full_params_set_strategy"
cWhisperFullParamsSetNThreads = "whisper_full_params_set_n_threads"
cWhisperFullParamsSetNMaxTextCtx = "whisper_full_params_set_n_max_text_ctx"
cWhisperFullParamsSetOffsetMs = "whisper_full_params_set_offset_ms"
cWhisperFullParamsSetDurationMs = "whisper_full_params_set_duration_ms"
cWhisperFullParamsSetTranslate = "whisper_full_params_set_translate"
cWhisperFullParamsSetNoContext = "whisper_full_params_set_no_context"
cWhisperFullParamsSetNoTimestamps = "whisper_full_params_set_no_timestamps"
cWhisperFullParamsSetSingleSegment = "whisper_full_params_set_single_segment"
cWhisperFullParamsSetPrintSpecial = "whisper_full_params_set_print_special"
cWhisperFullParamsSetPrintProgress = "whisper_full_params_set_print_progress"
cWhisperFullParamsSetPrintRealtime = "whisper_full_params_set_print_realtime"
cWhisperFullParamsSetPrintTimestamps = "whisper_full_params_set_print_timestamps"
cWhisperFullParamsSetTokenTimestamps = "whisper_full_params_set_token_timestamps"
cWhisperFullParamsSetTholdPt = "whisper_full_params_set_thold_pt"
cWhisperFullParamsSetTholdPtsum = "whisper_full_params_set_thold_ptsum"
cWhisperFullParamsSetMaxLen = "whisper_full_params_set_max_len"
cWhisperFullParamsSetSplitOnWord = "whisper_full_params_set_split_on_word"
cWhisperFullParamsSetMaxTokens = "whisper_full_params_set_max_tokens"
cWhisperFullParamsSetSpeedUp = "whisper_full_params_set_speed_up"
cWhisperFullParamsSetDebugMode = "whisper_full_params_set_debug_mode"
cWhisperFullParamsSetAudioCtx = "whisper_full_params_set_audio_ctx"
cWhisperFullParamsSetTdrzEnable = "whisper_full_params_set_tdrz_enable"
cWhisperFullParamsSetInitialPrompt = "whisper_full_params_set_initial_prompt"
cWhisperFullParamsSetPromptTokens = "whisper_full_params_set_prompt_tokens"
cWhisperFullParamsSetPromptNTokens = "whisper_full_params_set_prompt_n_tokens"
cWhisperFullParamsSetLanguage = "whisper_full_params_set_language"
cWhisperFullParamsSetDetectLanguage = "whisper_full_params_set_detect_language"
cWhisperFullParamsSetSuppressBlank = "whisper_full_params_set_suppress_blank"
cWhisperFullParamsSetSuppressNonSpeechTokens = "whisper_full_params_set_suppress_non_speech_tokens"
cWhisperFullParamsSetTemperature = "whisper_full_params_set_temperature"
cWhisperFullParamsSetMaxInitialTs = "whisper_full_params_set_max_initial_ts"
cWhisperFullParamsSetLengthPenalty = "whisper_full_params_set_length_penalty"
cWhisperFullParamsSetTemperatureInc = "whisper_full_params_set_temperature_inc"
cWhisperFullParamsSetEntropyThold = "whisper_full_params_set_entropy_thold"
cWhisperFullParamsSetLogprobThold = "whisper_full_params_set_logprob_thold"
cWhisperFullParamsSetNoSpeechThold = "whisper_full_params_set_no_speech_thold"
cWhisperFullParamsSetGreedyBestOf = "whisper_full_params_set_greedy_best_of"
cWhisperFullParamsSetBeamSearchBeamSize = "whisper_full_params_set_beam_search_beam_size"
cWhisperFullParamsSetBeamSearchPatience = "whisper_full_params_set_beam_search_patience"
cWhisperInitFromFileWithParamsRef = "whisper_init_from_file_with_params_ref"
cWhisperInitFromBufferWithParamsRef = "whisper_init_from_buffer_with_params_ref"
cWhisperInitFromFileWithParamsRefNoState = "whisper_init_from_file_with_params_ref_no_state"
cWhisperInitFromBufferWithParamsRefNoState = "whisper_init_from_buffer_with_params_ref_no_state"
cWhisperFullRef = "whisper_full_ref"
cWhisperFullRefWithState = "whisper_full_ref_with_state"
cWhisperFullRefParallel = "whisper_full_ref_parallel"
)
type CWhisperContext struct {
ctx uintptr
}
type CWhisperState struct {
state uintptr
}
// CWhisperFullParams WhisperFullParams Parameters for the CWhisper.WhisperFull function
// If you change the order or add new parameters, make sure to update the default values in whisper.cpp:
// CWhisper.WhisperFullDefaultParams()
//
//type CWhisperFullParams struct {
// strategy int32
//
// nThreads int32
// nMaxTextCtx int32 // max tokens to use from past text as prompt for the decoder
// offsetMs int32 // start offset in ms
// durationMs int32 // audio duration to process in ms
//
// translate bool
// noContext bool // do not use past transcription (if any) as initial prompt for the decoder
// noTimestamps bool // do not generate timestamps
// singleSegment bool // force single segment output (useful for streaming)
// printSpecial bool // print special tokens (e.g. <SOT>, <EOT>, <BEG>, etc.)
// printProgress bool // print progress information
// printRealtime bool // print results from within whisper.cpp (avoid it, use callback instead)
// printTimestamps bool // print timestamps for each text segment when printing realtime
//
// // [EXPERIMENTAL] token-level timestamps
// tokenTimestamps bool // enable token-level timestamps
// tholdPt float32 // timestamp token probability threshold (~0.01)
// tholdPtsum float32 // timestamp token sum probability threshold (~0.01)
// maxLen int32 // max segment length in characters
// splitOnWord bool // split on word rather than on token (when used with max_len)
// maxTokens int32 // max tokens per segment (0 = no limit)
//
// // [EXPERIMENTAL] speed-up techniques
// // note: these can significantly reduce the quality of the output
// speedUp bool // speed-up the audio by 2x using Phase Vocoder
// debugMode bool // enable debug_mode provides extra info (eg. Dump log_mel)
// audioCtx int32 // overwrite the audio context size (0 = use default)
//
// // [EXPERIMENTAL] [TDRZ] tinydiarize
// tdrzEnable bool // enable tinydiarize speaker turn detection
//
// // tokens to provide to the whisper decoder as initial prompt
// // these are prepended to any existing text context from a previous call
// initialPrompt uintptr
// promptTokens uintptr
// promptNTokens int32
//
// // for auto-detection, set to nullptr, "" or "auto"
// language uintptr
// detectLanguage bool
//
// // common decoding parameters:
// suppressBlank bool // ref: https://github.com/openai/whisper/blob/f82bc59f5ea234d4b97fb2860842ed38519f7e65/whisper/decoding.py#L89
// suppressNonSpeechTokens bool // ref: https://github.com/openai/whisper/blob/7858aa9c08d98f75575035ecd6481f462d66ca27/whisper/tokenizer.py#L224-L253
//
// temperature float32 // initial decoding temperature, ref: https://ai.stackexchange.com/a/32478
// maxInitialTs float32 // ref: https://github.com/openai/whisper/blob/f82bc59f5ea234d4b97fb2860842ed38519f7e65/whisper/decoding.py#L97
// lengthPenalty float32 // ref: https://github.com/openai/whisper/blob/f82bc59f5ea234d4b97fb2860842ed38519f7e65/whisper/transcribe.py#L267
//
// // fallback parameters
// // ref: https://github.com/openai/whisper/blob/f82bc59f5ea234d4b97fb2860842ed38519f7e65/whisper/transcribe.py#L274-L278
// temperatureInc float32
// entropyThold float32 // similar to OpenAI's "compression_ratio_threshold"
// logprobThold float32
// noSpeechThold float32 // [whisper.cpp] TODO: not implemented
//
// //struct {
// // int best_of; // ref: https://github.com/openai/whisper/blob/f82bc59f5ea234d4b97fb2860842ed38519f7e65/whisper/transcribe.py#L264
// //} greedy;
// greedy uintptr
//
// //struct {
// // int beam_size; // ref: https://github.com/openai/whisper/blob/f82bc59f5ea234d4b97fb2860842ed38519f7e65/whisper/transcribe.py#L265
// //
// // float patience; // TODO: not implemented, ref: https://arxiv.org/pdf/2204.05424.pdf
// //} beam_search;
// beamSearch uintptr
//
// // called for every newly generated text segment
// newSegmentCallback uintptr
// newSegmentCallbackUserData uintptr
//
// // called on each progress update
// progressCallback uintptr
// progressCallbackUserData uintptr
//
// // called each time before the encoder starts
// encoderBeginCallback uintptr
// encoderBeginCallbackUserData uintptr
//
// // called each time before ggml computation starts
// abortCallback uintptr
// abortCallbackUserData uintptr
//
// // called by each decoder to filter obtained logits
// logitsFilterCallback uintptr
// logitsFilterCallbackUserData uintptr
//
// grammarRules uintptr
// nGrammarRules int32
// iStartRule int32
// grammarPenalty float32
//}
type CWhisperFullParamsRef struct {
paramsRef uintptr
}
//type WhisperContextParams struct {
// UseGpu bool
//}
type CWhisperContextParamsRef struct {
paramsRef uintptr
}
type WhisperPos int
type WhisperToken int
type WhisperSeqId int
type WhisperSamplingStrategy int
const (
WHISPER_SAMPLING_GREEDY WhisperSamplingStrategy = iota
WHISPER_SAMPLING_BEAM_SEARCH
)
type WhisperSamplingStrategyStr string
const (
WHISPER_SAMPLING_GREEDY_S WhisperSamplingStrategyStr = "WHISPER_SAMPLING_GREEDY"
WHISPER_SAMPLING_BEAM_SEARCH_S = "WHISPER_SAMPLING_BEAM_SEARCH"
)
//type CWhisperTokenData struct {
//
//}
type CWhisper interface {
//=============================================whisper.h============================================================
// These APIs are compatible with memory structures and need to call whisper_abi
// WhisperInitFromFileWithParams WhisperInitFromBufferWithParams Various functions for loading a ggml whisper model.
// Allocate (almost) all memory needed for the model.
// Return NULL on failure
//WhisperInitFromFileWithParams(pathModel string, params *CWhisperContextParamsRef) *CWhisperContext
//WhisperInitFromBufferWithParams(buffer []byte, params *CWhisperContextParamsRef) *CWhisperContext
// whisper_init_with_params(struct whisper_model_loader * loader, struct whisper_context_params params) error
// WhisperInitFromFileWithParamsNoState These are the same as the above, but the internal state of the context is not allocated automatically
// It is the responsibility of the caller to allocate the state using whisper_init_state() (#523)
//WhisperInitFromFileWithParamsNoState(pathModel string, params *CWhisperContextParamsRef) *CWhisperContext
//WhisperInitFromBufferWithParamsNoState(buffer []byte, params *CWhisperContextParamsRef) *CWhisperContext
//whisper_init_with_params_no_state(struct whisper_model_loader * loader, struct whisper_context_params params)
WhisperInitState(ctx *CWhisperContext) *CWhisperState
// WhisperCtxInitOpenvinoEncoder Given a context, enable use of OpenVINO for encode inference.
// model_path: Optional path to OpenVINO encoder IR model. If set to nullptr,
// the path will be generated from the ggml model path that was passed
// in to whisper_init_from_file. For example, if 'path_model' was
// "/path/to/ggml-base.en.bin", then OpenVINO IR model path will be
// assumed to be "/path/to/ggml-base.en-encoder-openvino.xml".
// device: OpenVINO device to run inference on ("CPU", "GPU", etc.)
// cache_dir: Optional cache directory that can speed up init time, especially for
// GPU, by caching compiled 'blobs' there.
// Set to nullptr if not used.
// Returns 0 on success. If OpenVINO is not enabled in build, this simply returns 1.
WhisperCtxInitOpenvinoEncoder(ctx *CWhisperContext, modelPath, device, cacheDir string) *CWhisperState
// WhisperFree WhisperFreeState WhisperFreeParams WhisperFreeContextParams Frees all allocated memory
WhisperFree(ctx *CWhisperContext)
WhisperFreeState(state *CWhisperState)
WhisperFreeParams(params *CWhisperFullParamsRef)
WhisperFreeContextParams(params *CWhisperContextParamsRef)
// WhisperPcmToMel Convert RAW PCM audio to log mel spectrogram.
// The resulting spectrogram is stored inside the default state of the provided whisper context.
// Returns 0 on success
WhisperPcmToMel(ctx *CWhisperContext, samples []float32, nSamples, nThreads int) int
WhisperPcmToMelWithState(ctx *CWhisperContext, state *CWhisperState, samples []float32, nSamples, nThreads int) int
// WhisperPcmToMelPhaseVocoder Convert RAW PCM audio to log mel spectrogram but applies a Phase Vocoder to speed up the audio x2.
// The resulting spectrogram is stored inside the default state of the provided whisper context.
// Returns 0 on success
WhisperPcmToMelPhaseVocoder(ctx *CWhisperContext, samples []float32, nSamples, nThreads int) int
WhisperPcmToMelPhaseVocoderWithState(ctx *CWhisperContext, state *CWhisperState, samples []float32, nSamples, nThreads int) int
// WhisperSetMel This can be used to set a custom log mel spectrogram inside the default state of the provided whisper context.
// Use this instead of whisper_pcm_to_mel() if you want to provide your own log mel spectrogram.
// n_mel must be 80
// Returns 0 on success
WhisperSetMel(ctx *CWhisperContext, data []float32, nLen, nMel int) int
WhisperSetMelWithState(ctx *CWhisperContext, state *CWhisperState, data []float32, nLen, nMel int) int
// WhisperEncode Run the Whisper encoder on the log mel spectrogram stored inside the default state in the provided whisper context.
// Make sure to call whisper_pcm_to_mel() or whisper_set_mel() first.
// offset can be used to specify the offset of the first frame in the spectrogram.
// Returns 0 on success
WhisperEncode(ctx *CWhisperContext, offset, nThreads int) int
WhisperEncodeWithState(ctx *CWhisperContext, state *CWhisperState, offset, nThreads int) int
// WhisperDecode Run the Whisper decoder to obtain the logits and probabilities for the next token.
// Make sure to call whisper_encode() first.
// tokens + n_tokens is the provided context for the decoder.
// n_past is the number of tokens to use from previous decoder calls.
// Returns 0 on success
// [whisper.cpp] TODO: add support for multiple decoders
WhisperDecode(ctx *CWhisperContext, tokens []WhisperToken, nTokens, nPast, nThreads int) int
WhisperDecodeWithState(ctx *CWhisperContext, state *CWhisperState, tokens []WhisperToken, nTokens, nPast, nThreads int) int
// WhisperTokenize Convert the provided text into tokens.
// The tokens pointer must be large enough to hold the resulting tokens.
// Returns the number of tokens on success, no more than n_max_tokens
// Returns -1 on failure
// [whisper.cpp] TODO: not sure if correct
WhisperTokenize(ctx *CWhisperContext, text string, tokens []WhisperToken, nMaxTokens int) int
// WhisperLangMaxId Largest language id (i.e. number of available languages - 1)
WhisperLangMaxId() int
// WhisperLangId Return the id of the specified language, returns -1 if not found
// Examples:
// "de" -> 2
// "german" -> 2
WhisperLangId(lang string) int
// WhisperLangStr Return the short string of the specified language id (e.g. 2 -> "de"), returns nullptr if not found
WhisperLangStr(id int) string
// WhisperLangAutoDetect Use mel data at offset_ms to try and auto-detect the spoken language
// Make sure to call whisper_pcm_to_mel() or whisper_set_mel() first
// Returns the top language id or negative on failure
// If not null, fills the lang_probs array with the probabilities of all languages
// The array must be whisper_lang_max_id() + 1 in size
// ref: https://github.com/openai/whisper/blob/main/whisper/decoding.py#L18-L69
WhisperLangAutoDetect(ctx *CWhisperContext, offsetMs, nThreads int, langProbs []float32) int
WhisperLangAutoDetectWithState(ctx *CWhisperContext, state *CWhisperState, offsetMs, nThreads int, langProbs []float32) int
// WhisperNLen mel length
WhisperNLen(ctx *CWhisperContext) int
// WhisperNLenFromState mel length
WhisperNLenFromState(state *CWhisperState) int
WhisperNVocab(ctx *CWhisperContext) int
WhisperNTextCtx(ctx *CWhisperContext) int
WhisperNAudioCtx(ctx *CWhisperContext) int
WhisperIsMultilingual(ctx *CWhisperContext) int
WhisperModelNVocab(ctx *CWhisperContext) int
WhisperModelNAudioCtx(ctx *CWhisperContext) int
WhisperModelNAudioState(ctx *CWhisperContext) int
WhisperModelNAudioHead(ctx *CWhisperContext) int
WhisperModelNAudioLayer(ctx *CWhisperContext) int
WhisperModelNTextCtx(ctx *CWhisperContext) int
WhisperModelNTextState(ctx *CWhisperContext) int
WhisperModelNTextHead(ctx *CWhisperContext) int
WhisperModelNTextLayer(ctx *CWhisperContext) int
WhisperModelNMels(ctx *CWhisperContext) int
WhisperModelFtype(ctx *CWhisperContext) int
WhisperModelType(ctx *CWhisperContext) int
// WhisperGetLogits Token logits obtained from the last call to whisper_decode()
// The logits for the last token are stored in the last row
// Rows: n_tokens
// Cols: n_vocab
WhisperGetLogits(ctx *CWhisperContext) []float32
WhisperGetLogitsFromState(state *CWhisperState) []float32
// WhisperTokenToStr Token Id -> String. Uses the vocabulary in the provided context
WhisperTokenToStr(ctx *CWhisperContext, token WhisperToken) string
WhisperModelTypeReadable(ctx *CWhisperContext) string
// WhisperTokenEot WhisperTokenSot WhisperTokenSolm WhisperTokenPrev WhisperTokenNosp WhisperTokenNot WhisperTokenBeg WhisperTokenLang Special tokens
WhisperTokenEot(ctx *CWhisperContext) WhisperToken
WhisperTokenSot(ctx *CWhisperContext) WhisperToken
WhisperTokenSolm(ctx *CWhisperContext) WhisperToken
WhisperTokenPrev(ctx *CWhisperContext) WhisperToken
WhisperTokenNosp(ctx *CWhisperContext) WhisperToken
WhisperTokenNot(ctx *CWhisperContext) WhisperToken
WhisperTokenBeg(ctx *CWhisperContext) WhisperToken
WhisperTokenLang(ctx *CWhisperContext) WhisperToken
// WhisperTokenTranslate WhisperTokenTranscribe Task tokens
WhisperTokenTranslate(ctx *CWhisperContext) WhisperToken
WhisperTokenTranscribe(ctx *CWhisperContext) WhisperToken
// WhisperPrintTimings WhisperResetTimings Performance information from the default state.
WhisperPrintTimings(ctx *CWhisperContext)
WhisperResetTimings(ctx *CWhisperContext)
// WhisperPrintSystemInfo Print system information
WhisperPrintSystemInfo() string
// WhisperContextDefaultParamsByRef WhisperFullDefaultParamsByRef NOTE: this function allocates memory, and it is the responsibility of the caller to free the pointer - see whisper_free_context_params & whisper_free_params()
WhisperContextDefaultParamsByRef() *CWhisperContextParamsRef
WhisperFullDefaultParamsByRef(strategy WhisperSamplingStrategy) *CWhisperFullParamsRef
// These APIs are compatible with memory structures and need to call whisper_abi
//WhisperContextDefaultParams() *WhisperContextParams
//WhisperFullDefaultParams(strategy WhisperSamplingStrategy) *CWhisperFullParams
// These APIs are compatible with memory structures and need to call whisper_abi
// WhisperFull Run the entire model: PCM -> log mel spectrogram -> encoder -> decoder -> text
// Not thread safe for same context
// Uses the specified decoding strategy to obtain the text.
//WhisperFull(ctx *CWhisperContext, params *CWhisperFullParamsRef, samples []float32, nSamples int) int
//
//WhisperFullWithState(ctx *CWhisperContext, state *CWhisperState, params *CWhisperFullParamsRef, samples []float32, nSamples int) int
//
// WhisperFullParallel Split the input audio in chunks and process each chunk separately using whisper_full_with_state()
// Result is stored in the default state of the context
// Not thread safe if executed in parallel on the same context.
// It seems this approach can offer some speedup in some cases.
// However, the transcription accuracy can be worse at the beginning and end of each chunk.
//WhisperFullParallel(ctx *CWhisperContext, params *CWhisperFullParamsRef, samples []float32, nSamples, nProcessors int) int
// WhisperFullNSegments WhisperFullNSegmentsFromState Number of generated text segments
// A segment can be a few words, a sentence, or even a paragraph.
WhisperFullNSegments(ctx *CWhisperContext) int
WhisperFullNSegmentsFromState(state *CWhisperState) int
// WhisperFullLangId Language id associated with the context's default state
WhisperFullLangId(ctx *CWhisperContext) int
// WhisperFullLangIdFromState Language id associated with the provided state
WhisperFullLangIdFromState(state *CWhisperState) int
// WhisperFullGetSegmentT0 WhisperFullGetSegmentT0FromState Get the start and end time of the specified segment
WhisperFullGetSegmentT0(ctx *CWhisperContext, iSegment int) int64
WhisperFullGetSegmentT0FromState(state *CWhisperState, iSegment int) int64
WhisperFullGetSegmentT1(ctx *CWhisperContext, iSegment int) int64
WhisperFullGetSegmentT1FromState(state *CWhisperState, iSegment int) int64
// WhisperFullGetSegmentSpeakerTurnNext WhisperFullGetSegmentSpeakerTurnNextFromState Get whether the next segment is predicted as a speaker turn
WhisperFullGetSegmentSpeakerTurnNext(ctx *CWhisperContext, iSegment int) bool
WhisperFullGetSegmentSpeakerTurnNextFromState(state *CWhisperState, iSegment int) bool
// WhisperFullGetSegmentText WhisperFullGetSegmentTextFromState Get the text of the specified segment
WhisperFullGetSegmentText(ctx *CWhisperContext, iSegment int) string
WhisperFullGetSegmentTextFromState(state *CWhisperState, iSegment int) string
// WhisperFullNTokens Get number of tokens in the specified segment
WhisperFullNTokens(ctx *CWhisperContext, iSegment int) int
WhisperFullNTokensFromState(state *CWhisperState, iSegment int) int
// WhisperFullGetTokenText Get the token text of the specified token in the specified segment
WhisperFullGetTokenText(ctx *CWhisperContext, iSegment, iToken int) string
WhisperFullGetTokenTextFromState(ctx *CWhisperContext, state *CWhisperState, iSegment, iToken int) string
WhisperFullGetTokenId(ctx *CWhisperContext, iSegment, iToken int) WhisperToken
WhisperFullGetTokenIdFromState(state *CWhisperState, iSegment, iToken int) WhisperToken
// WhisperFullGetTokenData WhisperFullGetTokenDataFromState Get token data for the specified token in the specified segment
// This contains probabilities, timestamps, etc.
//WhisperFullGetTokenData(ctx *CWhisperContext, iSegment, iToken int) CWhisperTokenData
//WhisperFullGetTokenDataFromState(state *CWhisperState, iSegment, iToken int) CWhisperTokenData
// WhisperFullGetTokenP WhisperFullGetTokenPFromState Get the probability of the specified token in the specified segment
WhisperFullGetTokenP(ctx *CWhisperContext, iSegment, iToken int) float32
WhisperFullGetTokenPFromState(state *CWhisperState, iSegment, iToken int) float32
//=============================================whisper_abi.h========================================================
WhisperContextParamsSetUseGpu(ctx *CWhisperContext, useGPU bool)
WhisperFullParamsSetStrategy(ctx *CWhisperFullParamsRef, strategy string)
WhisperFullParamsSetNThreads(ctx *CWhisperFullParamsRef, nThreads int)
WhisperFullParamsSetNMaxTextCtx(ctx *CWhisperFullParamsRef, nMaxTextCtx int)
WhisperFullParamsSetOffsetMs(ctx *CWhisperFullParamsRef, offsetMs int)
WhisperFullParamsSetDurationMs(ctx *CWhisperFullParamsRef, durationMs int)
WhisperFullParamsSetTranslate(ctx *CWhisperFullParamsRef, translate bool)
WhisperFullParamsSetNoContext(ctx *CWhisperFullParamsRef, noContext bool)
WhisperFullParamsSetNoTimestamps(ctx *CWhisperFullParamsRef, noTimestamps bool)
WhisperFullParamsSetSingleSegment(ctx *CWhisperFullParamsRef, singleSegment bool)
WhisperFullParamsSetPrintSpecial(ctx *CWhisperFullParamsRef, printSpecial bool)
WhisperFullParamsSetPrintProgress(ctx *CWhisperFullParamsRef, printProgress bool)
WhisperFullParamsSetPrintRealtime(ctx *CWhisperFullParamsRef, printRealtime bool)
WhisperFullParamsSetPrintTimestamps(ctx *CWhisperFullParamsRef, printTimestamps bool)
WhisperFullParamsSetTokenTimestamps(ctx *CWhisperFullParamsRef, tokenTimestamps bool)
WhisperFullParamsSetTholdPt(ctx *CWhisperFullParamsRef, tholdPt float32)
WhisperFullParamsSetTholdPtsum(ctx *CWhisperFullParamsRef, tholdPtsum float32)
WhisperFullParamsSetMaxLen(ctx *CWhisperFullParamsRef, maxLen int)
WhisperFullParamsSetSplitOnWord(ctx *CWhisperFullParamsRef, splitOnWord bool)
WhisperFullParamsSetMaxTokens(ctx *CWhisperFullParamsRef, maxTokens int)
WhisperFullParamsSetSpeedUp(ctx *CWhisperFullParamsRef, speedUp bool)
WhisperFullParamsSetDebugMode(ctx *CWhisperFullParamsRef, debugMode bool)
WhisperFullParamsSetAudioCtx(ctx *CWhisperFullParamsRef, audioCtx int)
WhisperFullParamsSetTdrzEnable(ctx *CWhisperFullParamsRef, tdrzEnable bool)
WhisperFullParamsSetInitialPrompt(ctx *CWhisperFullParamsRef, initialPrompt string)
WhisperFullParamsSetPromptTokens(ctx *CWhisperFullParamsRef, promptTokens []int32)
WhisperFullParamsSetPromptNTokens(ctx *CWhisperFullParamsRef, promptNTokens int)
WhisperFullParamsSetLanguage(ctx *CWhisperFullParamsRef, language string)
WhisperFullParamsSetDetectLanguage(ctx *CWhisperFullParamsRef, detectLanguage bool)
WhisperFullParamsSetSuppressBlank(ctx *CWhisperFullParamsRef, suppressBlank bool)
WhisperFullParamsSetSuppressNonSpeechTokens(ctx *CWhisperFullParamsRef, suppressNonSpeechTokens bool)
WhisperFullParamsSetTemperature(ctx *CWhisperFullParamsRef, temperature float32)
WhisperFullParamsSetMaxInitialTs(ctx *CWhisperFullParamsRef, maxInitialTs float32)
WhisperFullParamsSetLengthPenalty(ctx *CWhisperFullParamsRef, lengthPenalty float32)
WhisperFullParamsSetTemperatureInc(ctx *CWhisperFullParamsRef, temperatureInc float32)
WhisperFullParamsSetEntropyThold(ctx *CWhisperFullParamsRef, entropyThold float32)
WhisperFullParamsSetLogprobThold(ctx *CWhisperFullParamsRef, logprobThold float32)
WhisperFullParamsSetNoSpeechThold(ctx *CWhisperFullParamsRef, noSpeechThold float32)
WhisperFullParamsSetGreedyBestOf(ctx *CWhisperFullParamsRef, bestOf int)
WhisperFullParamsSetBeamSearchBeamSize(ctx *CWhisperFullParamsRef, beamSize int)
WhisperFullParamsSetBeamSearchPatience(ctx *CWhisperFullParamsRef, patience float32)
WhisperInitFromFileWithParamsRef(pathModel string, params *CWhisperContextParamsRef) *CWhisperContext
WhisperInitFromBufferWithParamsRef(buffer []byte, params *CWhisperContextParamsRef) *CWhisperContext
WhisperInitFromFileWithParamsRefNoState(pathModel string, params *CWhisperContextParamsRef) *CWhisperContext
WhisperInitFromBufferWithParamsRefNoState(buffer []byte, params *CWhisperContextParamsRef) *CWhisperContext
WhisperFullRef(ctx *CWhisperContext, params *CWhisperFullParamsRef, samples []byte) int
WhisperFullRefWithState(ctx *CWhisperContext, state *CWhisperState, params *CWhisperFullParamsRef, samples []byte) int
WhisperFullRefParallel(ctx *CWhisperContext, params *CWhisperFullParamsRef, samples []byte, nProcessors int) int
}
type CWhisperImpl struct {
libWhisper uintptr
//=============================================whisper.h============================================================
//cWhisperInitFromFileWithParams func(pathModel string, params uintptr) uintptr
//cWhisperInitFromBufferWithParams func(buffer uintptr, bufferSize int, params uintptr) uintptr
//cWhisperInitWithParams func()
//cWhisperInitFromFileWithParamsNoState func(pathModel string, params uintptr) uintptr
//cWhisperInitFromBufferWithParamsNoState func(buffer uintptr, bufferSize int, params uintptr) uintptr
//cWhisperInitWithParamsNoState func()
cWhisperInitState func(ctx uintptr) uintptr
cWhisperCtxInitOpenvinoEncoder func(ctx uintptr, modelPath, device, cacheDir string) uintptr
cWhisperFree func(ctx uintptr)
cWhisperFreeState func(state uintptr)
cWhisperFreeParams func(params uintptr)
cWhisperFreeContextParams func(params uintptr)
cWhisperPcmToMel func(ctx uintptr, samples *float32, nSamples, nThreads int) int
cWhisperPcmToMelWithState func(ctx uintptr, state uintptr, samples *float32, nSamples, nThreads int) int
cWhisperPcmToMelPhaseVocoder func(ctx uintptr, samples *float32, nSamples, nThreads int) int
cWhisperPcmToMelPhaseVocoderWithState func(ctx uintptr, state uintptr, samples *float32, nSamples, nThreads int) int
cWhisperSetMel func(ctx uintptr, data *float32, nLen, nMel int) int
cWhisperSetMelWithState func(ctx uintptr, state uintptr, data *float32, nLen, nMel int) int
cWhisperEncode func(ctx uintptr, offset, nThreads int) int
cWhisperEncodeWithState func(ctx uintptr, state uintptr, offset, nThreads int) int
cWhisperDecode func(ctx uintptr, tokens *int, nTokens, nPast, nThreads int) int
cWhisperDecodeWithState func(ctx uintptr, state uintptr, tokens *int, nTokens, nPast, nThreads int) int
cWhisperTokenize func(ctx uintptr, text string, tokens *int, nMaxTokens int) int
cWhisperLangMaxId func() int
cWhisperLangId func(lang string) int
cWhisperLangStr func(lang int) string
cWhisperLangAutoDetect func(ctx uintptr, offsetMs, nThreads int, langProbs *float32) int
cWhisperLangAutoDetectWithState func(ctx uintptr, state uintptr, offsetMs, nThreads int, langProbs *float32) int
cWhisperNLen func(ctx uintptr) int
cWhisperNLenFromState func(ctx uintptr) int
cWhisperNVocab func(ctx uintptr) int
cWhisperNTextCtx func(ctx uintptr) int
cWhisperNAudioCtx func(ctx uintptr) int
cWhisperIsMultilingual func(ctx uintptr) int
cWhisperModelNVocab func(ctx uintptr) int
cWhisperModelNAudioCtx func(ctx uintptr) int
cWhisperModelNAudioState func(ctx uintptr) int
cWhisperModelNAudioHead func(ctx uintptr) int
cWhisperModelNAudioLayer func(ctx uintptr) int
cWhisperModelNTextCtx func(ctx uintptr) int
cWhisperModelNTextState func(ctx uintptr) int
cWhisperModelNTextHead func(ctx uintptr) int
cWhisperModelNTextLayer func(ctx uintptr) int
cWhisperModelNMels func(ctx uintptr) int
cWhisperModelFtype func(ctx uintptr) int
cWhisperModelType func(ctx uintptr) int
cWhisperGetLogits func(ctx uintptr) *float32
cWhisperGetLogitsFromState func(state uintptr) *float32
cWhisperTokenToStr func(ctx uintptr, token int) string
cWhisperModelTypeReadable func(ctx uintptr) string
cWhisperTokenEot func(ctx uintptr) int
cWhisperTokenSot func(ctx uintptr) int
cWhisperTokenSolm func(ctx uintptr) int
cWhisperTokenPrev func(ctx uintptr) int
cWhisperTokenNosp func(ctx uintptr) int
cWhisperTokenNot func(ctx uintptr) int
cWhisperTokenBeg func(ctx uintptr) int
cWhisperTokenLang func(ctx uintptr) int
cWhisperTokenTranslate func(ctx uintptr) int
cWhisperTokenTranscribe func(ctx uintptr) int
cWhisperPrintTimings func(ctx uintptr)
cWhisperResetTimings func(ctx uintptr)
cWhisperPrintSystemInfo func() string
cWhisperContextDefaultParamsByRef func() uintptr
cWhisperContextDefaultParams func() uintptr
cWhisperFullDefaultParamsByRef func(strategy int) uintptr
cWhisperFullDefaultParams func(strategy int) uintptr
//cWhisperFull func(ctx uintptr, params uintptr, samples *float32, nSamples int) int
//cWhisperFullWithState func(ctx uintptr, state uintptr, params uintptr, samples *float32, nSamples int) int
//
//cWhisperFullParallel func(ctx uintptr, params uintptr, samples *float32, nSamples, nProcessors int) int
cWhisperFullNSegments func(ctx uintptr) int
cWhisperFullNSegmentsFromState func(state uintptr) int
cWhisperFullLangId func(ctx uintptr) int
cWhisperFullLangIdFromState func(state uintptr) int
cWhisperFullGetSegmentT0 func(ctx uintptr, iSegment int) int64
cWhisperFullGetSegmentT0FromState func(state uintptr, iSegment int) int64
cWhisperFullGetSegmentT1 func(ctx uintptr, iSegment int) int64
cWhisperFullGetSegmentT1FromState func(state uintptr, iSegment int) int64
cWhisperFullGetSegmentSpeakerTurnNext func(ctx uintptr, iSegment int) bool
cWhisperFullGetSegmentSpeakerTurnNextFromState func(state uintptr, iSegment int) bool
cWhisperFullGetSegmentText func(ctx uintptr, iSegment int) string
cWhisperFullGetSegmentTextFromState func(ctx uintptr, state uintptr, iSegment int) string
cWhisperFullNTokens func(ctx uintptr, iSegment int) int
cWhisperFullNTokensFromState func(state uintptr, iSegment int) int
cWhisperFullGetTokenText func(ctx uintptr, iSegment, iToken int) string
cWhisperFullGetTokenTextFromState func(ctx uintptr, state uintptr, iSegment, iToken int) string
cWhisperFullGetTokenId func(ctx uintptr, iSegment, iToken int) int
cWhisperFullGetTokenIdFromState func(state uintptr, iSegment, iToken int) int
//cWhisperFullGetTokenData func()
//cWhisperFullGetTokenDataFromState func()
cWhisperFullGetTokenP func(ctx uintptr, iSegment, iToken int) float32
cWhisperFullGetTokenPFromState func(state uintptr, iSegment, iToken int) float32
//=============================================whisper_abi.h========================================================
cWhisperContextParamsSetUseGpu func(ctx uintptr, useGPU bool)
cWhisperFullParamsSetStrategy func(ctx uintptr, strategy string)
cWhisperFullParamsSetNThreads func(ctx uintptr, nThreads int)
cWhisperFullParamsSetNMaxTextCtx func(ctx uintptr, nMaxTextCtx int)
cWhisperFullParamsSetOffsetMs func(ctx uintptr, offsetMs int)
cWhisperFullParamsSetDurationMs func(ctx uintptr, durationMs int)
cWhisperFullParamsSetTranslate func(ctx uintptr, translate bool)
cWhisperFullParamsSetNoContext func(ctx uintptr, noContext bool)
cWhisperFullParamsSetNoTimestamps func(ctx uintptr, noTimestamps bool)
cWhisperFullParamsSetSingleSegment func(ctx uintptr, singleSegment bool)
cWhisperFullParamsSetPrintSpecial func(ctx uintptr, printSpecial bool)
cWhisperFullParamsSetPrintProgress func(ctx uintptr, printProgress bool)
cWhisperFullParamsSetPrintRealtime func(ctx uintptr, printRealtime bool)
cWhisperFullParamsSetPrintTimestamps func(ctx uintptr, printTimestamps bool)
cWhisperFullParamsSetTokenTimestamps func(ctx uintptr, tokenTimestamps bool)
cWhisperFullParamsSetTholdPt func(ctx uintptr, tholdPt float32)
cWhisperFullParamsSetTholdPtsum func(ctx uintptr, tholdPtsum float32)
cWhisperFullParamsSetMaxLen func(ctx uintptr, maxLen int)
cWhisperFullParamsSetSplitOnWord func(ctx uintptr, splitOnWord bool)
cWhisperFullParamsSetMaxTokens func(ctx uintptr, maxTokens int)
cWhisperFullParamsSetSpeedUp func(ctx uintptr, speedUp bool)
cWhisperFullParamsSetDebugMode func(ctx uintptr, debugMode bool)
cWhisperFullParamsSetAudioCtx func(ctx uintptr, audioCtx int)
cWhisperFullParamsSetTdrzEnable func(ctx uintptr, tdrzEnable bool)
cWhisperFullParamsSetInitialPrompt func(ctx uintptr, initialPrompt string)
cWhisperFullParamsSetPromptTokens func(ctx uintptr, promptTokens *int32)
cWhisperFullParamsSetPromptNTokens func(ctx uintptr, promptNTokens int)
cWhisperFullParamsSetLanguage func(ctx uintptr, language string)
cWhisperFullParamsSetDetectLanguage func(ctx uintptr, detectLanguage bool)
cWhisperFullParamsSetSuppressBlank func(ctx uintptr, suppressBlank bool)
cWhisperFullParamsSetSuppressNonSpeechTokens func(ctx uintptr, suppressNonSpeechTokens bool)
cWhisperFullParamsSetTemperature func(ctx uintptr, temperature float32)
cWhisperFullParamsSetMaxInitialTs func(ctx uintptr, maxInitialTs float32)
cWhisperFullParamsSetLengthPenalty func(ctx uintptr, lengthPenalty float32)
cWhisperFullParamsSetTemperatureInc func(ctx uintptr, temperatureInc float32)
cWhisperFullParamsSetEntropyThold func(ctx uintptr, entropyThold float32)
cWhisperFullParamsSetLogprobThold func(ctx uintptr, logprobThold float32)
cWhisperFullParamsSetNoSpeechThold func(ctx uintptr, noSpeechThold float32)
cWhisperFullParamsSetGreedyBestOf func(ctx uintptr, bestOf int)
cWhisperFullParamsSetBeamSearchBeamSize func(ctx uintptr, beamSize int)
cWhisperFullParamsSetBeamSearchPatience func(ctx uintptr, patience float32)
whisperInitFromFileWithParamsRef func(pathModel string, params uintptr) uintptr
whisperInitFromBufferWithParamsRef func(buffer uintptr, bufferSize int64, params uintptr) uintptr
whisperInitFromFileWithParamsRefNoState func(pathModel string, params uintptr) uintptr
whisperInitFromBufferWithParamsRefNoState func(buffer uintptr, bufferSize int64, params uintptr) uintptr
cWhisperFullParamsFullRef func(ctx uintptr, params uintptr, samples *byte, nSamples int) int
cWhisperFullParamsFullRefWithState func(ctx uintptr, state uintptr, params uintptr, samples *byte, nSamples int) int
cWhisperFullParamsFullRefParallel func(ctx uintptr, params uintptr, samples *byte, nSamples int, nProcessors int) int
}
func NewCWhisper(libraryPath string) (CWhisper, error) {
libWhisper, err := openLibrary(libraryPath)
if err != nil {
return nil, err
}
var (
//=============================================whisper.h========================================================
//whisperInitFromFileWithParams func(pathModel string, params uintptr) uintptr
//whisperInitFromBufferWithParams func(buffer uintptr, bufferSize int, params uintptr) uintptr
//whisperInitWithParams func()
//whisperInitFromFileWithParamsNoState func(pathModel string, params uintptr) uintptr
//whisperInitFromBufferWithParamsNoState func(buffer uintptr, bufferSize int, params uintptr) uintptr
//whisperInitWithParamsNoState func()
whisperInitState func(ctx uintptr) uintptr
whisperCtxInitOpenvinoEncoder func(ctx uintptr, modelPath, device, cacheDir string) uintptr
whisperFree func(ctx uintptr)
whisperFreeState func(state uintptr)
whisperFreeParams func(params uintptr)
whisperFreeContextParams func(params uintptr)
whisperPcmToMel func(ctx uintptr, samples *float32, nSamples, nThreads int) int
whisperPcmToMelWithState func(ctx uintptr, state uintptr, samples *float32, nSamples, nThreads int) int
whisperPcmToMelPhaseVocoder func(ctx uintptr, samples *float32, nSamples, nThreads int) int
whisperPcmToMelPhaseVocoderWithState func(ctx uintptr, state uintptr, samples *float32, nSamples, nThreads int) int
whisperSetMel func(ctx uintptr, data *float32, nLen, nMel int) int
whisperSetMelWithState func(ctx uintptr, state uintptr, data *float32, nLen, nMel int) int
whisperEncode func(ctx uintptr, offset, nThreads int) int
whisperEncodeWithState func(ctx uintptr, state uintptr, offset, nThreads int) int
whisperDecode func(ctx uintptr, tokens *int, nTokens, nPast, nThreads int) int
whisperDecodeWithState func(ctx uintptr, state uintptr, tokens *int, nTokens, nPast, nThreads int) int
whisperTokenize func(ctx uintptr, text string, tokens *int, nMaxTokens int) int
whisperLangMaxId func() int
whisperLangId func(lang string) int
whisperLangStr func(lang int) string
whisperLangAutoDetect func(ctx uintptr, offsetMs, nThreads int, langProbs *float32) int
whisperLangAutoDetectWithState func(ctx uintptr, state uintptr, offsetMs, nThreads int, langProbs *float32) int
whisperNLen func(ctx uintptr) int
whisperNLenFromState func(ctx uintptr) int
whisperNVocab func(ctx uintptr) int
whisperNTextCtx func(ctx uintptr) int
whisperNAudioCtx func(ctx uintptr) int
whisperIsMultilingual func(ctx uintptr) int
whisperModelNVocab func(ctx uintptr) int
whisperModelNAudioCtx func(ctx uintptr) int
whisperModelNAudioState func(ctx uintptr) int
whisperModelNAudioHead func(ctx uintptr) int
whisperModelNAudioLayer func(ctx uintptr) int
whisperModelNTextCtx func(ctx uintptr) int
whisperModelNTextState func(ctx uintptr) int
whisperModelNTextHead func(ctx uintptr) int
whisperModelNTextLayer func(ctx uintptr) int
whisperModelNMels func(ctx uintptr) int
whisperModelFtype func(ctx uintptr) int
whisperModelType func(ctx uintptr) int
whisperGetLogits func(ctx uintptr) *float32
whisperGetLogitsFromState func(state uintptr) *float32
whisperTokenToStr func(ctx uintptr, token int) string
whisperModelTypeReadable func(ctx uintptr) string
whisperTokenEot func(ctx uintptr) int
whisperTokenSot func(ctx uintptr) int
whisperTokenSolm func(ctx uintptr) int
whisperTokenPrev func(ctx uintptr) int
whisperTokenNosp func(ctx uintptr) int
whisperTokenNot func(ctx uintptr) int
whisperTokenBeg func(ctx uintptr) int
whisperTokenLang func(ctx uintptr) int
whisperTokenTranslate func(ctx uintptr) int
whisperTokenTranscribe func(ctx uintptr) int
whisperPrintTimings func(ctx uintptr)
whisperResetTimings func(ctx uintptr)
whisperPrintSystemInfo func() string
whisperContextDefaultParamsByRef func() uintptr
whisperContextDefaultParams func() uintptr
whisperFullDefaultParamsByRef func(strategy int) uintptr
whisperFullDefaultParams func(strategy int) uintptr
//whisperFull func(ctx uintptr, params uintptr, samples *float32, nSamples int) int
//whisperFullWithState func(ctx uintptr, state uintptr, params uintptr, samples *float32, nSamples int) int
//
//whisperFullParallel func(ctx uintptr, params uintptr, samples *float32, nSamples, nProcessors int) int
whisperFullNSegments func(ctx uintptr) int
whisperFullNSegmentsFromState func(state uintptr) int
whisperFullLangId func(ctx uintptr) int
whisperFullLangIdFromState func(state uintptr) int
whisperFullGetSegmentT0 func(ctx uintptr, iSegment int) int64
whisperFullGetSegmentT0FromState func(state uintptr, iSegment int) int64
whisperFullGetSegmentT1 func(ctx uintptr, iSegment int) int64
whisperFullGetSegmentT1FromState func(state uintptr, iSegment int) int64
whisperFullGetSegmentSpeakerTurnNext func(ctx uintptr, iSegment int) bool
whisperFullGetSegmentSpeakerTurnNextFromState func(state uintptr, iSegment int) bool
whisperFullGetSegmentText func(ctx uintptr, iSegment int) string
whisperFullGetSegmentTextFromState func(ctx uintptr, state uintptr, iSegment int) string
whisperFullNTokens func(ctx uintptr, iSegment int) int
whisperFullNTokensFromState func(state uintptr, iSegment int) int
whisperFullGetTokenText func(ctx uintptr, iSegment, iToken int) string
whisperFullGetTokenTextFromState func(ctx uintptr, state uintptr, iSegment, iToken int) string
whisperFullGetTokenId func(ctx uintptr, iSegment, iToken int) int
whisperFullGetTokenIdFromState func(state uintptr, iSegment, iToken int) int
//whisperFullGetTokenData func()
//whisperFullGetTokenDataFromState func()
whisperFullGetTokenP func(ctx uintptr, iSegment, iToken int) float32
whisperFullGetTokenPFromState func(state uintptr, iSegment, iToken int) float32
//=============================================whisper_abi.h====================================================
whisperContextParamsSetUseGpu func(ctx uintptr, useGPU bool)
whisperFullParamsSetStrategy func(ctx uintptr, strategy string)
whisperFullParamsSetNThreads func(ctx uintptr, nThreads int)
whisperFullParamsSetNMaxTextCtx func(ctx uintptr, nMaxTextCtx int)
whisperFullParamsSetOffsetMs func(ctx uintptr, offsetMs int)
whisperFullParamsSetDurationMs func(ctx uintptr, durationMs int)
whisperFullParamsSetTranslate func(ctx uintptr, translate bool)
whisperFullParamsSetNoContext func(ctx uintptr, noContext bool)
whisperFullParamsSetNoTimestamps func(ctx uintptr, noTimestamps bool)
whisperFullParamsSetSingleSegment func(ctx uintptr, singleSegment bool)
whisperFullParamsSetPrintSpecial func(ctx uintptr, printSpecial bool)
whisperFullParamsSetPrintProgress func(ctx uintptr, printProgress bool)
whisperFullParamsSetPrintRealtime func(ctx uintptr, printRealtime bool)
whisperFullParamsSetPrintTimestamps func(ctx uintptr, printTimestamps bool)
whisperFullParamsSetTokenTimestamps func(ctx uintptr, tokenTimestamps bool)
whisperFullParamsSetTholdPt func(ctx uintptr, tholdPt float32)
whisperFullParamsSetTholdPtsum func(ctx uintptr, tholdPtsum float32)
whisperFullParamsSetMaxLen func(ctx uintptr, maxLen int)
whisperFullParamsSetSplitOnWord func(ctx uintptr, splitOnWord bool)
whisperFullParamsSetMaxTokens func(ctx uintptr, maxTokens int)