Recording from Viewcontroller vs A Model Class

2019-09-13 12:34发布

问题:

Please refer to this post for code.

How can recording from the Viewcontroller (Main thread) and recording from a model class be different? I tried calling DispatchQueue.main.async {} but the audio data is always 44 bytes no matter how long i recorder which is not correct.

Working Implementation: ViewControllers calls SpeechRecorder.startRecording()

Desired Implementation, ViewController calls Model.tryRecording() which then results in Model calling SpeechRecorder.startRecording()

Any suggestions?

Thanks in advance -Lu

回答1:

Found Error was NOT with threads or (ViewController vs Model) but with mixing AVFoundation and AudioToolBox/CoreAudio Frameworks.

The Model was Playing an audio clip (using AVFoundation). When it finishes playing the audio, the model would call the recorder to start recording.(Using AudioToolbox and CoreAudio).

This was affecting the Recording.