没有耳机听不到 AVAudioRecorder 的声音

发布于 2024-11-14 10:43:52 字数 489 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

在巴黎塔顶看东京樱花 2024-11-21 10:43:52

在播放声音之前,您必须将 AVAudiosession 类别设置为 AVAudioSessionCategoryPlayback

You have to set the AVAudiosession category to AVAudioSessionCategoryPlayback before playing the sound

萌酱 2024-11-21 10:43:52

另一件需要考虑的事情是,如果您没有设置 AVAudioSession 进行播放,那么手机侧面的静音铃声开关将使您的音频无法通过扬声器播放。为了使您能够使用静音手机播放声音,请确保在触发 AVAudioPlayer 播放文件之前使用类似的内容:

AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
[session setActive:YES error:nil];

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:

AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
[session setActive:YES error:nil];
橘虞初梦 2024-11-21 10:43:52

也许将音频输出强制路由到扬声器会有帮助?

- (void) forceRouteAudioToSpeaker
{
    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
    AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute,
        sizeof(audioRouteOverride), &audioRouteOverride);
}

不要忘记包含 。再想一想,将音频类别切换为普通播放也应该可以解决问题,而你说它没有......

Maybe force-routing the audio output to the speaker will help?

- (void) forceRouteAudioToSpeaker
{
    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
    AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute,
        sizeof(audioRouteOverride), &audioRouteOverride);
}

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…

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文