gpt4 book ai didi

iphone - AVAudioEngine 音量低

转载 作者:行者123 更新时间:2023-12-03 20:27:22 33 4
gpt4 key购买 nike

我正在用 Swift 编写一个 iOS 应用程序,该应用程序正在录制用户的声音,然后可以使用一些语音效果进行播放,但问题是使用内置 iPhone 麦克风时播放非常安静。带耳机就没问题。

录制代码:

let recordingName = "my_audio.m4a"
let pathArray = [dirPath, recordingName]
let filePath = NSURL.fileURLWithPathComponents(pathArray)
print(filePath)

let recordSettings: [String: AnyObject] = [
AVFormatIDKey: Int(kAudioFormatAppleLossless),
AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue,
AVEncoderBitRateKey : 320000,
AVNumberOfChannelsKey: 2,
AVSampleRateKey : 44100.0
]

let session = AVAudioSession.sharedInstance()
try! session.setCategory(AVAudioSessionCategoryPlayAndRecord)
try! audioRecorder = AVAudioRecorder(URL: filePath!, settings: recordSettings)

audioRecorder.meteringEnabled = true
audioRecorder.updateMeters()
audioRecorder.delegate = self
audioRecorder.prepareToRecord()
audioRecorder.record()

播放代码:

playerNode.stop()
playerNode.volume = 1.0
audioEngine.stop()
audioEngine.reset()

audioEngine.attachNode(playerNode)
audioEngine.attachNode(audioUnitTime)
audioEngine.connect(playerNode, to: audioUnitTime, format: receivedAudio.processingFormat)
audioEngine.connect(audioUnitTime, to: audioEngine.outputNode, format: receivedAudio.processingFormat)

playerNode.scheduleFile(receivedAudio, atTime: nil, completionHandler: nil)
try! audioEngine.start()
playerNode.play()

对我来说唯一的解决方案是原始的苹果录音应用程序会执行相同的操作,但前提是右上角的扬声器图标被禁用。虽然我无法找出那个扬声器图标的作用。

最佳答案

好吧,终于找到了。问题出在 AVAudioSession 上:

let session = AVAudioSession.sharedInstance()
try! session.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions:AVAudioSessionCategoryOptions.DefaultToSpeaker)

关于iphone - AVAudioEngine 音量低,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36115497/

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