2017-06-14 224 views
1

我在Swift中创建了一个应用程序,它使用Twilio & CallKit拨打电话。在通话过程中,我想通过电话的耳机扬声器播放音频,例如“您已经接听了2分钟......”或至少有一个内置的系统音频声音。在通话期间播放音频

它会的工作方式类似于如何导航,当他们宣布的方向,当你在通话

我怎样才能做到这一点的应用程序工作吗?

我已经看过这里的一些类似的问题,但我无法得到答案或更新的答案。

回答

1

找到一种方法来做到这一点是通过使用内置的AVSpeechSynthesizer。看看下面

public func sayMessage(message: String) { 
    do { 
     try setCategory(AVAudioSessionCategoryPlayAndRecord) 
     try setActive(true) 
     let synth = AVSpeechSynthesizer() 
     print("Routes:: \(currentRoute.outputs)") 
     if let currentChannels = currentRoute.outputs.first?.channels { 
      synth.outputChannels = currentChannels 
      print("Found channels \(currentChannels)") 
     } 
     let myUtterance = AVSpeechUtterance(string: message) 
     synth.speak(myUtterance) 

    } catch { 
     print(error) 
    } 
} 
+0

代码,您也可以使用'AVAudioPlayer'播放录制的声音,喜欢这里:https://stackoverflow.com/questions/24043904/creating-and-playing-a-sound-in -迅速 – philnash