File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -176,8 +176,21 @@ def encode_audio_to_file_like(
176176 if samples .dtype != torch .float32 :
177177 raise ValueError (f"samples must have dtype torch.float32, got { samples .dtype } " )
178178
179- samples = samples .contiguous ()
179+ # We're having the same problem as with the decoder's create_from_file_like:
180+ # We should be able to pass a tensor directly, but this leads to a pybind
181+ # error. In order to work around this, we pass the pointer to the tensor's
182+ # data, and its shape, in order to re-construct it in C++. For this to work:
183+ # - the tensor must be float32
184+ # - the tensor must be contiguous, which is why we call contiguous().
185+ # In theory we could avoid this restriction by also passing the strides?
186+ # - IMPORTANT: the input samples tensor and its underlying data must be
187+ # alive during the call.
188+ #
189+ # A more elegant solution would be to cast the tensor into a py::object, but
190+ # casting the py::object backk to a tensor in C++ seems to lead to the same
191+ # pybing error.
180192
193+ samples = samples .contiguous ()
181194 _pybind_ops .encode_audio_to_file_like (
182195 samples .data_ptr (),
183196 list (samples .shape ),
You can’t perform that action at this time.
0 commit comments