Skip to content

Commit

Permalink
refactor resources bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
albho committed Dec 2, 2024
1 parent 0b5b93b commit 9d5890c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
6 changes: 5 additions & 1 deletion binding/ios/Falcon-iOS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '13.0'
s.swift_version = '5.0'
s.vendored_frameworks = 'lib/ios/PvFalcon.xcframework'
s.resources = 'lib/common/falcon_params.pv'
s.resource_bundles = {
'FalconResources' => [
'lib/common/falcon_params.pv'
]
}
s.source_files = 'binding/ios/*.{swift}'
s.exclude_files = 'binding/ios/FalconTestApp/**'
end
49 changes: 29 additions & 20 deletions binding/ios/Falcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ public struct FalconSegment {

/// iOS binding for Falcon speaker diarization engine. Provides a Swift interface to the Falcon library.
public class Falcon {

#if SWIFT_PACKAGE

static let resourceBundle = Bundle.module

#else

static let resourceBundle: Bundle = {
let myBundle = Bundle(for: Falcon.self)

guard let resourceBundleURL = myBundle.url(
forResource: "FalconResources", withExtension: "bundle")
else {
fatalError("FalconResources.bundle not found")
}

guard let resourceBundle = Bundle(url: resourceBundleURL)
else {
fatalError("Could not open FalconResources.bundle")
}

return resourceBundle
}()

#endif

private static let supportedAudioTypes: Set = [
"3gp",
"flac",
Expand Down Expand Up @@ -75,28 +101,11 @@ public class Falcon {
}

var modelPathArg = modelPath

if modelPath == nil {

#if SWIFT_PACKAGE

if let bundleURL = Bundle.module.url(forResource: "falcon_params", withExtension: "pv") {
modelPathArg = bundleURL.path
} else {
throw FalconIOError("Could not retrieve default model from the package bundle")
}

#else

let bundle = Bundle(for: type(of: self))

modelPathArg = bundle.path(forResource: "falcon_params", ofType: "pv")
if modelPathArg == nil {
modelPathArg = Falcon.resourceBundle.path(forResource: "falcon_params", ofType: "pv")
if modelPathArg == nil {
throw FalconIOError("Could not retrieve default model from app bundle")
throw FalconIOError("Could not find default model file in app bundle.")
}

#endif

}

if !FileManager().fileExists(atPath: modelPathArg!) {
Expand Down

0 comments on commit 9d5890c

Please sign in to comment.