2016-09-09 3 views
2

내가 필요한 것은 왼쪽 또는 오른쪽 채널 만 사용하여 오디오를 재생하는 것입니다. AVAudioPlayer는 pan 속성을 사용하여 두 채널 중 하나를 사용하여 오디오를 재생할 수 있습니다. AVSpeechSynthesizer가이를 수행 할 방법이없는 경우 AVAudioPlayer를 사용하여 음성을 재생하여 채널을 제어 할 수 있습니까? 어떻게 든 AVSpeechUtterance의 NSURL을 가져 와서 AVAudioPlayer를 사용하여 재생할 수 있습니다.안녕하세요, AVS 음성 합성기가 헤드셋을 사용하여 오디오를 재생하는 동안 두 채널 중 하나를 사용하여 오디오를 재생할 수있는 방법이 있습니까?

이전의 비슷한 질문 만 : Any way to control which audio channel AVSpeechSynthesizer outputs to? 나는 답변을 찾지 못했고 솔루션을 찾으려고 비어 있습니다.

답변

2

예, outputChannels 속성을 AVSpeechSynthesizer으로 사용하면됩니다. 애플은 이것에 대한 어떤 문서도 게시하지 않았지만, channelAssignments 속성은 AVAudioPlayer과 같은 방식으로 작동합니다. 다음과 같이 사람이 읽을 수있는 사용 가능한 채널 목록을 반환합니다.

- (NSArray *)getAudioChannelNames { 
    // return the name of each channel in each connected audio port 
    // examples: Headphones Left/Right, Speaker, DUO-CAPTURE 1/2 
    AVAudioSession *session = [AVAudioSession sharedInstance]; 
    AVAudioSessionRouteDescription *route = [session currentRoute]; 
    NSArray *outputPorts = [route outputs]; 
    NSMutableArray *channels = [NSMutableArray array]; 
    for (AVAudioSessionPortDescription *outputPort in outputPorts) { 
     for (AVAudioSessionChannelDescription *channel in outputPort.channels) { 
      [channels addObject:channel.channelName]; 
     } 
    } 
    return channels; 
} 

사용자 또는 사용자가 사용할 채널 이름을 선택할 수 있습니다.

- (void)setSpeechSynthesizer:(AVSpeechSynthesizer *)speechSynthesizer toChannels:(NSArray *)channelNames { 
    AVAudioSession *session = [AVAudioSession sharedInstance]; 
    AVAudioSessionRouteDescription *route = [session currentRoute]; 
    NSArray *outputPorts = [route outputs]; 
    NSMutableArray *channelDescriptions = [NSMutableArray array]; 
    for (NSString *channelName in channelNames) { 
     for (AVAudioSessionPortDescription *outputPort in outputPorts) { 
      for (AVAudioSessionChannelDescription *channel in outputPort.channels) { 
       if ([channel.channelName isEqualToString:channelName]) { 
        [channelDescriptions addObject:channel]; 
       } 
      } 
     } 
    } 
    if ([channelDescriptions count]) { 
     speechSynthesizer.outputChannels = channelDescriptions; 
    } 
} 
+0

speechSynthesizer.outputChannels이 * 아이폰 OS 8.0 – Sridhar

+0

난 출력 채널을 설정할 때마다에 채널의 배열이 항상 것을 같은 것을 할 수있는 옵션이 있습니까 아이폰 OS 10에서 지원 : 그런 다음이 해당 채널을 사용하도록 AVSpeechSynthesizer을 설정 빈. 어떤 단서가? (나는 Swift와 Ios 10을 사용한다) –

+0

@zo_chu'getAudioChannelNames'의 결과가 비어 있음을 의미합니까? 오디오 세션에'AVAudioSessionCategoryMultiRoute'을 사용하고 있습니까? 나는 그 밖의 무엇을 제안해야할지 모른다. – arlomedia