@@ -43,25 +43,20 @@ int64_t create_from_file_like(
4343}
4444
4545int64_t encode_audio_to_file_like (
46- py::bytes samples_data ,
47- py::tuple samples_shape ,
46+ uintptr_t data_ptr ,
47+ py::list shape ,
4848 int64_t sample_rate,
4949 const std::string& format,
5050 py::object file_like,
5151 std::optional<int64_t > bit_rate = std::nullopt ,
5252 std::optional<int64_t > num_channels = std::nullopt ) {
53- // Convert Python data back to tensor
54- auto shape_vec = samples_shape.cast <std::vector<int64_t >>();
55- std::string samples_str = samples_data;
53+ // Convert Python list to vector
54+ auto shape_vec = shape.cast <std::vector<int64_t >>();
5655
57- // Create tensor from raw data
56+ // Create tensor from existing data pointer (enforcing float32)
5857 auto tensor_options = torch::TensorOptions ().dtype (torch::kFloat32 );
59- auto samples =
60- torch::from_blob (
61- const_cast <void *>(static_cast <const void *>(samples_str.data ())),
62- shape_vec,
63- tensor_options)
64- .clone (); // Clone to ensure memory ownership
58+ auto samples = torch::from_blob (
59+ reinterpret_cast <void *>(data_ptr), shape_vec, tensor_options);
6560
6661 AudioStreamOptions audioStreamOptions;
6762 audioStreamOptions.bitRate = bit_rate;
@@ -86,8 +81,8 @@ PYBIND11_MODULE(decoder_core_pybind_ops, m) {
8681 m.def (
8782 " encode_audio_to_file_like" ,
8883 &encode_audio_to_file_like,
89- " samples_data " _a,
90- " samples_shape " _a,
84+ " data_ptr " _a,
85+ " shape " _a,
9186 " sample_rate" _a,
9287 " format" _a,
9388 " file_like" _a,
0 commit comments