Not exchanging Audio ptt-iOS.
Closed this issue · 3 comments
Hello,
I have run your ptt-ios project.And as you suggested convert CMSampleBuffer into AudioBuffer (or byte array) and send it as json-string to javascript code. I have code as below.
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
print("captured audio!")
//TODO: convert CMSampleBuffer into AudioBuffer (or byte array) and send it as json-string to javascript code
var audioBufferList = AudioBufferList()
var data = Data()
var blockBuffer : CMBlockBuffer?
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, nil, &audioBufferList, MemoryLayout<AudioBufferList>.size, nil, nil, 0, &blockBuffer)
let buffers = UnsafeBufferPointer<AudioBuffer>(start: &audioBufferList.mBuffers, count: Int(audioBufferList.mNumberBuffers))
for audioBuffer in buffers {
let frame = audioBuffer.mData?.assumingMemoryBound(to: UInt8.self)
data.append(frame!, count: Int(audioBuffer.mDataByteSize))
}
let responseString = String(decoding: data, as: UTF8.self)
let jsonArrayString = responseString
let script = callback+"('"+jsonArrayString+"');"
print(script)
DispatchQueue.main.async {
self.webView.evaluateJavaScript(script){ (result, error) in
guard error == nil else {
print(error)
print("there was an error")
return
}
print("yes script is working")
}
}
}
but now i am getting
(Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=47, WKJavaScriptExceptionMessage=SyntaxError: JSON Parse error: Unrecognized token 'tExceptionSourceURL=file:///var/containers/Bundle/Application/60121993-27C1-4FFC-8118-29B2A642E431/ptt.app/api.js, NSLocalizedDescription=A JavaScript exception occurred})
at line 47 in api.js file which is
var byteArray = JSON.parse(stringArray);
I am not able to understand what i am doing wrong please help.
Hi,
thanks for contributing to the project. Unfortunately I discontinued the iOS implementation, because I do not have an iPhone to test it with.
To me it seems like the exception is caused by the data
, which you pass to the javascript callback, hence it cannot be parsed. Maybe the conversion to string is not correct.
Thank You for reply. Hello Sir is there Native iOS sample app available for same as it is available in android. Please help.
Unfortunately I cannot you help you, this is the only iOS app that I started.
Good luck with the project.