I am using AVSpeechSynthesizer for TextToSpeech. I have to play the speak in HeadPhone left Channel (Mono 2). I have got 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 the code
1. Cant able to set outputchannels , It always nil (It is happening on first time calling this method, consecutive calls working fine)
2. outputchannels supports from iOS 10.* But I need to support it from iOS 8.0
Please provide the best way to do that.
1 Answers
Answers 1
Instead of checking the
channelName
, which is descriptive (i.e. for the user), check thechannelLabel
. There is an enumeration containing the left channel.I suspect this may not be possible pre-iOS 10.
AVAudioSession doesn't appear to have any method to select only the left output channel.You may be able to useoverrideAudioPort:error
but it would affect the entire app.
0 comments:
Post a Comment