title: Text To Speech (TTS) iOS7
body: <p>My application wants to play some text when it is available, and if there is some music playing in the background I want to lower the voice for the music while my app is playing its text, what I did is:</p>
  
  <pre><code>[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
                                   withOptions:AVAudioSessionCategoryOptionDuckOthers
                                        error:&amp;err];
  [[AVAudioSession sharedInstance] setActive:YES error:&amp;err];
  </code></pre>
  
  <p>The option <code>AVAudioSessionCategoryOptionDuckOthers</code> will lower the music volume while my app is playing its text.
  Then play the text with the <code>speechSynthesizer</code>, after that in:</p>
  
  <pre><code>- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)
  </code></pre>
  
  <p>utterance I do:</p>
  
  <pre><code>[[AVAudioSession sharedInstance] setActive:NO withFlags:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
  </code></pre>
  
  <p>so the music will be back to it original volume.</p>
  
  <p>The problem by setting the session active to NO, I am loosing the volume control (the iPhone hardware volume control the one in the left side of the phone). i.e I can not upper or lower the volume for my app unless there is a text actively playing in my app at the moment I am changing the volume.</p>