【问题标题】:Accessing some file via Cloud Speech in Google cloud storage throws error 7通过 Google 云存储中的 Cloud Speech 访问某些文件会引发错误 7
【发布时间】:2018-02-09 13:01:13
【问题描述】:

这里是 上下文:我的 iOS swift 应用程序

  1. 录制声音,
  2. 创建一个 firebase 对象,
  3. 用对象的键重命名文件
  4. 在 Firebase 云上上传 wav 文件。
  5. 触发了 Firebase 云功能,将音频文件发送到 Google Speech .recognize

我的问题: 当我手动将声音文件上传到云存储时,它可以正常工作,但是当应用程序自动上传文件时,我收到以下错误消息作为语音 API 的返回:

{ Error: The caller does not have permission
at /user_code/node_modules/@google-cloud/speech/node_modules/grpc/src/node/src/client.js:554:15

代码:7,元数据:元数据{_internal_repr:{}​​},注意: '重试方法发生异常,未归类为 瞬态'}

这里是快速部分:

func uploadFile(fileName:String){

    // File located on disk
    let localFileURL = FileManager.default.urls(for: .documentDirectory, in:.userDomainMask)[0]
    let fileURL = localFileURL.appendingPathComponent(fileName)
    if FileManager.default.fileExists(atPath: fileURL.path) {
        print("FilePath", fileURL.path)
        // Create a reference to the file you want to upload
        let newMnemoRef = MnemoDatabase.shared.createNew()

        let newMnemoId = newMnemoRef.key
        let filename=newMnemoId+".wav"
        //let filename=fileName
        let audioStorageRef = storage.reference().child(filename)
        let storagePath = "gs://\(audioStorageRef.bucket)/\(audioStorageRef.fullPath)"

        print(storagePath)
        // Upload the file to the path "audio"
        let uploadTask = audioStorageRef.putFile(from: fileURL, metadata: nil) { metadata, error in
            if let error = error {
                print("Upload error : ", error.localizedDescription)
            } else {
                // Metadata contains file metadata such as size, content-type, and download URL.
                print ("OK")

            }
        }

        // Add a progress observer to an upload task
        let observer = uploadTask.observe(.success) { snapshot in
            print("uploaded!")
            newMnemoRef.child("audio").setValue([
                "encoding_converted":"LINEAR16",
                "sampleRate_converted":"44100",
                "path_converted":storagePath])

        }


    } else {
        print ("Non existent file", fileURL.path)
    }

}

调用语音 API 的云函数适用于手动上传文件。 这是摘录

const request = {
      encoding: encoding,
      sampleRateHertz: sampleRateHertz,
      languageCode: language,
      speechContexts: context

    };
speech.recognize(uri, request)

云存储桶和云函数都共享相同的项目凭据。 我从存储桶中删除了所有身份验证

// Anyone can read or write to the bucket, even non-users of your app.
// Because it is shared with Google App Engine, this will also make
// files uploaded via GAE public.
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

我什至尝试将路径硬编码到云函数中,但无济于事。

如果有任何帮助,我将不胜感激

【问题讨论】:

    标签: swift google-app-engine firebase firebase-realtime-database firebase-storage


    【解决方案1】:

    看来我正在处理两个不同的项目,我从中调用函数的一个没有激活语音 API,而我正在传递另一个项目的凭据。 我真的应该停止工作太晚了... 我重新设计了我的项目以使用文件触发器,这就是我发现错误的方式...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-12
      • 1970-01-01
      • 1970-01-01
      • 2019-01-24
      • 2021-10-18
      • 2018-08-05
      • 2023-02-17
      • 1970-01-01
      相关资源
      最近更新 更多