我正在尝试用SWIG包装下面的函数,这样我就可以在Python中调用它了。签名是:
int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame,
size_t frame_length);我有以下SWIG文件:
%module webrtc_vad
%{
#define SWIG_FILE_WITH_INIT
#include "webrtc/common_audio/vad/include/webrtc_vad.h"
%}
%{
/* Include in the generated wrapper file */
typedef unsigned int size_t;
%}
%include "stdint.i"
%include "numpy.i"
%init %{
import_array();
%}
typedef unsigned int size_t;
%apply (const int16_t* IN_ARRAY1, unsigned int DIM1) {(const int16_t* audio_frame, size_t frame_length)};
%include "webrtc/common_audio/vad/include/webrtc_vad.h"在这段代码的末尾,我得到以下错误:webrtc_vad.i:22: Warning 453: Can't apply (int16_t const *IN_ARRAY1,unsigned int DIM1). No typemaps are defined.
如果我在签名中删除了unsigned位,那么它编译得很好,但函数签名是按原样携带的(即函数需要一个整型指针和所有的事务)。
有谁有解决方案吗?非常感谢。
发布于 2015-12-17 16:57:21
我没有一个完整的答案,但我有一个类似的问题,它可能会有一些帮助。
我不知道为什么swig不能将unsigned int识别为一个大小,因为根据文档,“每一个类似整型的类型”都应该可以工作。不过,使用int应该没什么问题。
我的问题是对数组使用<stdint.h>类型(比如您的int16_t),我通过编辑numpy.i来解决这个问题:
https://stackoverflow.com/questions/33626537
复制相似问题