无法从 Siri 获取音频消息 INSendMessageIntent

Can't get audio message from Siri INSendMessageIntent

提问人:Ilya Krigouzov 提问时间:7/16/2023 更新时间:7/16/2023 访问量:24

问:

卡在尝试使用 SiriKit 发送语音消息时。

调用 Siri 命令,它正在录制消息,然后调用Send audio message with AppNamefunc handle(intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void)

但是附加的长度为 0,当我尝试通过直接 URL 获取文件时,我收到了消息Datafile:///var/tmp/SiriMessages/E262A828-A24E-452E-BF70-867F5653BEFE.caf: Unable to open «E262A828-A24E-452E-BF70-867F5653BEFE.caf», you have no permissions.

我没有找到任何权限设置,所以寻求帮助。

func handle(intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) {
        let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self))
        let MIMEType = "audio/x-caf"
        var resultCode: INSendMessageIntentResponseCode = .failure
        var response = INSendMessageIntentResponse(code: resultCode, userActivity: userActivity)
        
        if let audio = intent.attachments!.first?.audioMessageFile {

            let networkService = NetworkService() // Test service for uploading files

            let audioData =  audio.data
            let filePath = audio.fileURL!
            
            Task {
                var resultCode: INSendMessageIntentResponseCode = .success
                var response = INSendMessageIntentResponse(code: resultCode, userActivity: userActivity)
                
                await networkService.uploadAudioMessage(filePath: filePath, withMIMEType: MIMEType) // Here I've got permission error



                print("Size of file: \(audioData.count)") // Will output Size of file: 0
                print("Result success")
                
                completion(response)
                return
            }
        } else {
            print("no voice message attached")
            
            completion(response)
            return
        }
    }
斯威夫 ·诗丽吉特

评论

0赞 Gonzo Oin 9/29/2023
你找到任何解决方案了吗?我很难理解是否真的可以做到这一点。我没有成功让 Siri 开始录制音频,它一直告诉我我的应用程序无法处理音频消息

答: 暂无答案