【问题标题】:Play audio during phone call在通话期间播放音频
【发布时间】:2017-11-16 21:43:48
【问题描述】:

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

它的工作方式类似于导航应用在您通话时宣布路线时的工作方式

我怎样才能做到这一点?

我在这里查看了一些类似的问题,但我无法得到答案或更新的答案。

【问题讨论】:

    标签: ios swift twilio callkit


    【解决方案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)
        }
    }
    

    【讨论】:

    • 您也可以使用AVAudioPlayer 播放录制的声音,例如:stackoverflow.com/questions/24043904/…
    • @philnash 答案不完整。您何时/何地调用此方法?
    • @VyachaslavGerchicov 我不知道,取决于您希望何时播放音频。这取决于你?
    • @philnash 你写了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:)
    • 抱歉,但那是来自提问者和回答者,是@Phil,而不是我。再次检查您的用户名?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    相关资源
    最近更新 更多