debug
This commit is contained in:
parent
ee1d84cb1c
commit
a9362449a6
|
@ -72,21 +72,23 @@ int sendCustomAudioData(int16_t destChannelIndex, py::object pD,
|
|||
throw std::runtime_error("Failed to convert input to int16 array");
|
||||
}
|
||||
|
||||
// 修复点:显式构造 py::object(两种写法均可)
|
||||
py::object arr(py::handle<>(py_array)); // 写法1:构造函数
|
||||
// py::object arr = py::reinterpret_borrow<py::object>(py_array); // 写法2:borrow语义
|
||||
// 修复点:使用花括号初始化
|
||||
py::object arr{py::handle<>(py_array)};
|
||||
|
||||
// 检查数据长度
|
||||
PyArrayObject* npArray = reinterpret_cast<PyArrayObject*>(arr.ptr());
|
||||
if (PyArray_SIZE(npArray) != static_cast<npy_intp>(dataLen)) {
|
||||
Py_DECREF(py_array);
|
||||
throw std::runtime_error("Array length does not match dataLen");
|
||||
}
|
||||
|
||||
// 处理数据...
|
||||
void* dataPtr = PyArray_DATA(npArray);
|
||||
return RTCContext::instance().sendCustomAudioData(
|
||||
int ret = RTCContext::instance().sendCustomAudioData(
|
||||
destChannelIndex, dataPtr, sampleRate, channelNum, dataLen
|
||||
);
|
||||
Py_DECREF(py_array); // 释放临时数组
|
||||
return ret;
|
||||
} catch (...) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Invalid audio data");
|
||||
return -1;
|
||||
|
|
Loading…
Reference in New Issue