如何将Numpy数组波形转换为类似WAV文件的对象?
我想将numpy阵列波形转换为类似WAV的对象,以便可以将其上传到S3,而无需保存波形以在本地文件。想象一下,我有一个numpy数组波形,y
,
y, sr = librosa.load('something.wav', sr = 44100)
如何将此numpy数组,y
转换为一个类似WAV文件的对象,使用boto3 < /code>'s
upload_fileobj
方法?
根据boto3
文档,类似文件的对象必须具有属性:
类似文件的对象上传。至少必须实现读取 方法,并且必须返回字节。
这就是我想上传类似文件的对象的方式:
import boto3
s3 = boto3.resource('s3')
bucket = s3.Bucket('mybucket')
# with open('filename', 'rb') as data:
# bucket.upload_fileobj(data, 'mykey')
bucket.upload_fileobj(wav_object, 'something.wav')
tldr:
我想要一个将numpy数组转换为wav样阵列的函数,以实现读取方法并返回字节。
I want to convert a numpy array waveform into a wav-like object so that I can upload it to S3 without having to save the waveform to file locally. Imagine I have a numpy array waveform, y
,
y, sr = librosa.load('something.wav', sr = 44100)
How can I convert this numpy array, y
into a wav file-like object to upload to S3 using boto3
's upload_fileobj
method?
According to the boto3
docs, the file-like object must have the properties:
A file-like object to upload. At a minimum, it must implement the read
method, and must return bytes.
This is how I would like to upload the file-like object:
import boto3
s3 = boto3.resource('s3')
bucket = s3.Bucket('mybucket')
# with open('filename', 'rb') as data:
# bucket.upload_fileobj(data, 'mykey')
bucket.upload_fileobj(wav_object, 'something.wav')
TLDR:
I want a function that converts a numpy array into a wav-like object that implements the read method and returns bytes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以这样尝试:
You can try like this: