AVSpeechSynthesizer : speak text in Headphone left channel

Hi all,


I am using AVSpeechSynthesizer for Text-To-Speak functionality. If headphones connected to device, the AVSpeechSynthesizer should speak in particular channel ie Headphone Left (MONO 2). I tried the below code to achieve this functionality. It works but It suports from iOS 10.0.




func initalizeSpeechForRightChannel(){

let avSession = AVAudioSession.sharedInstance()

let route = avSession.currentRoute

let outputPorts = route.outputs

var leftChannels:[AVAudioSessionChannelDescription] = []

for outputPort in outputPorts {

for channel in outputPort.channels! {

if channel.channelName == "Headphones Left" {

leftChannels.append(channel)

}

}

}

if channels.count > 0 {

if #available(iOS 10.0, *) {

print("Setting Left Channel")

speechSynthesizer.outputChannels = leftChannels /

print("Checking output channel : \(speechSynthesizer.outputChannels?.count)")

}

}

}


Is there any option to do this functionality for iOS 8.2?

Or is there any other option to achieve this functionality (playing the speech only on Left or Right HeadPhone)?

Replies

In relate to the oculus build in headphones and mic, i excluded my headphones on the rift to use my 7.1 headset. do i just skip the "set up oculus mode on discord" step?

Instead of checking the

channelName
, which is descriptive (i.e. for the user), check the
channelLabel
.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 use overrideAudioPort:error but it would affect the entire app.