Some checks failed
Bindings Tests (Go) / ubuntu-22 (push) Failing after 31s
CI (sycl) / ubuntu-22-cmake-sycl (linux/arm/v7, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl (linux/ppc64le, icx, icpx, ON) (push) Failing after 2s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/amd64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/arm/v7, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/arm64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/ppc64le, icx, icpx, ON) (push) Failing after 3s
CI (vad) / vad (push) Failing after 3s
CI (wasm) / emscripten (Release) (push) Failing after 4s
Bindings Tests (Ruby) / ubuntu-22 (push) Failing after 37s
CI (android) / android (push) Failing after 16s
CI (android) / android_java (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/amd64, Debug) (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/amd64, Release) (push) Failing after 2s
CI (clang) / ubuntu-22-clang (linux/ppc64le, Debug) (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/ppc64le, Release) (push) Failing after 3s
CI (cpu) / ggml-ci-x64-cpu-low-perf (push) Failing after 3s
CI (cpu) / ggml-ci-x64-cpu-high-perf (push) Failing after 2s
CI (gcc) / ubuntu-22-gcc (linux/amd64, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/amd64, Release) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/ppc64le, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/ppc64le, Release) (push) Failing after 4s
CI (gcc) / ubuntu-22-gcc-arm-v7 (linux/arm/v7, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc-arm-v7 (linux/arm/v7, Release) (push) Failing after 3s
CI (quantize) / quantize (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (ADDRESS) (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (THREAD) (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (UNDEFINED) (push) Failing after 2s
CI (sycl) / ubuntu-22-cmake-sycl (linux/amd64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl (linux/arm64, icx, icpx, ON) (push) Failing after 3s
Examples WASM / deploy-wasm-github-pages (push) Failing after 3s
Examples Tests / addon_node-ubuntu-22 (20.x) (push) Failing after 3s
Examples Tests / addon_node-ubuntu-22 (22.x) (push) Failing after 2s
CI (coreml) / coreml-base-en (push) Has been cancelled
CI (self-hosted) / gpu-vulkan (push) Has been cancelled
CI (self-hosted) / npu-amd-windows (push) Has been cancelled
CI (self-hosted) / gpu-vulkan-nvidia-cm2 (push) Has been cancelled
CI (clang) / ubuntu-22-clang-arm64 (Debug) (push) Has been cancelled
CI (clang) / ubuntu-22-clang-arm64 (Release) (push) Has been cancelled
CI (self-hosted) / gpu-cuda (push) Has been cancelled
CI (self-hosted) / gpu-vulkan-nvidia-cm (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-low-perf (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-high-perf (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-high-perf-sve (push) Has been cancelled
CI (freebsd) / freeBSD-latest (push) Has been cancelled
CI (self-hosted) / gpu-metal (push) Has been cancelled
CI (gcc) / ubuntu-22-gcc-arm64 (Debug) (push) Has been cancelled
CI (gcc) / ubuntu-22-gcc-arm64 (Release) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=iOS) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=macOS) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=tvOS) (push) Has been cancelled
CI (self-hosted) / npu-amd-linux (push) Has been cancelled
CI (windows) / windows-msys2 (Release, clang, clang-x86_64, CLANG64) (push) Has been cancelled
CI (windows) / windows-msys2 (Release, gcc, ucrt-x86_64, UCRT64) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-cuda.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-cuda]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-intel.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-intel]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-musa.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-musa]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-vulkan.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-vulkan]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-vulkan.Dockerfile platform:linux/arm64 runs_on:ubuntu-24.04-arm tag:main-vulkan-arm64]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main.Dockerfile platform:linux/arm64 runs_on:ubuntu-24.04-arm tag:main-arm64]) (push) Has been cancelled
Mark inactive issues stale / mark-issues (push) Failing after 1s
245 lines
5.2 KiB
Go
245 lines
5.2 KiB
Go
package whisper
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// CGO
|
|
|
|
/*
|
|
#include <whisper.h>
|
|
*/
|
|
import "C"
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// PUBLIC METHODS
|
|
|
|
func (p *Params) SetTranslate(v bool) {
|
|
p.translate = toBool(v)
|
|
}
|
|
|
|
func (p *Params) SetSplitOnWord(v bool) {
|
|
p.split_on_word = toBool(v)
|
|
}
|
|
|
|
func (p *Params) SetNoContext(v bool) {
|
|
p.no_context = toBool(v)
|
|
}
|
|
|
|
func (p *Params) SetSingleSegment(v bool) {
|
|
p.single_segment = toBool(v)
|
|
}
|
|
|
|
func (p *Params) SetPrintSpecial(v bool) {
|
|
p.print_special = toBool(v)
|
|
}
|
|
|
|
func (p *Params) SetPrintProgress(v bool) {
|
|
p.print_progress = toBool(v)
|
|
}
|
|
|
|
func (p *Params) SetPrintRealtime(v bool) {
|
|
p.print_realtime = toBool(v)
|
|
}
|
|
|
|
func (p *Params) SetPrintTimestamps(v bool) {
|
|
p.print_timestamps = toBool(v)
|
|
}
|
|
|
|
// Voice Activity Detection (VAD)
|
|
func (p *Params) SetVAD(v bool) {
|
|
p.vad = toBool(v)
|
|
}
|
|
|
|
func (p *Params) SetVADModelPath(path string) {
|
|
p.vad_model_path = C.CString(path)
|
|
}
|
|
|
|
func (p *Params) SetVADThreshold(t float32) {
|
|
p.vad_params.threshold = C.float(t)
|
|
}
|
|
|
|
func (p *Params) SetVADMinSpeechMs(ms int) {
|
|
p.vad_params.min_speech_duration_ms = C.int(ms)
|
|
}
|
|
|
|
func (p *Params) SetVADMinSilenceMs(ms int) {
|
|
p.vad_params.min_silence_duration_ms = C.int(ms)
|
|
}
|
|
|
|
func (p *Params) SetVADMaxSpeechSec(s float32) {
|
|
p.vad_params.max_speech_duration_s = C.float(s)
|
|
}
|
|
|
|
func (p *Params) SetVADSpeechPadMs(ms int) {
|
|
p.vad_params.speech_pad_ms = C.int(ms)
|
|
}
|
|
|
|
func (p *Params) SetVADSamplesOverlap(sec float32) {
|
|
p.vad_params.samples_overlap = C.float(sec)
|
|
}
|
|
|
|
// Set language id
|
|
func (p *Params) SetLanguage(lang int) error {
|
|
if lang == -1 {
|
|
p.language = nil
|
|
return nil
|
|
}
|
|
str := C.whisper_lang_str(C.int(lang))
|
|
if str == nil {
|
|
return ErrInvalidLanguage
|
|
} else {
|
|
p.language = str
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Get language id
|
|
func (p *Params) Language() int {
|
|
if p.language == nil {
|
|
return -1
|
|
}
|
|
return int(C.whisper_lang_id(p.language))
|
|
}
|
|
|
|
// Threads available
|
|
func (p *Params) Threads() int {
|
|
return int(p.n_threads)
|
|
}
|
|
|
|
// Set number of threads to use
|
|
func (p *Params) SetThreads(threads int) {
|
|
p.n_threads = C.int(threads)
|
|
}
|
|
|
|
// Set start offset in ms
|
|
func (p *Params) SetOffset(offset_ms int) {
|
|
p.offset_ms = C.int(offset_ms)
|
|
}
|
|
|
|
// Set audio duration to process in ms
|
|
func (p *Params) SetDuration(duration_ms int) {
|
|
p.duration_ms = C.int(duration_ms)
|
|
}
|
|
|
|
// Set timestamp token probability threshold (~0.01)
|
|
func (p *Params) SetTokenThreshold(t float32) {
|
|
p.thold_pt = C.float(t)
|
|
}
|
|
|
|
// Set timestamp token sum probability threshold (~0.01)
|
|
func (p *Params) SetTokenSumThreshold(t float32) {
|
|
p.thold_ptsum = C.float(t)
|
|
}
|
|
|
|
// Set max segment length in characters
|
|
func (p *Params) SetMaxSegmentLength(n int) {
|
|
p.max_len = C.int(n)
|
|
}
|
|
|
|
func (p *Params) SetTokenTimestamps(b bool) {
|
|
p.token_timestamps = toBool(b)
|
|
}
|
|
|
|
// Set max tokens per segment (0 = no limit)
|
|
func (p *Params) SetMaxTokensPerSegment(n int) {
|
|
p.max_tokens = C.int(n)
|
|
}
|
|
|
|
// Set audio encoder context
|
|
func (p *Params) SetAudioCtx(n int) {
|
|
p.audio_ctx = C.int(n)
|
|
}
|
|
|
|
func (p *Params) SetMaxContext(n int) {
|
|
p.n_max_text_ctx = C.int(n)
|
|
}
|
|
|
|
func (p *Params) SetBeamSize(n int) {
|
|
p.beam_search.beam_size = C.int(n)
|
|
}
|
|
|
|
func (p *Params) SetEntropyThold(t float32) {
|
|
p.entropy_thold = C.float(t)
|
|
}
|
|
|
|
func (p *Params) SetTemperature(t float32) {
|
|
p.temperature = C.float(t)
|
|
}
|
|
|
|
// Sets the fallback temperature incrementation
|
|
// Pass -1.0 to disable this feature
|
|
func (p *Params) SetTemperatureFallback(t float32) {
|
|
p.temperature_inc = C.float(t)
|
|
}
|
|
|
|
// Set initial prompt
|
|
func (p *Params) SetInitialPrompt(prompt string) {
|
|
p.initial_prompt = C.CString(prompt)
|
|
}
|
|
|
|
func (p *Params) SetCarryInitialPrompt(v bool) {
|
|
p.carry_initial_prompt = toBool(v)
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// PRIVATE METHODS
|
|
|
|
func toBool(v bool) C.bool {
|
|
if v {
|
|
return C.bool(true)
|
|
}
|
|
return C.bool(false)
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// STRINGIFY
|
|
|
|
func (p *Params) String() string {
|
|
str := "<whisper.params"
|
|
str += fmt.Sprintf(" strategy=%v", p.strategy)
|
|
str += fmt.Sprintf(" n_threads=%d", p.n_threads)
|
|
if p.language != nil {
|
|
str += fmt.Sprintf(" language=%s", C.GoString(p.language))
|
|
}
|
|
str += fmt.Sprintf(" n_max_text_ctx=%d", p.n_max_text_ctx)
|
|
str += fmt.Sprintf(" offset_ms=%d", p.offset_ms)
|
|
str += fmt.Sprintf(" duration_ms=%d", p.duration_ms)
|
|
str += fmt.Sprintf(" audio_ctx=%d", p.audio_ctx)
|
|
str += fmt.Sprintf(" initial_prompt=%s", C.GoString(p.initial_prompt))
|
|
str += fmt.Sprintf(" entropy_thold=%f", p.entropy_thold)
|
|
str += fmt.Sprintf(" temperature=%f", p.temperature)
|
|
str += fmt.Sprintf(" temperature_inc=%f", p.temperature_inc)
|
|
str += fmt.Sprintf(" beam_size=%d", p.beam_search.beam_size)
|
|
if p.translate {
|
|
str += " translate"
|
|
}
|
|
if p.no_context {
|
|
str += " no_context"
|
|
}
|
|
if p.single_segment {
|
|
str += " single_segment"
|
|
}
|
|
if p.print_special {
|
|
str += " print_special"
|
|
}
|
|
if p.print_progress {
|
|
str += " print_progress"
|
|
}
|
|
if p.print_realtime {
|
|
str += " print_realtime"
|
|
}
|
|
if p.print_timestamps {
|
|
str += " print_timestamps"
|
|
}
|
|
if p.token_timestamps {
|
|
str += " token_timestamps"
|
|
}
|
|
if p.carry_initial_prompt {
|
|
str += " carry_initial_prompt"
|
|
}
|
|
|
|
return str + ">"
|
|
}
|