package phonicapi; public class PhonicNative { /** * 设置事件通知回调函数和工作模式 * * @param eh回调函数 * @param mode * USB盒的工作模式,通常是录音方式,0录音模式,1诊断模式,2配置模式 * @return 0成功,其实失败 */ public static native int ubox_open(PhonicHandler eh, int mode); /** * 设关闭 */ public static native void ubox_close(); /** * 获取硬件的版本号, * * @param uboxHnd * 设备句柄 * @return version_num由整数部分和1位小数部分组成,整数部分是主版本号,小数部分是次版本号 */ public static native float ubox_get_device_versionnum(int uboxHnd); /** * 获取产品设备号 * * @param uboxHnd * 设备句柄 * @return 产品对应的设备号,1 FI3102A,2 FI3002B,3 FI3001B,4 FI3101A */ public static native int ubox_get_product_ID(int uboxHnd); /** * 获取产品设备名称 * * @param uboxHnd * 设备句柄 * @return 设备名称 * "FI3102A"两路外线,"FI3002B"两路高阻录音,"FI3001B"一路高阻录音,"FI3101A"带耳麦语音盒 */ public static native String ubox_get_product_name(int uboxHnd); /** * 读取用户号 * * @param uboxHnd * 设备句柄 * @param len * 返回用户号的长度不能低于16 * @return 用户号,用户号的长度为16字节,前8个字节为用户编号,后8个字节为出厂日期 */ public static native String ubox_get_usernum(int uboxHnd, int len); /** * 获取当前工作模式 * * @return 当前工作的模式有:0录音模式,1诊断模式,2配置模式 */ public static native int ubox_get_work_mode(); /** * 检查指定的语音编码是否合法 * * @param coder * 语音编码支持一下几种编码格式:0 CODER_ALAW,1 CODER_PCM,3 CODER_G729,20 * CODER_SPEEX(8倍压缩率),38 CODER_MP3,100 CODER_ULAW * @return 0合法,UBOX_ERR_INVALID_VOICE_CODER 语音编码不合法 */ public static native int ubox_check_coder(int coder); /** * 录音到文件中 * * @param uboxHnd * 设备句柄 * @param filename * 录音文件名 如果编码格式选择CODER_MP3,文件名后缀为.mp3,其它格式推荐使用.wav后缀 * @param coder * 语音编码格式:0 CODER_ALAW,1 CODER_PCM,3 CODER_G729,20 * CODER_SPEEX(8倍压缩率),38 CODER_MP3,100 * CODER_ULAW,一般推荐用CODER_ALAW, CODER_MP3和CODER_SPEEX编码 * @return 0成功,<0失败 */ public static native int ubox_record_file(int uboxHnd, String filename, int coder); /** * 流式录音 * * @param uboxHnd * 设备句柄 * @param coder * 语音编码格式:0 CODER_ALAW,1 CODER_PCM,3 CODER_G729,20 * CODER_SPEEX(8倍压缩率),38 CODER_MP3,100 CODER_ULAW * @return 0成功 * 说明:调用这个函数后,会不停地触发UBOX_EVENT_STREAM_VOICE事件,直到调用ubox_stop_record() */ public static native int ubox_record_stream(int uboxHnd, int coder); /** * 停止文件和流式录音 * * @param uboxHnd * 设备句柄 * @return 0成功 */ public static native int ubox_stop_record(int uboxHnd); /** * 读取悬空 * * @param uboxHnd * 设备句柄 * @return >0悬空门限值,<0失败 说明:此函数必需在 UBOX_MODE_CONFIG 模式下使用,否则返回 * UBOX_ERR_INVALID_WORK_MODE。Fi3001B调用这个函数才有意义 */ public static native int ubox_get_hang_threshold(int uboxHnd); /** * 设置悬空门限值,参考ubox_set_hookoff_threshold中的说明 * * @param uboxHnd * 设备句柄 * @param threshold * 小于该值,判断线路悬空 * @return 0成功, 说明:产品Fi3001B调用这个函数才有意义 */ public static native int ubox_set_hang_threshold(int uboxHnd, int threshold); /** * 读取摘机门限值 * * @param uboxHnd * 设备句柄 * @return >0摘机门限值,<0失败 说明:产品Fi3001B调用这个函数才有意义 */ public static native int ubox_get_hookoff_threshold(int uboxHnd); /** * 设置摘机门限值 * * @param uboxHnd * 设备句柄 * @param threshold * 的值是摘机电压和挂机电压的之和的一半,摘机电压和挂机电压测量调用,ubox_start_read_line_voltage, * 对于Fi3001B摘机状态是通过电压判断的 * @return 说明:产品Fi3001B调用这个函数才有意义 * Fi3001是通过压控方式检测电话状态,通常情况下,挂机时直流电压为48V左右,摘机时直流电压会降到6V左右 * 。USB录音盒设置默认摘机门限值为18V, * 当线路电压大于18V,软件判断为挂机,小于18V软件判断为摘机。由于电话线的所处的环境不同 * ,线路直流电压值不同,可能摘机后,线路电压依然要大于摘机门限值,这样软件不能正确检测到电话状态,需要重新设置摘机门限值 */ public static native int ubox_set_hookoff_threshold(int uboxHnd, int threshold); /** * 开始检测线路电压 * * @param uboxHnd * 设备句柄 * @return 0成功 * 说明:调用这个函数后,会不停触发UBOX_EVENT_LINE_VOLTAGE事件,报告当前线路电压值。产品Fi3001B调用这个函数才有意义 */ public static native int ubox_start_read_line_voltage(int uboxHnd); /** * 结束检测线路电压 * * @param uboxHnd * 设备句柄 * @return 0成功 说明:调用这个函数后,会停止触发UBOX_EVENT_LINE_VOLTAGE事件产品Fi3001B调用这个函数才有意义 */ public static native int ubox_stop_read_line_voltage(int uboxHnd); /** * 发送号码(DTMF) * * @param uboxHnd * 设备句柄 * @param dmftfstring * 号码串 * @return 0成功 * 说明:Fi3101A,FI3102A可以不摘机,软拨号直接拨出号码。对于Fi3101A,如果电话机摘机声音自动切换到电话机里 * ,底层自动软挂机,耳机无声音 * 。Fi3001B和Fi3002B,必须要先手动摘机,才可以拨号。对于有软摘机功能的产品,直接软件拨号, * 有可能拨号不成功,拨得太快了, * 交换机需要时间检测摘机,因此处理方法上层程序需要先软摘机后,延时1-2S钟,然后再调用ubox_send_dtmf函数 */ public static native int ubox_send_dtmf(int uboxHnd, String dmftfstring); /** * 播放语音文件 * * @param uboxHnd * 设备句柄 * @param filename * 语音文件名 * @return 0成功 说明:放音格式为: A-law,u-law, 8k * 16 位 pcm文件 */ public static native int ubox_play_file(int uboxHnd, String filename); /** * 停止播放 * * @param uboxHnd * 设备句柄 * @return 0成功 */ public static native int ubox_stop_play(int uboxHnd); /** * 暂停播放,再调用一次,继续播放 * * @param uboxHnd * 设备句柄 * @return 0成功 */ public static native int ubox_play_pause(int uboxHnd); /** * 设置MIC音量,一般设置为0db * * @param uboxHnd * 设备句柄 * @param volume * 设置值,取值范围为0--19 * @return 0成功 */ public static native int ubox_set_volume(int uboxHnd, int volume); /** * 设置放音音量 * * @param uboxHandle * 设备句柄 * @param volume * 设置音量,取值范围为-12--6 * @return 0成功 */ public static native int ubox_set_Speakervolume(long uboxHandle, short volume); /** * 打开和关闭agc * * @param uboxHnd * 设备句柄 * @param bclose * true关闭agc,false打开agc,默认情况下是打开agc * @return 0成功 */ public static native int ubox_close_agc(int uboxHnd, boolean bclose); /** * 读取USB录音盒中eeprom内的数据 * * @param uboxHnd * 设备句柄 * @param addr * 要读取的数据的起始地址,范围为0x00-0x07 * @param len * 读取的长度 * @return 读取到的数据 说明:Fi3001B使用该函数必须要在配置模式下才能使用 * 用法:假如uboxHnd=1,addr=0x0,unsigned char * readdata[8],ubox_read_eeprom * (1,0x00,&readata[0],8),调用成功后,读取的数据在readdata中 */ public static native String ubox_read_eeprom(int uboxHnd, char addr, int len); /** * 往USB录音盒中的eeprom写入数据 * * @param uboxHnd * 设备句柄 * @param addr * 开始写入的起始地址,范围为0x00-0x07 * @return 0成功 用法:假如uboxHnd=1,addr=0x00,unsigned char writedata[8]= * {0x01,0x20,0x30,0x31,0x32,0x33,0x40,0x70} * ubox_write_eeprom(1,0x0, * &writedata[0],8),可以在同一个地址区域调用ubox_read_eeprom验证,读取的数据和写入数据是否相等 */ public static native int ubox_write_eeprom(int uboxHnd, char addr, byte[] inData); /** * 读取USB录音盒中eeprom内的数据 * * @param uboxHnd * 设备句柄 * @param addr * 要读取的数据的起始地址,范围为0x00-0x07 * @param len * 读取的长度 * @return 读取到的数据 * 说明:对于Fi3001B,调用ubox_write_eeprom写成功后,读取其正确值,必须在软件重新启动后(关闭后, * 再打开),调用ubox_read_eepromEx才能正确读取上次修改的值 * 。而其它产品调用ReadEepromEx和ReadEeprom功能是一样的 * 用法:假如uboxHnd=1,addr=0x0,unsigned char * readdata[8],ubox_read_eeprom * (1,0x00,&readata[0],8),调用成功后,读取的数据在readdata中 */ public static native int ubox_read_eepromEx(int uboxHnd, char addr, int len); /** * 软件摘机 * * @param uboxHnd * 设备句柄 * @return 0成功 说明:Fi3101A 和Fi3102A才具有该功能 */ public static native int ubox_soft_hook_off(int uboxHnd); /** * 软件挂机 * * @param uboxHnd * 设备句柄 * @return 0成功 说明:Fi3101A 和Fi3102A才具有该功能 */ public static native int ubox_soft_hook_on(int uboxHnd); /** * 设置忙音参数 * * @param uboxHnd * 设备句柄 * @param dual_frequency * 是否是双音频,默认为0 * @param frequency0 * 忙音频率0,默认为450HZ * @param frequency1 * 忙音频率1,默认420HZ * @param busy_on * 忙音周期的持续时间,默认为35表示350ms * @param busy_off * 忙音周期的断续时间,默认为35表示350ms * @param on_off_error * 忙音周期的持续时间和断续时间的误差,默认为5表示50ms * @param enery_gate * 忙音的能量,默认为12db * @param period_count * 忙音判断的周期数,默认为3,表示连续检测到三个周期的忙音才报告有忙音UBOX_EVENT_DEVICE_BUSY_TONE事件 * @return 0成功 说明:Fi3101A 和Fi3102A才具有该功能 */ public static native int ubox_set_busy_tone(int uboxHnd, int dual_frequency, int frequency0, int frequency1, int busy_on, int busy_off, int on_off_error, int enery_gate, int period_count); /** * 设置留言模式参数 * * @param uboxHnd * 设备句柄 * @param bset * true打开留言参数,false关闭留言参数 * @return 0成功 说明:设置留言模式下才需要打开留言参数。要退出留言模式,必须关闭留言参数,否则麦克风不能用Fi3101A才具有该功能 */ public static native int ubox_set_message_param(int uboxHnd, boolean bset); /** * 打开/关闭蜂鸣器 * * @param uboxHnd * 设备句柄 * @param bset * true 打开蜂鸣器,false 关闭蜂鸣器。该功能的用于没有接电话机只接耳麦时,当振铃时蜂鸣器响,提示用户 * @return 0成功 说明:Fi3101A才具有该功能 */ public static native int ubox_open_buzzer_switch(int uboxHnd, boolean bset); /** * 打开日志文件,记录底层的工作信息 * * @param level * 0记录所有日志信息,1记录错误和警告信息,该函数可以在调用ubox_open之前调用 * 说明:调用这个函数后,在应用程序目录下会产生一个ubox-log目录,在该目录下会生成日志文件 */ public static native void ubox_open_logfile(long level); /** * 关闭日志文件 */ public static native void ubox_close_logfile(); /** *打开日志文件,该函数可以在调用ubox_open之前调用 *dir:记录日志文件的路径,如果为空,就是当前程序目录下。 *level=0, 显示所有日志信息 *level =1, 显示错误和警告信息显示 * * */ public static native void ubox_open_logfileEx(String strDir, long level); /** * 功 能:上传录音文件。 参 数:uploadUrl: 上传文件使用的URL(形如192.168.1.1) paramName: 提交http请求时,上传文件在服务器上名字,可以包括目录,目录必须是存在的。 uploadFilePath: 待上传的文件全路径(形如D:\\recordFile.wav) 返 回:上传成功返回0,失败返回负数。 * * */ public static native int ubox_uploadFile(String strUploadUrl, String strParamName, String strUploadFilename); /** 无线设备发送号码() * * @param uboxHnd * 设备句柄 * @param phonenumber * 电话号码 * @return 0成功 * 说明:无线设备外呼拨号 */ public static native int ubox_makecall(int uboxHnd, String phonenumber); public static native int ubox_reject_call(int uboxHnd); public static native int ubox_set_talk_link(int uboxHnd, int mode, int value); //设定通话link 开关 public static native int ubox_makecallSlic(int uboxHnd, int ringtime, int stopringtime, String phonenumber); public static native int ubox_set_record_enable(int uboxHnd, int mode, int value); // 设定录音开关 public static native int ubox_gsm_power(int uboxHnd, int value); //0:GSM模块断电, 1:GSM模块上电 public static native int ubox_gsm_bootkey(int uboxHnd, int value); //1:GSM开机键, 延时按1~2s,在调用释放命令, 0:GSM开机键释放 public static native int ubox_feed_slic_polarity(int uboxHnd, int value); //0:slic正向馈电, 1:slic反向馈电 /* */ public static native int ubox_send_gsm_cmd(int uboxHnd, String cmd, int len); //发送GSM命令,供调试GSM模块使用 /* * * uboxHnd 设备句柄 phonenumber: 手机电话号码,必须要加国家区号,比如8615907550000 mode: 0: 短信内容已经用unicode转码, 1:未转码的数据 msg: 短信内容 len: 短信长度 */ public static native int ubox_send_gsm_msg(int uboxHnd, int mode, String phonenumber, String msg, int len); //发短信 /* 查询GSM设备可存储短信数目和目前有多少条短信 */ public static native int ubox_query_gsm_msg_number(int uboxHnd); /* 按照索引值,该数值通过ubox_query_gsm_msg_number获取, index从1开始,查询GSM设备内短信内容 */ public static native int ubox_query_gsm_msg(int uboxHnd, int index); //短信内容是unicode方式,需要应用软件再转换 public static native int ubox_query_gsm_msgEx(int uboxHnd, int index); //短信内容已经转换为多字节方式 /*删除短信数目 msgtype=0, index是删除单条短信的序号,msgtype为其它值,index设为1 msgtype=1, 删除所有的已经阅读的短消息 msgtype=2, 删除所有的已经阅读和发送出去的短消息 msgtype=3, 删除所有的已经阅读过、已经发送出去的和未发送的短消息 msgtype=4, 删除所有的短消息 */ public static native int ubox_delete_gsm_msg(int uboxHnd, int index, int msgtype); //设备是单模,支持双卡,0:选择sim卡1, 1:选择sim卡2 // 选择卡后,需要给GSM模块断电,上电,然后调用GSM开机键 ubox_gsm_bootkey(1),延时2秒,最后开机键释放ubox_gsm_bootkey(0) public static native int ubox_select_simcard(int uboxHnd, int simcardno); /* 设置GSM输出和输入音量, type:0 输入音量 0-10 type:1:输出音量 0-100 */ public static native int ubox_set_gsm_vol(int uboxHnd, int type, int vol); /* type:0 输入音量 type:1:输出音量 获取GSM输出和输入音量,以事件UBOX_EVENT_GSM_VOL_SIZE通知 */ public static native int ubox_get_gsm_vol(int uboxHnd, int type); /* type: 0 耳麦模式, 1:电话机模式 设置耳麦和slic电话机工作模式 type mode 0 1 耳麦自动模式,有电话呼入,按耳麦线按钮,电话摘机,再按按一次,挂断GSM通话 0 0 关闭耳麦自动模式 1 1 话机自动模式,电话呼入,电话机振铃,电话机挂机,挂断GSM通话 1 0 关闭话机自动模式 */ public static native int ubox_set_gsm_work_mode(int uboxHnd, int type, int mode); /* 让GSM模块产生本地定制单音, 用于电话呼入的时候,耳麦里面能够听到声音,提醒有来电 mode 0 停止播放 1 开始播放 freq 播放单音频率 periodon 一个周期内播放单音的时长 periodoff 一个周期内静音的时长 duration 单音播放总时长,单位为毫秒 */ public static native int ubox_gsm_generate_tone(int uboxHnd, int mode, int freq, int periodon, int periodoff, int duration); //加载DLL static { System.out.println(System.getProperty("java.library.path")); String property = System.getProperty("user.dir"); System.out.println("property:"+property.replace("\\","/")+"/bin/"); // String path = PhonicNative.class.getResource("/").toString(); // path = path.substring(6).replaceAll("%20", " "); // String path =property.replace("\\","/")+"/bin/"; // System.out.println(path); String path = property + "\\bin\\"; System.out.println(path); try { // 包含 "64",即可64位 JDK , 否则 32位 System.out.println(System.getProperty("java.vm.name")); System.out.println(System.getProperty("os.arch")); System.out.println(System.getProperty("sun.arch.data.model")); if(Integer.parseInt(System.getProperty("sun.arch.data.model")) == 32) //32bit Java { System.out.println("load 32bit dll"); System.load(path + "x86/phonic_ubox.dll"); System.load(path + "x86/phonic_native.dll"); System.load(path + "x86/phonic_utool.dll"); System.load(path + "x86/phonic_utoolI.dll"); System.load(path + "x86/phonic_utoolII.dll"); System.load(path + "x86/phonic_utoolIIEx.dll"); } else { System.out.println("load 64bit dll"); // System.load( "E:/workspace/ubox-java/api/Demo/bin/x64/phonic_ubox.dll"); // System.load("E:/workspace/ubox-java/api/Demo/bin/x64/phonic_native.dll"); // System.load( "E:/workspace/ubox-java/api/Demo/bin/x64/phonic_utool.dll"); // System.load("E:/workspace/ubox-java/api/Demo/bin/x64/phonic_utoolI.dll"); // System.load( "E:/workspace/ubox-java/api/Demo/bin/x64/phonic_utooIIl.dll"); System.load(path + "x64\\phonic_ubox.dll"); System.load(path + "x64\\phonic_native.dll"); System.load(path + "x64\\phonic_utool.dll"); System.load(path + "x64\\phonic_utoolI.dll"); System.load(path + "x64\\phonic_utoolII.dll"); // System.loadLibrary(path + "phonic_ubox.dll"); // System.loadLibrary(path + "phonic_native.dll"); // System.loadLibrary(path + "phonic_utool.dll"); // System.loadLibrary(path + "phonic_utoolI.dll"); // System.loadLibrary(path + "phonic_utooIIl.dll"); } //System.load(path + "X86/phonic_ubox"); //System.load(path + "X86/phonic_native"); } catch (Exception e) { e.printStackTrace(); } } }