1

I am working on a push to talk functionality where sender can send an audio in form of bytes array to server and receiver can listen it at realtime through socket connection.

when i try to play video at receiver end using AVAudioEngine, it's not working.

    let buffer = dataToPCMBuffer(format: format16KHzMono!, data: data)
    let player = AVAudioPlayerNode()
    self.audioEngine?.attach(audioPlayerNode)   
    let mixer = self.audioEngine?.mainMixerNode

    self.audioEngine?.connect(player, to: mixer!, format: AVAudioFormat.init(commonFormat: AVAudioCommonFormat.pcmFormatInt16, sampleRate: 16000, channels: 1, interleaved: true) )

    self.playerQueue.async {
        self.audioPlayerNode.scheduleBuffer(buffer!) {
            print("stopping")
            if self.audioEngine!.isRunning  {
                self.audioPlayerNode.play()
            }else {
              try? self.audioEngine?.start()
        }
    }

And, i am facing crash at below given line.

 self.audioEngine?.connect(player, to: mixer!, format: AVAudioFormat.init(commonFormat: AVAudioCommonFormat.pcmFormatInt16, sampleRate: 16000, channels: 1, interleaved: true) )

Any help will be appreciated.

Aman.Samghani
  • 2,151
  • 3
  • 12
  • 27
  • Can you post the crash? – Chris Oct 05 '18 at 20:07
  • :124:_AVAE_CheckSuccessAndNoNSError: [AUInterface.mm:526:SetFormat: ([[busArray objectAtIndexedSubscript:(NSUInteger)element] setFormat:format error:&nsErr])] returned false, error Error Domain=NSOSStatusErrorDomain Code=-10868 "(null)" – Aman.Samghani Oct 06 '18 at 18:29
  • 2
    I am facing a similar issue; did you resolve it in the end? – Adamski Jan 15 '19 at 14:47

1 Answers1

0

I think it’s the format in your connection. Try using nil instead. There are some magic numbers needed for sample rates, maybe 16000 is not one of them.

dave234
  • 4,793
  • 1
  • 14
  • 29