title: Text to speech from notification in ios swift
body: <p>I develop an app in ios swift. The data come from push notifications. In the notification payload, there is a text which is for playing. I play text to speech through <strong>AVSpeechSynthesizer</strong> but I want to play it 2,3 times it only plays one time. Please help me to resolve this issue. Thanks in advance.Here is the code</p>
  <pre><code>func textToSpeechWithMessage(message:String, _ languageCode:String)
      {
          
          let synthesizer = AVSpeechSynthesizer()
          
          let audioSession = AVAudioSession.sharedInstance()
          
          print(&quot;Activating audio session&quot;)
          do {
              try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback)
              
              try audioSession.setActive(true)
              UIApplication.shared.beginReceivingRemoteControlEvents()
              
              let utterance = AVSpeechUtterance(string:message)
              utterance.rate = 0.5
              utterance.volume = 0.8
              utterance.voice = AVSpeechSynthesisVoice(language: languageCode)
              synthesizer.speak(utterance)
  
              
          } catch {
              print(&quot;Unable to set audio session category: %@&quot;, error)
          }
      }
  </code></pre>