当我尝试播放不同音高的音频时,我收到此消息:
我搜索了那个没有成功的错误。如果我设置断点,它会在此处停止:
我测试打印所有对象以查看是否有任何东西,但我没有找到任何东西。最神奇的事情是,只发生在我的iphone6 +中,在我测试过的其他手机中没有破坏。然后搜索我调查的项目添加此声音效果,这是: https://github.com/atikur/Pitch-Perfect 如果你运行它,它会起作用,直到你改变......
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, error: &error)
要:
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: &error)
然后繁荣(仅在真实设备上连接到XCODE,它在模拟器中工作):
2015-03-21 11:56:13.311 Pitch Perfect [1237:607678] 11:56:13.311 ERROR:[0x10320c000] AVAudioFile.mm:496: - [AVAudioFile readIntoBuffer:frameCount:error:]:error -50 2015-03-21 11:56:13.313 Pitch Perfect [1237:607678] *由于未捕获的异常终止应用程序' com.apple.coreaudio.avfaudio',原因:'错误 - 50' * 第一次抛出调用堆栈: (0x18687a530 0x1978040e4 0x18687a3f0 0x1851ea6c0 0x185232d38 0x1852130f8 0x185212ccc 0x100584fd4 0x100584f94 0x10058fdb8 0x1005882c4 0x1005925d4 0x100592208 0x198037dc8 0x198037d24 0x198034ef8) libc ++ abi.dylib:以NSException类型的未捕获异常终止
真正非常奇怪的是这个截图,由于某些原因打印audioEngine后,audioEngine.outputNode变为零?
答案 0 :(得分:0)
我遇到了同样的错误......我创建了一个" sound.swift"我的视图控制器将实例化的类......我决定简化一切并专注于使声音工作。所以我将以下代码放在视图控制器中,它可以工作:
//获取录制的文件
var pitchPlayer = AVAudioPlayerNode()
var timePitch = AVAudioUnitTimePitch()
let dirPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)[0] as! String
var pathArray = [dirPath, String("son.wav")]
filePath = NSURL.fileURLWithPathComponents(pathArray)
audioFile = AVAudioFile(forReading: filePath.filePathURL, error: nil)
audioEngine = AVAudioEngine()
audioEngine.attachNode(pitchPlayer)
audioEngine.attachNode(timePitch)
//Create a session
var session=AVAudioSession.sharedInstance()
session.setCategory(AVAudioSessionCategoryPlayAndRecord,error:nil)
//output audio
session.overrideOutputAudioPort(AVAudioSessionPortOverride.Speaker, error: nil)
audioEngine.connect(pitchPlayer, to: timePitch, format: audioFile.processingFormat)
audioEngine.connect(timePitch, to: audioEngine.outputNode, format: audioFile.processingFormat)
pitchPlayer.scheduleFile(audioFile, atTime: nil, completionHandler: nil)
audioEngine.startAndReturnError(&audioError)
pitchPlayer.play()