语音录制与播放

录制与播放

void start_capture_callback(int rescode,void* user_data)
{
    //开始录音
}

void stop_capture_callback(int rescode, const char* file_path, const char* file_ext, long file_size, int audio_duration,void* userdata)
{
    //结束录音,获取语音文件详细信息
}

void cancel_capture_callback(int rescode,void* user_data)
{
    //取消语音录制
}

typedef bool(*nim_audio_reg_start_capture_cb)(nim_rescode_cb cb, void* user_data);
typedef bool(*nim_audio_reg_stop_capture_cb)(nim_stop_capture_cb cb,void* user_data);
typedef bool(*nim_audio_reg_cancel_audio_cb)(nim_rescode_id_cb cb,void* user_data);

typedef bool(*nim_audio_start_capture)(int audio_format, int volume, int loudness , const char* capture_device);
typedef bool(*nim_audio_stop_capture)();
typedef bool(*nim_audio_cancel_audio)();

void OnInit()
{
    //从动态库获取函数指针,注册语音回调
    nim_audio_reg_start_capture_cb start_func = (nim_audio_reg_start_capture_cb) dlsym(hInst, "nim_audio_reg_start_capture_cb");
    nim_audio_reg_stop_capture_cb stop_func = (nim_audio_reg_stop_capture_cb) dlsym(hInst, "nim_audio_reg_stop_capture_cb");
    nim_audio_reg_cancel_audio_cb cancel_func = (nim_audio_reg_cancel_audio_cb) dlsym(hInst, "nim_audio_reg_cancel_audio_cb");

    nim_audio_reg_stop_capture_cb stop_func = (nim_audio_reg_stop_capture_cb) dlsym(hInst, "nim_audio_reg_stop_capture_cb");
    nim_audio_reg_cancel_audio_cb cancel_func = (nim_audio_reg_cancel_audio_cb) dlsym(hInst, "nim_audio_reg_cancel_audio_cb");

    start_funcb(start_capture_callback,NULL);
    stop_func(stop_capture_callback,NULL);
    cancel_func(cancel_capture_callback,NULL);
}

bool StartCapture(int audio_format, int volume, int loudness , const char* capture_device)
{
    nim_audio_start_capture func = (nim_audio_start_capture) dlsym(hInst, "nim_audio_start_capture");
    return func(audio_format,volume,loudness,capture_device);
}

bool StopCapture()
{
    nim_audio_stop_capture func = (nim_audio_stop_capture) dlsym(hInst, "nim_audio_stop_capture");
    return func();
}

bool CancelCapture()
{
    nim_audio_reg_cancel_audio_cb func = (nim_audio_reg_cancel_audio_cb) dlsym(hInst, "nim_audio_reg_cancel_audio_cb");
    return func();
}