ggerganov / whisper.spm

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

Can't get models to load in MacOS project #8

Closed brytonsf closed 1 year ago

brytonsf commented 1 year ago

Hello.

I seem to be unable to get past this stage: let ctx = whisper_init_from_file("models/for-tests-ggml-base.en.bin")

I'm able to run

make build
.build/debug/test-swift

in terminal and have everything work properly. But when I simply run a MacOS app in Xcode using Whisper as a package dependency, the model fails to load: whisper_init_from_file_no_state: failed to open 'models/for-tests-ggml-base.en.bin'

I've tried using absolute paths on my filesystem and using a different model binary, but I've got the same results each time.

Does anyone have any thoughts/advice? What can I learn to figure this out?

brytonsf commented 1 year ago

Closed, I'm going to try https://github.com/exPHAT/SwiftWhisper or use a python wrapper if that fails.

mountain-hiker commented 1 year ago

Here are the steps:

  1. After installing the swift package navigate to the models folder in your Xcode project (whisper.spm/Sources/models)
  2. Right click -> show in Finder
  3. With the finder open drag that models folder to your own swift project ("Copy Items if needed" selected)
  4. Copy the main.swift from Sources/test-swift
  5. Now replace the let ctx = whisper_init_from_file("models/for-tests-ggml-base.en.bin") line with the following two lines:
let fileURL = Bundle.main.url(forResource: "for-tests-ggml-base.en", withExtension: "bin")
let ctx = whisper_init_from_file(fileURL?.path(percentEncoded: true))

Then hit run!