Да, вы можете сделать это, используя outputChannels
property AVSpeechSynthesizer
. Apple не размещала никакой документации для этого, но работает так же, как и свойство 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;
}
Вы или пользователь можете выбрать название канала для использования. Тогда это устанавливает AVSpeechSynthesizer
использовать этот канал:
- (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;
}
}
speechSynthesizer.outputChannels поддерживает с прошивки 10. * Есть ли возможность сделать это в прошивке 8.0 – Sridhar
каждый раз, когда я выходные каналы, как, что массив каналов всегда пустой. Какие-нибудь подсказки, почему? (я использую Swift и ios 10) –
@zo_chu Вы имеете в виду результат 'getAudioChannelNames' пуст? Вы используете 'AVAudioSessionCategoryMultiRoute' для своей аудио сессии? Я не знаю, что еще предложить. – arlomedia