1

I created a simple model with Pytorch to recognize bird sounds and until now I feed it .wav recordings. I want to start doing real time recognition and my question is: can I convert bytes to Pytorch tensors directly without converting it first to numpy?

What I do is make an MFCC from the audio that feed it to the model.

Thank you

What I'm doing right now is to use numpy.frombuffer and after I use torch.from_numpy as a way to convert the byte data to tensor

asabasdc
  • 23
  • 4

2 Answers2

0

PyTorch also has a torch.frombuffer function.

jodag
  • 19,885
  • 5
  • 47
  • 66
0

there has more flexible and effcient way:

import numpy
import torch
resut=torch.Tensor(numpy.frombuffer(bytes_origin_var, dtype=numpy.int32))

where result is dtypet is numpy.int32 tensor