没有耳机听不到 AVAudioRecorder 的声音
我正在使用 AVAudioRecorder 在 iPhone 上录制语音,这些是我的录音机设置:
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:16000.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
问题是,如果没有耳机,我无法听到录制的声音。 我也希望不戴耳机也能听到声音。 我应该如何更改我的代码?
I am recording voice on iPhone using AVAudioRecorder and these are my recorder settings:
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:16000.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
The problem is that I can't hear the recorded voice without headphones.
I want to be able to hear the voice without headphones also.
How should I change my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在播放声音之前,您必须将 AVAudiosession 类别设置为
AVAudioSessionCategoryPlayback
You have to set the AVAudiosession category to
AVAudioSessionCategoryPlayback
before playing the sound另一件需要考虑的事情是,如果您没有设置 AVAudioSession 进行播放,那么手机侧面的静音铃声开关将使您的音频无法通过扬声器播放。为了使您能够使用静音手机播放声音,请确保在触发 AVAudioPlayer 播放文件之前使用类似的内容:
Another thing to consider is that if you do not set up your AVAudioSession for playback, then the silence ringer switch on the side of the phone will make your audio not play over the speaker. In order for you to be able to play sound with a silenced phone make sure you are using something like this before triggering your AVAudioPlayer to play the file:
也许将音频输出强制路由到扬声器会有帮助?
不要忘记包含
。再想一想,将音频类别切换为普通播放也应该可以解决问题,而你说它没有......Maybe force-routing the audio output to the speaker will help?
Don’t forget to include
<AudioToolbox/AudioServices.h>
. On second thought, switching the audio category to plain playback should also do the trick, and you say it didn’t…