ggerganov / whisper.spm

whisper.cpp package for the Swift Package Manager
MIT License
168 stars 27 forks source link

Enable CoreML, with fallback #13

Closed venkr closed 1 year ago

venkr commented 1 year ago

This PR:

As a result, this changes behavior of the .spm package such that if you have the CoreML model present, it'll use CoreML, otherwise the functionality will remain unchanged.

vade commented 1 year ago

Hey this is interesting. Few quick questions:

vizaiapp commented 1 year ago

Hi folks, @venkr thank you for this change! I just tried to update and test this out, though I'm running into an issue. When I try to load whisper_init_from_file, the function breaks out of whatever context I call it in whenever a CoreML model is available.

Using the example in test-swift in the SPM package:

import Foundation
import whisper

let ctx = whisper_init_from_file("models/for-tests-ggml-base.en.bin")

var params = whisper_full_default_params(WHISPER_SAMPLING_GREEDY)

params.print_realtime   = true
params.print_progress   = false
params.print_timestamps = true
params.print_special    = false
params.translate        = false
//params.language         = "en";
params.n_threads        = 4
params.offset_ms        = 0

let n_samples = Int32(WHISPER_SAMPLE_RATE)
let pcmf32 = [Float](repeating: 0, count: Int(n_samples))

let ret = whisper_full(ctx, params, pcmf32, n_samples)
assert(ret == 0, "Failed to run the model")

let n_segments = whisper_full_n_segments(ctx)

for i in 0..<n_segments {
    let text_cur = whisper_full_get_segment_text(ctx, i)
    print(text_cur as Any)
}

whisper_print_timings(ctx)
whisper_free(ctx)

It doesn't execute past the initial whisper_init_from_file call. Is this the expected behavior? I'm able to run whisper.cpp fine with CoreML enabled.