gpt4 book ai didi

python - 像目录一样写入 Google Cloud 存储桶?

转载 作者:行者123 更新时间:2023-12-01 21:23:45 24 4
gpt4 key购买 nike

我编写了一个 Python 脚本,可以对大量音频数据进行重新采样和重命名,并将其移动到磁盘上的新位置。我想使用此脚本将我正在重采样的数据移动到谷歌存储桶。

问题:有没有一种方法可以将您的 GCP VM 实例连接/挂载到存储桶,这样就可以像存储桶只是另一个目录一样进行读写?

例如,这是我脚本中的某处:

# load audio from old location
audio, _ = librosa.load(old_path):

# Do some stuff to the audio
# ...

# write audio to new location
with sf.SoundFile(new_path, 'w', sr, channels=1, format='WAV') as f:
f.write(audio)

我想要一种方法来获取我的存储桶的路径,因为我的脚本采用原始数据所在的old_path,重新采样并将其移动到新路径

我的脚本不会像上面的代码片段看起来那么容易修改,因为我正在做很多多处理。另外,我想让脚本通用,这样我就可以将它重新用于本地文件等。基本上,改变脚本是不可能的。

最佳答案

您可以使用 FUSE 适配器将 GCS 存储桶挂载到本地文件系统

https://cloud.google.com/storage/docs/gcs-fuse

对于 Linux:

sudo apt-get update
sudo apt-get install gcsfuse
gcsfuse mybucket /my/path

或者,您可以使用适用于 Python 的 GCS 客户端直接上传您的内容:

https://cloud.google.com/storage/docs/reference/libraries#client-libraries-usage-python

关于python - 像目录一样写入 Google Cloud 存储桶?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63418588/

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