AVCaptureSession用于模拟器中的音频 [英] AVCaptureSession for audio in simulator

查看:111
本文介绍了AVCaptureSession用于模拟器中的音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此问题中的方法捕获音频;使用AVCaptureSession和AVCaptureAudioDataOutput。这似乎工作正常1带来不便:它在模拟器中不起作用。 AVAudioRecorder和优秀的SpeakHere演示应用程序都可以在我的MacBook Pro上使用内置麦克风在模拟器中正常工作。

I'm trying to capture audio, using the method in this question; with AVCaptureSession and AVCaptureAudioDataOutput. This seems to work fine with 1 inconvenience: it doesn't work in the simulator. Both AVAudioRecorder, and the good old SpeakHere demo app, work fine in the simulator, using the internal microphone on my MacBook Pro.

问题在于 [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio] 在模拟器中给出 null ,因此后续代码失败并显示消息(当它尝试添加 null 作为AVCaptureSession的输入):

Problem is that [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio] gives null in the simulator, so subsequent code fails with the message (when it tries to add null as input to the AVCaptureSession):

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Can't add <AVCaptureDeviceInput: 0x9138b40 [(null)]> because the device does not support AVCaptureSessionPresetHigh.  Use -[AVCaptureDevice supportsAVCaptureSessionPreset:].'

有没有一种简单的方法可以让它在模拟器?

Is there an easy way to get this to work in the simulator?

推荐答案

AVCaptureDevice 类未在模拟器上实现(至少在撰写本文时,也许它将来会发生变化。)

The AVCaptureDevice class is not implemented on the simulator (as of this writing at least, maybe it will change in the future).

尝试例如

NSLog(@"%@", [AVCaptureDevice devices]);

这将在模拟器上产生一个空列表(但如果编译并运行,将列出所有捕获设备一个真正的iDevice)。

which will produce an empty list on the simulator (but will list all capture devices if compiled and run on a real iDevice).

这种功能无论如何都需要在真实设备上进行测试(由于硬件细节依赖性,例如支持延迟和样本格式),因此,出于测试目的,在模拟器中使用设备支持并不重要。但是将其用于演示目的确实很不错。

This kind of functionality needs to be tested on a real device anyway (due to the hardware detail dependency, such as latency and sample formats supported), so for testing purposes it is not that important to have device support in the simulator. But it would indeed be nice to have it for demo purposes.

要在模拟器上运行演示,也许你可以模拟捕获输入。如果你真的想花一些时间在它上面,也许你可以为模拟器回退 AVAudioRecorder (我从未使用过AVAudioRecorder,所以我不知道它是否确实如此在模拟器上不起作用,但从你的问题我看到它确实如此)。

To have a demo running on the simulator, maybe you can mock the capture input. If you really want to spend some time on it, maybe you can fallback on the AVAudioRecorder for the simulator (I never used AVAudioRecorder, so I can't tell if it does or does not work on the simulator, but from your question I read that it does).

这篇关于AVCaptureSession用于模拟器中的音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆