如何从Google Storage加载音频/如何从Google Storage读取音频 [英] how to load audio from Google Storage/ how to read audio from google storage

查看:109
本文介绍了如何从Google Storage加载音频/如何从Google Storage读取音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以wav格式将音频文件保存在google存储中,但是当我尝试使用google colab加载音频时,却无法完成操作.

I save my audio file in google storage in wav format, but when i try to load the audio using google colab, i not manage to done it.

下面是我用来从Google存储设备加载音频的示例.

Below the example i used to load audio from google storage.

import numpy as np
import IPython.display as ipd
import librosa
import soundfile as sf
import io
from google.cloud import storage
import os
from google.colab import auth
auth.authenticate_user()
os.environ["GCLOUD_PROJECT"] = "fundpro" #project_id
BUCKET = 'parli-2020' #bucket_name
gcs = storage.Client()
bucket = gcs.get_bucket(BUCKET)
import speech_recognition as sr
for blob in bucket.list_blobs(prefix='speech/Transcribe'):
    filename = 'gs://parli-2020/' + blob.name
    X, sample_rate = librosa.core.load(filename)

但显示此错误;

filename cannot be found.[Errno 2] No such file or directory

如果有人可以帮助我,我将非常感激...

If anyone could help me out I'd be very thankful...

谢谢

推荐答案

Librosa不支持GCS协议,如

Librosa doesn't support GCS protocol, as explained in the source code documentation

因此,要使用符合路径的解决方案,可以使用gcsfs库

So, to use a path compliant solution, you can use gcsfs library

from fs import open_fs
...
...
for blob in bucket.list_blobs(prefix='speech/Transcribe'):
    filename = 'gs://parli-2020/' + blob.name
    gcsfs = open_fs(filename)
    X, sample_rate = librosa.core.load(gcsfs)

这篇关于如何从Google Storage加载音频/如何从Google Storage读取音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆