Skip to content

Commit

Permalink
use resource_bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
albho committed Dec 2, 2024
1 parent b53fd6e commit 6d84bbd
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 12 deletions.
6 changes: 5 additions & 1 deletion binding/ios/Octopus-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/PvOctopus.xcframework'
s.resources = 'lib/common/param/octopus_params.pv'
s.resource_bundles = {
'OctopusResources' => [
'lib/common/param/octopus_params.pv'
]
}
s.source_files = 'binding/ios/*.{swift}'
s.exclude_files = 'binding/ios/OctopusTestApp/**'
end
33 changes: 28 additions & 5 deletions binding/ios/Octopus.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021-2023 Picovoice Inc.
// Copyright 2021-2024 Picovoice Inc.
// You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
// file accompanying this source.
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
Expand All @@ -25,6 +25,31 @@ public struct OctopusMatch {
/// iOS binding for Octopus Speech-to-Index engine. It transforms audio into searchable metadata.
public class Octopus {

#if SWIFT_PACKAGE

static let resourceBundle = Bundle.module

#else

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

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

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

return resourceBundle
}()

#endif

/// Required audio sample rate for PCM data
public static let pcmDataSampleRate = Int(pv_sample_rate())

Expand All @@ -50,11 +75,9 @@ public class Octopus {
var modelPathArg = modelPath

if modelPath == nil {
let bundle = Bundle(for: type(of: self))

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
C757D8E828A1D08B00F391C8 /* octopus_params_it.pv in Resources */ = {isa = PBXBuildFile; fileRef = C757D8E128A1D08B00F391C8 /* octopus_params_it.pv */; };
C757D8E928A1D08B00F391C8 /* octopus_params_de.pv in Resources */ = {isa = PBXBuildFile; fileRef = C757D8E228A1D08B00F391C8 /* octopus_params_de.pv */; };
C757D8EA28A1D08B00F391C8 /* octopus_params_fr.pv in Resources */ = {isa = PBXBuildFile; fileRef = C757D8E328A1D08B00F391C8 /* octopus_params_fr.pv */; };
E10DF5122CFE60E5008D4AA0 /* Octopus in Frameworks */ = {isa = PBXBuildFile; productRef = E10DF5112CFE60E5008D4AA0 /* Octopus */; };
E10DF5142CFE60E9008D4AA0 /* Octopus in Frameworks */ = {isa = PBXBuildFile; productRef = E10DF5132CFE60E9008D4AA0 /* Octopus */; };
E10DF5162CFE60EC008D4AA0 /* Octopus in Frameworks */ = {isa = PBXBuildFile; productRef = E10DF5152CFE60EC008D4AA0 /* Octopus */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -91,13 +94,15 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E10DF5122CFE60E5008D4AA0 /* Octopus in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
1E0064FB27CFEC95006FF6E9 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E10DF5142CFE60E9008D4AA0 /* Octopus in Frameworks */,
36696536961DE78B3E1C06FA /* (null) in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -106,6 +111,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E10DF5162CFE60EC008D4AA0 /* Octopus in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -118,7 +124,7 @@
1E5B7B022800D9A500F8BDDB /* PerformanceTest */,
1E0064C627CEEA65006FF6E9 /* OctopusAppTest */,
1E0064E727CEEA66006FF6E9 /* OctopusAppTestUITests */,
E15A378F2CF7E5DE00A96F85 /* Frameworks */,
E10DF5102CFE60E5008D4AA0 /* Frameworks */,
1E0064C527CEEA65006FF6E9 /* Products */,
);
sourceTree = "<group>";
Expand Down Expand Up @@ -182,7 +188,7 @@
path = PerformanceTest;
sourceTree = "<group>";
};
E15A378F2CF7E5DE00A96F85 /* Frameworks */ = {
E10DF5102CFE60E5008D4AA0 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
Expand Down Expand Up @@ -278,7 +284,7 @@
);
mainGroup = 1E0064BB27CEEA65006FF6E9;
packageReferences = (
E15A37882CF7E12E00A96F85 /* XCLocalSwiftPackageReference "../../../../octopus" */,
E10DF50F2CFE60DE008D4AA0 /* XCLocalSwiftPackageReference "../../../../octopus" */,
);
productRefGroup = 1E0064C527CEEA65006FF6E9 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -708,11 +714,29 @@
/* End XCConfigurationList section */

/* Begin XCLocalSwiftPackageReference section */
E15A37882CF7E12E00A96F85 /* XCLocalSwiftPackageReference "../../../../octopus" */ = {
E10DF50F2CFE60DE008D4AA0 /* XCLocalSwiftPackageReference "../../../../octopus" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = ../../../../octopus;
};
/* End XCLocalSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
E10DF5112CFE60E5008D4AA0 /* Octopus */ = {
isa = XCSwiftPackageProductDependency;
package = E10DF50F2CFE60DE008D4AA0 /* XCLocalSwiftPackageReference "../../../../octopus" */;
productName = Octopus;
};
E10DF5132CFE60E9008D4AA0 /* Octopus */ = {
isa = XCSwiftPackageProductDependency;
package = E10DF50F2CFE60DE008D4AA0 /* XCLocalSwiftPackageReference "../../../../octopus" */;
productName = Octopus;
};
E10DF5152CFE60EC008D4AA0 /* Octopus */ = {
isa = XCSwiftPackageProductDependency;
package = E10DF50F2CFE60DE008D4AA0 /* XCLocalSwiftPackageReference "../../../../octopus" */;
productName = Octopus;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 1E0064BC27CEEA65006FF6E9 /* Project object */;
}
10 changes: 8 additions & 2 deletions demo/ios/OctopusDemo/OctopusDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
02447A8F26D94F75004A6CE9 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02447A8E26D94F75004A6CE9 /* ContentView.swift */; };
02447A9126D94F7C004A6CE9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 02447A9026D94F7C004A6CE9 /* Assets.xcassets */; };
C76A41602703B17000DB57D6 /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C76A415F2703B17000DB57D6 /* ViewModel.swift */; };
E10DF5192CFE6104008D4AA0 /* Octopus in Frameworks */ = {isa = PBXBuildFile; productRef = E10DF5182CFE6104008D4AA0 /* Octopus */; };
E15A378B2CF7E15700A96F85 /* Octopus in Frameworks */ = {isa = PBXBuildFile; productRef = E15A378A2CF7E15700A96F85 /* Octopus */; };
E15A378E2CF7E1C000A96F85 /* Octopus in Frameworks */ = {isa = PBXBuildFile; productRef = E15A378D2CF7E1C000A96F85 /* Octopus */; };
/* End PBXBuildFile section */
Expand All @@ -29,6 +30,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E10DF5192CFE6104008D4AA0 /* Octopus in Frameworks */,
E15A378E2CF7E1C000A96F85 /* Octopus in Frameworks */,
E15A378B2CF7E15700A96F85 /* Octopus in Frameworks */,
);
Expand Down Expand Up @@ -109,7 +111,7 @@
);
mainGroup = 02447A8026D94F74004A6CE9;
packageReferences = (
E15A378C2CF7E1C000A96F85 /* XCLocalSwiftPackageReference "../../../../octopus" */,
E10DF5172CFE6104008D4AA0 /* XCLocalSwiftPackageReference "../../../../octopus" */,
);
productRefGroup = 02447A8A26D94F75004A6CE9 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -329,13 +331,17 @@
/* End XCConfigurationList section */

/* Begin XCLocalSwiftPackageReference section */
E15A378C2CF7E1C000A96F85 /* XCLocalSwiftPackageReference "../../../../octopus" */ = {
E10DF5172CFE6104008D4AA0 /* XCLocalSwiftPackageReference "../../../../octopus" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = ../../../../octopus;
};
/* End XCLocalSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
E10DF5182CFE6104008D4AA0 /* Octopus */ = {
isa = XCSwiftPackageProductDependency;
productName = Octopus;
};
E15A378A2CF7E15700A96F85 /* Octopus */ = {
isa = XCSwiftPackageProductDependency;
productName = Octopus;
Expand Down

0 comments on commit 6d84bbd

Please sign in to comment.