This commit is contained in:
wangjiyu 2025-04-10 10:38:57 +08:00
parent f1414abe5c
commit ee1d84cb1c
1 changed files with 6 additions and 2 deletions

View File

@ -58,6 +58,7 @@ py::object create_int16_array() {
// 4. 转换为 py::object自动管理引用计数
return py::object(py::handle<>(py_array));
}
int sendCustomAudioData(int16_t destChannelIndex, py::object pD,
int32_t sampleRate, uint64_t channelNum, uint64_t dataLen) {
try {
@ -71,10 +72,12 @@ int sendCustomAudioData(int16_t destChannelIndex, py::object pD,
throw std::runtime_error("Failed to convert input to int16 array");
}
py::object arr = py::handle<>(py_array);
PyArrayObject* npArray = reinterpret_cast<PyArrayObject*>(arr.ptr());
// 修复点:显式构造 py::object两种写法均可
py::object arr(py::handle<>(py_array)); // 写法1构造函数
// py::object arr = py::reinterpret_borrow<py::object>(py_array); // 写法2borrow语义
// 检查数据长度
PyArrayObject* npArray = reinterpret_cast<PyArrayObject*>(arr.ptr());
if (PyArray_SIZE(npArray) != static_cast<npy_intp>(dataLen)) {
throw std::runtime_error("Array length does not match dataLen");
}
@ -89,6 +92,7 @@ int sendCustomAudioData(int16_t destChannelIndex, py::object pD,
return -1;
}
}
/*
int sendCustomAudioData(const int16_t destChannelIndex, py::object pyData, int32_t sampleRate, uint64_t channelNum,
uint64_t dataLen) {