gpt4 book ai didi

iphone - 如何通过扬声器而不是弱得多的耳机播放音频?

转载 作者:技术小花猫 更新时间:2023-10-29 11:03:09 25 4
gpt4 key购买 nike

我正在学习核心音频。出于某种原因,处理图的声音只能通过微弱的“耳机扬声器”播放(当您将设备放在耳朵上时),而不是通过 iPhone 的常规扬声器播放。

这是设置 Audio Session 的代码,但我看不到它在哪里配置音频路由:

- (void) setupAudioSession {

AVAudioSession *mySession = [AVAudioSession sharedInstance];

// Specify that this object is the delegate of the audio session, so that
// this object's endInterruption method will be invoked when needed.
[mySession setDelegate: self];

// Assign the Playback category to the audio session.
NSError *audioSessionError = nil;
[mySession setCategory: AVAudioSessionCategoryPlayAndRecord//AVAudioSessionCategoryPlayback
error: &audioSessionError];

if (audioSessionError != nil) {

NSLog (@"Error setting audio session category.");
return;
}

// Request the desired hardware sample rate.
self.graphSampleRate = 44100.0; // Hertz

[mySession setPreferredHardwareSampleRate: graphSampleRate
error: &audioSessionError];

if (audioSessionError != nil) {

NSLog (@"Error setting preferred hardware sample rate.");
return;
}

// Activate the audio session
[mySession setActive: YES
error: &audioSessionError];

if (audioSessionError != nil) {

NSLog (@"Error activating audio session during initial setup.");
return;
}

// Obtain the actual hardware sample rate and store it for later use in the audio processing graph.
self.graphSampleRate = [mySession currentHardwareSampleRate];

// Register the audio route change listener callback function with the audio session.
AudioSessionAddPropertyListener (
kAudioSessionProperty_AudioRouteChange,
audioRouteChangeListenerCallback,
self
);
}

当使用音频单元播放声音时,您会在核心音频的哪一点说“通过扬声器播放”?

最佳答案

您可以使用setCategory withOption:

[mySession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:&audioSessionError];

关于iphone - 如何通过扬声器而不是弱得多的耳机播放音频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14418147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com