【发布时间】:2017-11-16 21:43:48
【问题描述】:
我在 Swift 中创建了一个应用程序,它使用 Twilio 和 CallKit 来拨打电话。在通话过程中,我想通过手机的耳机播放音频,例如“您已接听此电话 2 分钟......”或至少一个内置的系统音频声音。
它的工作方式类似于导航应用在您通话时宣布路线时的工作方式
我怎样才能做到这一点?
我在这里查看了一些类似的问题,但我无法得到答案或更新的答案。
【问题讨论】:
我在 Swift 中创建了一个应用程序,它使用 Twilio 和 CallKit 来拨打电话。在通话过程中,我想通过手机的耳机播放音频,例如“您已接听此电话 2 分钟......”或至少一个内置的系统音频声音。
它的工作方式类似于导航应用在您通话时宣布路线时的工作方式
我怎样才能做到这一点?
我在这里查看了一些类似的问题,但我无法得到答案或更新的答案。
【问题讨论】:
发现一种方法是使用内置的 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)
}
}
【讨论】:
AVAudioPlayer 播放录制的声音,例如:stackoverflow.com/questions/24043904/…
I've created an app in Swift that uses Twilio & CallKit to make outgoing phone calls. During the phone call, I would like to play audio。您能否添加信息,如何以及何时调用您的 func sayMessage(message:)?