简体   繁体   English

iPhone SDK audioSession问题

[英]iPhone SDK audioSession question

In my app i record and play audio at the same time. 在我的应用程序中,我同时录制和播放音频。 The app is almost finished. 该应用程序几乎完成。 But there is one thing, that annoying me. 但是有一件事让我烦恼。 When audio session is set to PlayAndRecord, sounds become quiet in comparison with the same sounds with the SoloAmbient category. 当音频会话设置为PlayAndRecord时,与SoloAmbient类别的相同声音相比,声音变得安静。 Is there any way to make sound louder using PlayAndRecord? 有没有什么方法可以使用PlayAndRecord让声音更响亮?

when you use the session for play and record, the playback comes out of the speaker used for the phone, otherwise it comes out the speaker located at the bottom of the phone. 当您使用会话进行播放和录制时,播放来自用于电话的扬声器,否则它会从位于电话底部的扬声器发出。 this is to prevent feedback. 这是为了防止反馈。 you can override this like so (but watch out for feedback, not an issue if you aren't doing both at once) 你可以像这样覆盖它(但要小心反馈,如果你不同时做两件事,那就不要问题)

    //when the category is play and record the playback comes out of the speaker used for phone conversation to avoid feedback
    //change this to the normal or default speaker

    UInt32 doChangeDefaultRoute = 1;        
    AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute);

this code works on 3.1.2, earlier sdk's you have to do differently. 这段代码适用于3.1.2,早期的sdk你必须采用不同的方式。

    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; 
    status = AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);

you have to be careful with this method, it will override even if you have headphones plugged in, you have to monitor interruptions and change the routes accordingly. 您必须小心这种方法,即使您插入了耳机,它也会覆盖,您必须监控中断并相应地更改路线。 much better now using 3.1.2 现在使用3.1.2好多了

Ask the user to plug in headphones? 要求用户插入耳机?

The headphone + mic combination doesn't suffer from this problem. 耳机+麦克风组合不会遇到这个问题。

I don't know if it's a bug, a consequence of the audio hardware, or if the quiet playback is just an intentional and hamfisted way of getting cleaner recordings. 我不知道这是一个错误,是音频硬件的结果,还是安静的播放只是一种有意和无聊的方式来获得更清晰的录音。

UPDATE UPDATE

I found out that setting the PlayAndRecord session changes your audio route to the receiver. 我发现设置PlayAndRecord会话会将您的音频路径更改为接收器。
Apparently the use case is for telephony applications where the user holds the device up to his ear. 显然,该用例适用于电话应用程序,用户可以将设备放在他的耳边。

If that doesn't violate the Principle of Least Surprise, I don't know what does. 如果这不违反最低惊喜原则,我不知道是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM