gpt4 book ai didi

python - 如何从谷歌云存储桶读取音频文件并在datalab笔记本中使用ipd播放

转载 作者:行者123 更新时间:2023-12-02 08:10:32 24 4
gpt4 key购买 nike

我想在数据实验室笔记本中播放我从谷歌云存储桶中读取的声音文件。如何做到这一点?

最佳答案

import numpy as np
import IPython.display as ipd
import librosa
import soundfile as sf
import io
from google.cloud import storage

BUCKET = 'some-bucket'

# Create a Cloud Storage client.
gcs = storage.Client()

# Get the bucket that the file will be uploaded to.
bucket = gcs.get_bucket(BUCKET)

# specify a filename
file_name = 'some_dir/some_audio.wav'

# read a blob
blob = bucket.blob(file_name)
file_as_string = blob.download_as_string()

# convert the string to bytes and then finally to audio samples as floats
# and the audio sample rate
data, sample_rate = sf.read(io.BytesIO(file_as_string))

left_channel = data[:,0] # I assume the left channel is column zero

# enable play button in datalab notebook
ipd.Audio(left_channel, rate=sample_rate)

关于python - 如何从谷歌云存储桶读取音频文件并在datalab笔记本中使用ipd播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51413209/

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