我正在开发一个同时启动多个循环的应用程序,并且应该保持它们的同步。
使用以前的简单方法来解决该问题(不使用 AVAudioEngine),我发现以编程方式按顺序启动多个音频播放器会在调用之间产生足够的延迟,从而导致结果无用;节拍明显不同步。
我可以使用 AVAudioEngine 实现这种功能吗?
目前,我正在将 AVAudioPlayerNodes 连接到混音器,并将缓冲区附加到它们并控制来自那里的输入。但我可以让它们同时启动吗?
看来节点在我调用播放之前不会开始产生声音,而在引擎启动之前这是无法完成的......
我正在实施以下教程:语音转文本
我正在使用 AVAudioEngine 录制音频并使用 SFSpeechRecognizer 来实现语音到文本。此处,教程使用开始和停止录制的按钮将语音引导为文本。
当应用程序获得许可时,我开始在 viewDidAppear 进行录制。但我找不到任何方法可以在几秒钟的沉默后停止录制。以下是我的代码:
import UIKit
import Speech
public class ViewController: UIViewController, SFSpeechRecognizerDelegate {
// MARK: Properties
private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))!
private var recognitionRequest: SFSpeechAudioBufferRecognitionRequest?
private var recognitionTask: SFSpeechRecognitionTask?
private let audioEngine = AVAudioEngine()
@IBOutlet var textView : UILabel!
@IBOutlet var recordButton : UIButton!
public override func viewDidLoad() {
super.viewDidLoad()
recordButton.isEnabled = false
}
override public func viewDidAppear(_ animated: Bool) {
speechRecognizer.delegate = self
SFSpeechRecognizer.requestAuthorization { authStatus in
/*
The callback …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有语音转文本功能,请按住按钮;视图控制器从窗口边界外动画进入视图并开始录制,释放按钮;录制停止,视图动画超出窗口范围。
突然,我通过 Firebase Crashreporting 收到一些崩溃报告,该功能在某些用户(2 个用户 / 5 个实例,所有相同的事件)上崩溃了.. 下面是我的崩溃日志事件指向我的代码.. 但是,我只是无法重现错误,我已经尝试了 1000 次,压力加载(猴子按钮捣碎它等),它不会在我的设备上崩溃..
有人可以帮我剖析底部/建议中的堆栈跟踪吗?/ 有什么问题的建议?我能做些什么来稳定?
据我了解,它围绕 installTapOnBus:0? 对下一步有什么建议吗?
_audioEngine = [[AVAudioEngine alloc] init];
_speechRecognizer = [[SFSpeechRecognizer alloc] initWithLocale:[NSLocale localeWithLocaleIdentifier:@"da"]];
[_speechRecognizer setDelegate:self];
_request = [[SFSpeechAudioBufferRecognitionRequest alloc] init];
AVAudioInputNode *node =[_audioEngine inputNode];
AVAudioFormat *recordingFormat = [node outputFormatForBus:0];
[node installTapOnBus:0 bufferSize:1024 format:recordingFormat block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
[_request appendAudioPCMBuffer:buffer];
}];
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
1 CoreFoundation __exceptionPreprocess + 1232864
2 libobjc.A.dylib objc_exception_throw + 34100
3 CoreFoundation +[NSException raise:format:arguments:] + 1232560
4 …Run Code Online (Sandbox Code Playgroud) 我有一个 motu UltraLite mk4 USB 音频接口连接到运行 MacOS 10.13.3 的 Mac。
我正在尝试播放三个立体声文件,每个文件都有自己的立体声扬声器。
为了降低复杂性,我只是试图让一个 AVAudioPlayerNode 的立体声从默认输出通道 0 和 1 以外的东西中出来。
我希望通过 AVAudioEngine + 一些低级别的 Core Audio 来实现这一点。
到目前为止,通过配置 AVAudioEngine 的输出节点,我已经成功地将音频播放到我的 USB 音频接口:
AudioUnit audioUnit = [[self.avAudioEngine outputNode] audioUnit];
OSStatus error = AudioUnitSetProperty(audioUnit,
kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Global,
0,
&deviceID,
sizeof(deviceID));
if (error) {
NSLog(@"Failed to set desired output audio device: %d", (int)
}
Run Code Online (Sandbox Code Playgroud)
我还成功地设置了一个通道映射,它允许一个播放器将立体声文件播放到我的 USB 音频接口的 4+5 通道,如 Apple 开发论坛中的 theanalogkid 所述。
通道映射的问题在于它全局应用于 AVAudioEngine 的输出,并且会影响所有 AVAudioPlayerNode。所以这不是解决方案。
因此,我没有在 AVAudioEngine 的 outputNode …
audio core-audio avfoundation avaudioengine avaudioplayernode
在我的应用程序中,我使用 AVAudioEngine 进行语音识别,但我很难理解如何正确设置 inputNode。
我使用本教程作为我的代码示例:https : //www.raywenderlich.com/155752/speech-recognition-tutorial-ios
这部分代码让我头疼:
let node = audioEngine.inputNode
let recordingFormat = node.outputFormat(forBus: 0)
node.installTap(onBus: 0, bufferSize: 1024,
format: recordingFormat) { [unowned self]
(buffer, _) in
self.request.append(buffer)
}
audioEngine.prepare()
try audioEngine.start()
Run Code Online (Sandbox Code Playgroud)
基本上,我的应用程序因以下错误而崩溃:
AVAEInternal.h:70:_AVAE_Check: required condition is false: [AVAudioIONodeImpl.mm:897:SetOutputFormat:
(format.sampleRate == hwFormat.sampleRate)]
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,如何从运行应用程序的设备获取硬件采样率,以便我可以将其设置为节点的记录格式?
另外,如果正在运行的应用程序是通过 mac 录制的或通过 Apple TV 进行屏幕共享的,我想我需要获取这些设备的硬件采样率,这样我的应用程序也不会在这些情况下崩溃?!
任何形式的帮助都非常感谢!
我有一个带有详细渲染回调的应用程序,我怀疑是否可以使用 AVAudioEngine 来实现。
无论如何,要将我的 AUGraph 渲染回调(具有多个总线)与 AVAudioEngine 一起使用吗?
有示例代码吗?
我正在开发一个带有Swift和Xcode 6的iOS应用程序.我想要做的是使用AVAudioEngine播放音频文件,直到这一切都好.但是我怎么能不停地播放它,我的意思是,当它结束播放它再次开始?
这是我的代码:
/*==================== CONFIGURATES THE AVAUDIOENGINE ===========*/
audioEngine.reset() //Resets any previous configuration on AudioEngine
let audioPlayerNode = AVAudioPlayerNode() //The node that will play the actual sound
audioEngine.attachNode(audioPlayerNode) //Attachs the node to the audioengine
audioEngine.connect(audioPlayerNode, to: audioEngine.outputNode, format: nil) //Connects the applause playback node to the sound output
audioPlayerNode.scheduleFile(applause.applauseFile, atTime: nil, completionHandler: nil)
audioEngine.startAndReturnError(nil)
audioPlayerNode.play() //Plays the sound
Run Code Online (Sandbox Code Playgroud)
在我说我应该使用AVAudioPlayer之前,我不能因为以后我将不得不使用一些效果并同时播放三个音频文件,也是反复的.
我正在播放一首歌AVAudioPlayerNode,我试图控制它的时间使用UISlider但是我无法弄明白如何使用它来寻找时间AVAUdioEngine.
该应用程序运行正常,但一旦我点击chipmunkButton应用程序崩溃并提供以下错误:
错误:AVAudioPlayerNode.mm:678: - [AVAudioPlayerNode scheduleFile:atTime:completionHandler:]:必需条件为false:file!= nil 2015-05-10 17:24:25.269 Pitch Perfect [50278:1897012]***终止app由于未被捕获的异常'com.apple.coreaudio.avfaudio',原因:'必要条件为false:file!= nil'
import UIKit
import AVFoundation
class PlaySoundsViewController: UIViewController {
var audioRecording = AVAudioPlayer()
var receivedAudio:RecordedAudio!
var audioEngine:AVAudioEngine!
var audioFile:AVAudioFile!
func setupAudioPlayerWithFile(file:NSString, type:NSString) -> AVAudioPlayer {
//1
var path = NSBundle.mainBundle().pathForResource(file as String, ofType: type as String)
var url = NSURL.fileURLWithPath(path!)
//2
var error: NSError?
//3
var audioPlayer:AVAudioPlayer?
audioPlayer = AVAudioPlayer(contentsOfURL: url, error: &error)
//4
return audioPlayer!
}
override func viewDidLoad() {
super.viewDidLoad()
audioRecording = AVAudioPlayer(contentsOfURL: receivedAudio.filePathUrl, error: nil)
audioRecording.enableRate …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用 AVAudioEngine 和 AVAudioPlayerNode 处理音频播放,我想实现远程控制。背景音频已配置并正常工作。
控制中心控制工作,但当我从应用程序内部播放/暂停音乐时,播放/暂停按钮不会更新。我正在真实设备上进行测试。
这是我的 AVAudioSession 设置代码:
func setupAudioSession() {
UIApplication.shared.beginReceivingRemoteControlEvents()
do {
try AVAudioSession.sharedInstance().setActive(true)
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch let sessionError {
print("Failed to activate session:", sessionError)
}
}
Run Code Online (Sandbox Code Playgroud)
MPRemoteCommandCenter 设置:
func setupRemoteControl() {
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.playCommand.isEnabled = true
commandCenter.playCommand.addTarget { (_) -> MPRemoteCommandHandlerStatus in
self.audioPlayerNode.play()
return .success
}
commandCenter.pauseCommand.isEnabled = true
commandCenter.pauseCommand.addTarget { (_) -> MPRemoteCommandHandlerStatus in
self.audioPlayerNode.pause()
return .success
}
}
Run Code Online (Sandbox Code Playgroud)
锁屏控制 - 从未出现过。
ios avaudiosession swift avaudioengine mpremotecommandcenter
avaudioengine ×10
ios ×8
swift ×4
audio ×3
core-audio ×3
augraph ×1
avfoundation ×1
crash ×1
ios13 ×1
null ×1
objective-c ×1
swift3 ×1