gpt4 book ai didi

ios - 覆盖iOS音频输出

转载 作者:行者123 更新时间:2023-12-02 23:49:11 25 4
gpt4 key购买 nike

我一直在为一个正在研究的项目做一些研究,试图确定是否可以通过编程方式重定向音频输出。假设我有一个通过USB连接到iPhone的音频混音器盒。该USB支持音频输入和输出路由。我知道如何“检测”外部USB附件是否已连接到iPhone,并且我知道如何检测AVAudioSession的输入和输出。现在,让我发布一些示例代码,并将其理解为到目前为止。

AVAudioSessionRouteDescription *route = [[AVAudioSession sharedInstance] currentRoute];

//Check the route inputs
for( AVAudioSessionPortDescription *inputDescription in route.inputs)
{
NSLog(@"Port Name: %@", inputDescription.portName);
NSLog(@"Port Description: %@", inputDescription.portType);

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Input Ports" message:[NSString stringWithFormat:@"INPUT PORT NAME NAME: %@ INPUT PORT DESCRIPTION: %@ INPUT ROUTE COUNT: %lu",inputDescription.portName, inputDescription.portType, (unsigned long)[route.outputs count]] delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok" , nil];
[alert show];

[self setInput:inputDescription];
}

if(route.inputs.count == 0)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Input Ports" message:@"Did not detect any input connections" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok" , nil];

[alert show];
}

//Check the route outputs
for( AVAudioSessionPortDescription *portDescription in route.outputs )
{
NSLog(@"Port Name: %@", portDescription.portName);
NSLog(@"Port Description: %@", portDescription.portType);

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Output Ports" message:[NSString stringWithFormat:@"OUTPUT PORT NAME NAME: %@ OUTPUT PORT DESCRIPTION: %@ OUTPUT ROUTE COUNT: %lu",portDescription.portName, portDescription.portType, (unsigned long)[route.outputs count]] delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok" , nil];
[alert show];
}

我也知道如何“替代” iOS输出,以便它涉及内置扬声器而不是耳机。
NSError *error;

AVAudioSession *session = [AVAudioSession sharedInstance];

BOOL overrideSuccess = [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];

if(overrideSuccess)
{
NSLog(@"Override succeeded");
}

理想情况下,我希望能够执行以下操作:
  • 检测任何输出并将其显示给用户。 (我可以这样做)
  • 允许用户“选择”他们希望使用
  • 的输出
  • 覆盖当前输出路径,以将输出重定向到用户希望使用的设备。

  • 我不确定是否可以做这最后一步。

    这个想法是让用户进行录音而不仅限于iOS设备的外部麦克风。如果我想要实现什么,将不胜感激任何提示或建议。另外,我已经广泛浏览了Apple文档,因此无法断定是否有100%的可能性。

    最佳答案

    如果使用AVAudioSession,则可以使用“overrideOutputAudioPort:error:”方法来实现。这是指向AVAudioSession类引用的链接:https://developer.apple.com/library/IOs/documentation/AVFoundation/Reference/AVAudioSession_ClassReference/index.html

    关于ios - 覆盖iOS音频输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27065122/

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