gpt4 book ai didi

IOs App 在模拟器上运行但在设备上崩溃(主要使用 AVFoundation)

转载 作者:行者123 更新时间:2023-11-28 07:00:46 25 4
gpt4 key购买 nike

我正在从事一个学习项目,该项目与 AVFoundation 配合使用,处理音频的录制和操作播放。该应用程序在模拟器上运行良好,但在设备上运行时崩溃。

请注意,它不会立即崩溃。只有当我尝试操纵要播放的声音的音高时,它才会崩溃。

此外,如果我只是尝试播放录制的音频,它不会工作,但也不会崩溃。

如果你想要/可以帮助我,整个项目都在 github 上,地址为 https://github.com/pablomarques/Voice-FX

[项目在 XCode 6.4 上运行,设备是运行 8.4 的 iPhone 6]

提前致谢。

编辑:在此处添加一些代码以节省人们必须通过存储库的麻烦(如果您想复制它,将保留存储库)

它在模拟器上工作得很好,它让我很投入。:(

import UIKit
import AVFoundation

class PlaySoundsViewController: UIViewController {

var audioPlayer:AVAudioPlayer!
var receivedAudio:AudioRecording!

var audioEngine:AVAudioEngine!
var audioFile:AVAudioFile!

override func viewDidLoad() {
super.viewDidLoad()
if let path = receivedAudio.filePathURL {
audioPlayer = AVAudioPlayer(contentsOfURL: path, error: nil)
audioPlayer.enableRate = true

audioEngine = AVAudioEngine()
audioFile = AVAudioFile(forReading: path, error: nil)

println(path)
}
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

@IBAction func playSlowSound(sender: AnyObject) {

playSound(0.35)
println("clicking works")

}

@IBAction func playFastSound(sender: AnyObject) {

playSound(3.0)

}

@IBAction func chipMunkSound(sender: AnyObject) {

playAudioWithVariablePitch(1000.0)

}

@IBAction func vaderSound(sender: AnyObject) {

playAudioWithVariablePitch(-1000.0)

}

@IBAction func stopSounds(sender: AnyObject) {

audioPlayer.stop()
audioPlayer.currentTime = 0

}

func playSound(soundSpeed: Float) {
audioPlayer.stop()
audioPlayer.currentTime = 0
audioPlayer.rate = soundSpeed
audioPlayer.prepareToPlay()
audioPlayer.play()
println("playing")
}

func playAudioWithVariablePitch(pitch: Float){

audioPlayer.stop()
audioEngine.stop()
audioEngine.reset()

var audioPlayerNode = AVAudioPlayerNode()
audioEngine.attachNode(audioPlayerNode)

var changePitchEffect = AVAudioUnitTimePitch()
changePitchEffect.pitch = pitch
audioEngine.attachNode(changePitchEffect)

audioEngine.connect(audioPlayerNode, to: changePitchEffect, format: nil)
audioEngine.connect(changePitchEffect, to: audioEngine.outputNode, format: nil)

audioPlayerNode.scheduleFile(audioFile, atTime: nil, completionHandler: nil)
audioEngine.startAndReturnError(nil)

audioPlayerNode.play()

}

它在我的 AppDelegate.swift 文件中显示绿色错误断点,这很奇怪。

class AppDelegate: UIResponder, UIApplicationDelegate {

这是我收到的错误信息:

2015-08-20 05:32:55.506 Voice FX[2265:548015] 05:32:55.506 错误:[0x19bb13310] >auurioc> 806:失败:-10851(启用 2,输出 < 2 channel ,0 Hz , Float32, non-inter> inf< 2 ch, 0 Hz, Float32, non-inter>)2015-08-20 05:32:55.509 Voice FX[2265:548015] 05:32:55.508 错误:[0x19bb13310] >aurioc> 806:失败:-10851(启用 2,outf< 2 ch,44100 Hz,Float32, non-inter> inf< 2 ch, 0 Hz, Float32, non-inter>)2015-08-20 05:32:55.512 语音 FX[2265:548015] 05:32:55.512 错误:[0x19bb13310] >aurioc> 806:失败:-10851(启用 2,outf< 2 ch,44100 Hz,Float32, non-inter> inf< 2 ch, 0 Hz, Float32, non-inter>)2015-08-20 05:32:55.513 语音 FX[2265:548015] 05:32:55.512 错误:[0x19bb13310] AVAudioEngineGraph.mm:2417: PerformCommand: 错误 -108512015-08-20 05:32:55.517 Voice FX[2265:548015] * 由于未捕获的异常“com.apple.coreaudio.avfaudio”而终止应用程序,原因:“错误 -10851”* 首先抛出调用栈:(0x18563022c 0x1972fc0e4 0x1856300ec 0x183f6e008 0x183fa07ac 0x183fa8a54 0x183fa99dc 0x183f9d9b4 0x183f9da94 0x183f9da94 0x183f9e9f4 0x183fa2140 0x183f9292c 0x183f91f98 0x183f91f28 0x10006c03c 0x10006b20c 0x10006b264 0x18a0e11ec 0x18a0ca2c8 0x18a0e0b88 0x18a0e0814 0x18a0d9d50 0x18a0acf74 0x18a34e124 0x18a0ab488 0x1855e7f8c 0x1855e7230 0x1855e52e0 0x185510f74 0x18ef6b6fc 0x18a112d94 0x10006f3f8 0x1979a6a08)libc++abi.dylib:以 NSException 类型的未捕获异常终止(lldb) BT

最佳答案

我刚遇到这个问题,当时我正在使用旧的 AVAudioSession(用于录制声音文件)功能和新的 AVAudioEngine(用于应用语音音高转换)。

错误 -10851 是 kAudioUnitErr_InvalidPropertyValue,如此处所示 https://developer.apple.com/library/ios/documentation/AudioUnit/Reference/AUComponentServicesReference/

我现在的 hacky 修复只是在我即将使用 AudioEngine 时停止我的 session

self.avSession?.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)
self.avSession?.setActive(false, error: nil)

我仍然得到以下错误

AVAudioSession.mm:646: -[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.

但语音音高部分正常工作,我的应用程序不再崩溃。所以我猜这只是整理我如何使用这两个 AVAudio 工具的问题。

关于IOs App 在模拟器上运行但在设备上崩溃(主要使用 AVFoundation),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32107257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com