gpt4 book ai didi

ios - Replaykit 和 Twilio

转载 作者:行者123 更新时间:2023-11-30 11:58:31 30 4
gpt4 key购买 nike

我正在使用 Twilio 可编程视频在音频聊天中连接两个用户。我想为用户提供在 Audio Session 期间录制屏幕的选项,因此我使用 Replaykit。一切正常,除了 Twilio 启动后录音中的音频就中断了。

Twilio 使用的音频类型和 Replaykit 音频捕获之间是否存在冲突?

我之前在 Twilio 处于事件状态时尝试添加声音时遇到过类似的情况,并且一旦播放另一个声音,就会导致 Twilio 音频被切断。

编辑:我尝试了不同的方法,所以我只有最新的更改,但这是我用于 ReplayKit 的代码。这只是标准的开始、停止和预览录制。

func startRecording() {

guard recorder.isAvailable else {
print("Recording not available")
return
}

recorder.isMicrophoneEnabled = true

recorder.startRecording{ [unowned self] (error) in

guard error == nil else {
print("error starting the recording")
return
}

print("Started Recording Successfully")

self.isRecording = true
}
}

func stopRecording() {

recorder.stopRecording { [unowned self] (preview, error) in
print("Stopped recording")

guard preview != nil else {
print("Preview controller not available")
return
}

let alert = UIAlertController(title: "Recording Finished", message: "Would you like to edit or delete your recording?", preferredStyle: .alert)

let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (action: UIAlertAction) in
self.recorder.discardRecording(handler: { () -> Void in
print("Recording suffessfully deleted.")
})
})

let editAction = UIAlertAction(title: "Edit", style: .default, handler: { (action: UIAlertAction) -> Void in
preview?.previewControllerDelegate = self
self.present(preview!, animated: true, completion: nil)
})

alert.addAction(editAction)
alert.addAction(deleteAction)
self.present(alert, animated: true, completion: nil)

self.isRecording = false
}
}

func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
dismiss(animated: true)
}

我还尝试使用控制面板中的新录制功能。我可以从其他应用程序捕获音频,但是当 Twilio 在我的应用程序上启动时,录音中的音频会变得静音,并在 Twilio 停止时恢复。这让我觉得 Twilio 和 Replaykit 之间存在一些冲突,但也许有一种我不知道的方法来捕捉它。

我也尝试过 .startCapture 而不是 .startRecording,但我认为我没有正确使用它,而且我还没有找到太多关于它的文档。

最佳答案

为了防止新的音频源中断前一个音频源,您可以将其类别设置为环境:

 try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)

就您而言,我认为您应该将其应用于 Twilio session

关于ios - Replaykit 和 Twilio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47514359/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com