1
这里是上下文:我的iOS迅速应用通过云讲话在谷歌云存储访问某些文件会抛出错误7
- 记录声音,
- 创建了一个火力点对象,
- 重命名文件与对象的关键
- 上firebase云的wav文件。
- 一个火力点云功能被触发发送音频文件到谷歌语音.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;
}
}
}
我甚至尝试硬编码路径到云的功能,但无济于事。
我会感谢所有帮助