I am trying to customise language model but face the error when exporting.
I created a project and copied example code from Apple:
import Speech
class Data {
func export() async throws {
let data = SFCustomLanguageModelData(
locale: Locale(identifier: "en_US"),
identifier: "personal.TestCustomModel",
version: "1.0"
) {
SFCustomLanguageModelData.PhraseCount(
phrase: "Play the Albin counter gambit",
count: 10
)
SFCustomLanguageModelData.PhraseCountsFromTemplates(
classes: [
"piece" : ["pawn", "rook", "knight", "bishop", "queen", "king"],
"royal" : ["queen", "king"],
"rank" : Array(1...8).map({String($0)})
]
) {
SFCustomLanguageModelData.TemplatePhraseCountGenerator.Template(
"‹piece> to <royal> <piece> <rank>",
count: 10000
)
}
}
try await data.export(to: URL(filePath: "/var/tmp/TestCustomModel.bin"))
}
}
I am running app on device and got this error:
Unable to open archive: Failed to open '/var/tmp/TestCustomModel.bin' Failed to write header for asset_info.json to archive: INTERNAL ERROR: Function 'archive_write_header' invoked with archive structure in state 'new', should be in state 'header/data' Failed to write metadata
Any ideas what is the issue?
So I learned about /var/tmp and that it's path on macOS. Fixed the issue by creating command line tool (project in Xcode) and exported bin file on my macOS and imported it in my speech recognition project. Here is the sample code I found from Apple doing this:
https://developer.apple.com/documentation/speech/recognizing-speech-in-live-audio