How to get the Audio data BlueSTSDKFeatureAudioADPCM.getLinearPCMAudio(sample) in Swift
// BlueSTSDKFeatureDelegate
func didUpdate(_ feature: BlueSTSDKFeature, sample: BlueSTSDKFeatureSample) {
guard let node = self.node else {
return
}
let features = node.getFeatures()
guard let ind = features.firstIndex(of: feature) else {
return
}
// Audio Feature
if feature.isKind(of: BlueSTSDKFeatureAudioADPCM.self), let audio = feature as? BlueSTSDKFeatureAudioADPCM {
let fileURL = getDocumentsDirectory().appendingPathComponent("\(audio.name).\(audioFileFormat)")
if let data = BlueSTSDKFeatureAudioADPCM.getLinearPCMAudio(sample) {
if records["\(ind)"] != nil {
var record = records["\(ind)"]
objc_sync_enter(record as Any)
record?.append(data)
objc_sync_exit(record as Any)
records["\(ind)"] = record!
}
else {
records["\(ind)"] = Data()
}
}
}
}
// So I was able to save the "record".
do { try record.write(to: fileURL, options: .atomic) } catch let error { // failed to write file – bad permissions, bad filename, missing permissions, or more likely it can't be converted to the encoding print("Record Write: (error.localizedDescription)") }
// But I was not able to play in AVAudioPlayer.
Hi,
did you see this code: https://github.com/STMicroelectronics/STBlueMS_iOS/blob/master/W2STApp/MainApp/Demo/Audio/Util/W2STAudioPlaybackController.swift
it is used here: https://github.com/STMicroelectronics/STBlueMS_iOS/blob/master/W2STApp/MainApp/Demo/Audio/BlueVoice/BlueMSBlueVoiceViewController.swift
Hi, thanks for the info! let me try again with above code.
Hi @GiovanniVisentini ,
I have integrated the latest BlueSTSDK_iOS. But I am getting the following error in Xcode 11.1.

Please let me know how to fix it.
Looking forward to hearing from you as soon as possible.
Thank you
Hi,
I think that the problem is that you are targeting the emulator. with this version we add the opus decoder that is done using a serrated library.. the library is compiled only for arm, so the library doesn't build for the x86 enviroment.
Best Regards Giovanni
Hi @GiovanniVisentini ,
Thanks for the info!
Yes Right. I was targeting the emulator.
Let me try again.
Thank you!
Hi @GiovanniVisentini ,
Your answer was really helpful for me.
By the way, I am just wondering how to detect once the data transfer is stopped.
I just wanted to know how to check if the data transfer is stopped or started.
Is there any API or something else?
Looking forward to hearing from you.
Thank you!
you can check if the 2 characteristics/features have the notification enabled, in that case the fw is streaming audio to the mobile.
if your fw stops autonomously to stream, from the feature.lastSample you can see the when the last package arrive an have a threshold on that.
Best Regards Giovanni