IOS: AVSpeechSynthesizer: need to speak text in the left channel for headphones

I am using AVSpeechSynthesizer for TextToSpeech. I need to play in the left channel HeadPhone Channel (Mono 2). I have the following to set the output channel.

func initalizeSpeechForRightChannel(){ let avSession = AVAudioSession.sharedInstance() let route = avSession.currentRoute let outputPorts = route.outputs var channels:[AVAudioSessionChannelDescription] = [] //NSMutableArray *channels = [NSMutableArray array]; var leftAudioChannel:AVAudioSessionChannelDescription? = nil var leftAudioPortDesc:AVAudioSessionPortDescription? = nil for outputPort in outputPorts { for channel in outputPort.channels! { leftAudioPortDesc = outputPort //print("Name: \(channel.channelName)") if channel.channelName == "Headphones Left" { channels.append(channel) leftAudioChannel = channel }else { // leftAudioPortDesc?.channels?.removeObject(channel) } } } if channels.count > 0 { if #available(iOS 10.0, *) { print("Setting Left Channel") speechSynthesizer.outputChannels = channels print("Checking output channel : \(speechSynthesizer.outputChannels?.count)") } else { // Fallback on earlier versions } } } 

I have 2 problems in code

1. It is impossible to set the output channels, always nil (this happens when you first call this method, consecutive calls work fine)

2. Support for output channels from iOS 10. * But I need to support it with iOS 8.0

Please provide the best way to do this.

+5
source share
1 answer
+1
source

Source: https://habr.com/ru/post/1264442/


All Articles