网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Java语音识别简单代码,语音识别编程语言

在java怎么调用julius做语音识别啊?求接口代码

package com.cnblogs.htynkn;

嘉兴网站建设公司成都创新互联,嘉兴网站设计制作,有大型网站制作公司丰富经验。已为嘉兴成百上千提供企业网站建设服务。企业网站搭建\成都外贸网站制作要多少钱,请找那个售后服务好的嘉兴做网站的公司定做!

import com.sun.jna.Library;

import com.sun.jna.Native;

import com.sun.jna.Pointer;

import com.sun.jna.ptr.IntByReference;

public interface QTSR extends Library {

QTSR INSTANCE = (QTSR) Native.loadLibrary("msc", QTSR.class);

/**

* 初始化MSC的ISR部分

*

* @param configs

* 初始化时传入的字符串,以指定合成用到的一些配置参数,各个参数以“参数名=参数值”的形式出现,大小写不敏感,不同的参数之间以“

* ,”或“\n”隔开,不设置任何值时可以传入NULL或空串:

* @return 如果函数调用成功返回MSP_SUCCESS,否则返回错误代码,错误代码参见msp_errors

*/

public int QISRInit(String configs);

/**

* 开始一个ISR会话

*

* @param grammarList

* uri-list格式的语法,可以是一个语法文件的URL或者一个引擎内置语法列表。可以同时指定多个语法,不同的语法之间以“,”

* 隔开。进行语音听写时不需要语法,此参数设定为NULL或空串即可;进行语音识别时则需要语法,语法可以在此参数中指定,

* 也可以随后调用QISRGrammarActivate指定识别所用的语法。

* @param params

* 本路ISR会话使用的参数,可设置的参数及其取值范围请参考《可设置参数列表_MSP20.xls》,各个参数以“参数名=参数值”

* 的形式出现,不同的参数之间以“,”或者“\n”隔开。

* @param errorCode

* 如果函数调用成功则其值为MSP_SUCCESS,否则返回错误代码,错误代码参见msp_errors。几个主要的返回值:

* MSP_ERROR_NOT_INIT 未初始化 MSP_ERROR_INVALID_PARA 无效的参数

* MSP_ERROR_NO_LICENSE 开始一路会话失败

* @return MSC为本路会话建立的ID,用来唯一的标识本路会话,供以后调用其他函数时使用。函数调用失败则会返回NULL。

*/

public String QISRSessionBegin(String grammarList, String params,

IntByReference errorCode);

/**

* 传入语法

*

* @param sessionID

* 由QISRSessionBegin返回过来的会话ID。

* @param grammar

* 语法字符串

* @param type

* 语法类型,可以是uri-list、abnf、xml等

* @param weight

* 本次传入语法的权重,本参数在MSP 2.0中会被忽略。

* @return 如果函数调用成功返回MSP_SUCCESS,否则返回错误代码,错误代码参见msp_errors

*/

public int QISRGrammarActivate(String sessionID, String grammar,

String type, int weight);

/**

* 写入用来识别的语音

*

* @param sessionID

* 由QISRSessionBegin返回过来的会话ID。

* @param waveData

* 音频数据缓冲区起始地址

* @param waveLen

* 音频数据长度,其大小不能超过设定的max_audio_size

* @param audioStatus

* 用来指明用户本次识别的音频是否发送完毕,可能值如下:

* MSP_AUDIO_SAMPLE_FIRST = 1 第一块音频

* MSP_AUDIO_SAMPLE_CONTINUE = 2 还有后继音频

* MSP_AUDIO_SAMPLE_LAST = 4 最后一块音频

* @param epStatus

* 端点检测(End-point detected)器所处的状态,可能的值如下:

* MSP _EP_LOOKING_FOR_SPEECH = 0 还没有检测到音频的前端点。

* MSP _EP_IN_SPEECH = 1 已经检测到了音频前端点,正在进行正常的音频处理。

* MSP _EP_AFTER_SPEECH = 3 检测到音频的后端点,后继的音频会被MSC忽略。

* MSP _EP_TIMEOUT = 4 超时。

* MSP _EP_ERROR= 5 出现错误。

* MSP _EP_MAX_SPEECH = 6 音频过大。

* @param recogStatus

* 识别器所处的状态

* @return

*/

public int QISRAudioWrite(String sessionID, Pointer waveData, int waveLen,

int audioStatus, IntByReference epStatus, IntByReference recogStatus);

/**

* 获取识别结果

*

* @param sessionID 由QISRSessionBegin返回过来的会话ID。

* @param rsltStatus 识别结果的状态,其取值范围和含义请参考QISRAudioWrite的参数recogStatus

* @param waitTime 与服务器交互的间隔时间,可以控制和服务器的交互频度。单位为ms,建议取值为5000。

* @param errorCode 如果函数调用成功返回MSP_SUCCESS,否则返回错误代码,错误代码参见msp_errors

* @return 函数执行成功并且获取到识别结果时返回识别结果,函数执行成功没有获取到识别结果时返回NULL

*/

public String QISRGetResult(String sessionID, IntByReference rsltStatus,

int waitTime, IntByReference errorCode);

/**

* 结束一路会话

*

* @param sessionID 由QISRSessionBegin返回过来的会话ID。

* @param hints 结束本次会话的原因描述,用于记录日志,便于用户查阅或者跟踪某些问题。

* @return

*/

public int QISRSessionEnd(String sessionID, String hints);

/**

* 获取与识别交互相关的参数

*

* @param sessionID 由QISRSessionBegin返回过来的会话ID。

* @param paramName 要获取的参数名称;支持同时查询多个参数,查询多个参数时,参数名称按“,” 或“\n”分隔开来。

* @param paramValue 获取的参数值,以字符串形式返回;查询多个参数时,参数值之间以“;”分开,不支持的参数将返回空的值。

* @param valueLen 参数值的长度。

* @return

*/

public int QISRGetParam(String sessionID, String paramName,

String paramValue, IntByReference valueLen);

/**

* 逆初始化MSC的ISR部分

*

* @return

*/

public int QISRFini();

}

*Msp_errors

?

package com.cnblogs.htynkn;

import com.sun.jna.win32.StdCallLibrary;

public interface Msp_errors extends StdCallLibrary {

public static final int MSP_SUCCESS = 0;

public static final int ERROR_FAIL = -1;

public static final int ERROR_EXCEPTION= -2;

public static final int ERROR_GENERAL= 10100; /* 0x2774 */

public static final int ERROR_OUT_OF_MEMORY= 10101; /* 0x2775 */

public static final int ERROR_FILE_NOT_FOUND= 10102; /* 0x2776 */

public static final int ERROR_NOT_SUPPORT= 10103; /* 0x2777 */

public static final int ERROR_NOT_IMPLEMENT= 10104; /* 0x2778 */

public static final int ERROR_ACCESS= 10105; /* 0x2779 */

public static final int ERROR_INVALID_PARA= 10106; /* 0x277A */

public static final int ERROR_INVALID_PARA_VALUE= 10107; /* 0x277B */

public static final int ERROR_INVALID_HANDLE= 10108; /* 0x277C */

public static final int ERROR_INVALID_DATA= 10109; /* 0x277D */

public static final int ERROR_NO_LICENSE= 10110; /* 0x277E */

public static final int ERROR_NOT_INIT= 10111; /* 0x277F */

public static final int ERROR_NULL_HANDLE= 10112; /* 0x2780 */

public static final int ERROR_OVERFLOW= 10113; /* 0x2781 */

public static final int ERROR_TIME_OUT= 10114; /* 0x2782 */

public static final int ERROR_OPEN_FILE= 10115; /* 0x2783 */

public static final int ERROR_NOT_FOUND= 10116; /* 0x2784 */

public static final int ERROR_NO_ENOUGH_BUFFER= 10117; /* 0x2785 */

public static final int ERROR_NO_DATA= 10118; /* 0x2786 */

public static final int ERROR_NO_MORE_DATA= 10119; /* 0x2787 */

public static final int ERROR_NO_RESPONSE_DATA= 10120; /* 0x2788 */

public static final int ERROR_ALREADY_EXIST= 10121; /* 0x2789 */

public static final int ERROR_LOAD_MODULE= 10122; /* 0x278A */

public static final int ERROR_BUSY = 10123; /* 0x278B */

public static final int ERROR_INVALID_CONFIG= 10124; /* 0x278C */

public static final int ERROR_VERSION_CHECK= 10125; /* 0x278D */

public static final int ERROR_CANCELED= 10126; /* 0x278E */

public static final int ERROR_INVALID_MEDIA_TYPE= 10127; /* 0x278F */

public static final int ERROR_CONFIG_INITIALIZE= 10128; /* 0x2790 */

public static final int ERROR_CREATE_HANDLE= 10129; /* 0x2791 */

public static final int ERROR_CODING_LIB_NOT_LOAD= 10130; /* 0x2792 */

/* Error codes of network 10200(0x27D8)*/

public static final int ERROR_NET_GENERAL= 10200; /* 0x27D8 */

public static final int ERROR_NET_OPENSOCK= 10201; /* 0x27D9 */ /* Open socket */

public static final int ERROR_NET_CONNECTSOCK= 10202; /* 0x27DA */ /* Connect socket */

public static final int ERROR_NET_ACCEPTSOCK = 10203; /* 0x27DB */ /* Accept socket */

public static final int ERROR_NET_SENDSOCK= 10204; /* 0x27DC */ /* Send socket data */

public static final int ERROR_NET_RECVSOCK= 10205; /* 0x27DD */ /* Recv socket data */

public static final int ERROR_NET_INVALIDSOCK= 10206; /* 0x27DE */ /* Invalid socket handle */

public static final int ERROR_NET_BADADDRESS = 10207; /* 0x27EF */ /* Bad network address */

public static final int ERROR_NET_BINDSEQUENCE= 10208; /* 0x27E0 */ /* Bind after listen/connect */

public static final int ERROR_NET_NOTOPENSOCK= 10209; /* 0x27E1 */ /* Socket is not opened */

public static final int ERROR_NET_NOTBIND= 10210; /* 0x27E2 */ /* Socket is not bind to an address */

public static final int ERROR_NET_NOTLISTEN = 10211; /* 0x27E3 */ /* Socket is not listening */

public static final int ERROR_NET_CONNECTCLOSE= 10212; /* 0x27E4 */ /* The other side of connection is closed */

public static final int ERROR_NET_NOTDGRAMSOCK= 10213; /* 0x27E5 */ /* The socket is not datagram type */

public static final int ERROR_NET_DNS= 10214; /* 0x27E6 */ /* domain name is invalid or dns server does not function well */

/* Error codes of mssp message 10300(0x283C) */

public static final int ERROR_MSG_GENERAL= 10300; /* 0x283C */

public static final int ERROR_MSG_PARSE_ERROR= 10301; /* 0x283D */

public static final int ERROR_MSG_BUILD_ERROR= 10302; /* 0x283E */

public static final int ERROR_MSG_PARAM_ERROR= 10303; /* 0x283F */

public static final int ERROR_MSG_CONTENT_EMPTY= 10304; /* 0x2840 */

public static final int ERROR_MSG_INVALID_CONTENT_TYPE = 10305; /* 0x2841 */

public static final int ERROR_MSG_INVALID_CONTENT_LENGTH = 10306; /* 0x2842 */

public static final int ERROR_MSG_INVALID_CONTENT_ENCODE = 10307; /* 0x2843 */

public static final int ERROR_MSG_INVALID_KEY= 10308; /* 0x2844 */

public static final int ERROR_MSG_KEY_EMPTY= 10309; /* 0x2845 */

public static final int ERROR_MSG_SESSION_ID_EMPTY= 10310; /* 0x2846 */

public static final int ERROR_MSG_LOGIN_ID_EMPTY= 10311; /* 0x2847 */

public static final int ERROR_MSG_SYNC_ID_EMPTY= 10312; /* 0x2848 */

public static final int ERROR_MSG_APP_ID_EMPTY= 10313; /* 0x2849 */

public static final int ERROR_MSG_EXTERN_ID_EMPTY= 10314; /* 0x284A */

public static final int ERROR_MSG_INVALID_CMD= 10315; /* 0x284B */

public static final int ERROR_MSG_INVALID_SUBJECT= 10316; /* 0x284C */

public static final int ERROR_MSG_INVALID_VERSION= 10317; /* 0x284D */

public static final int ERROR_MSG_NO_CMD= 10318; /* 0x284E */

public static final int ERROR_MSG_NO_SUBJECT= 10319; /* 0x284F */

public static final int ERROR_MSG_NO_VERSION= 10320; /* 0x2850 */

public static final int ERROR_MSG_MSSP_EMPTY= 10321; /* 0x2851 */

public static final int ERROR_MSG_NEW_RESPONSE= 10322; /* 0x2852 */

public static final int ERROR_MSG_NEW_CONTENT= 10323; /* 0x2853 */

public static final int ERROR_MSG_INVALID_SESSION_ID = 10324; /* 0x2854 */

/* Error codes of DataBase 10400(0x28A0)*/

public static final int ERROR_DB_GENERAL= 10400; /* 0x28A0 */

public static final int ERROR_DB_EXCEPTION= 10401; /* 0x28A1 */

public static final int ERROR_DB_NO_RESULT= 10402; /* 0x28A2 */

public static final int ERROR_DB_INVALID_USER= 10403; /* 0x28A3 */

public static final int ERROR_DB_INVALID_PWD= 10404; /* 0x28A4 */

public static final int ERROR_DB_CONNECT= 10405; /* 0x28A5 */

public static final int ERROR_DB_INVALID_SQL= 10406; /* 0x28A6 */

public static final int ERROR_DB_INVALID_APPID= 10407; /* 0x28A7 */

/* Error codes of Resource 10500(0x2904)*/

public static final int ERROR_RES_GENERAL= 10500; /* 0x2904 */

public static final int ERROR_RES_LOAD = 10501; /* 0x2905 */ /* Load resource */

public static final int ERROR_RES_FREE = 10502; /* 0x2906 */ /* Free resource */

public static final int ERROR_RES_MISSING = 10503; /* 0x2907 */ /* Resource File Missing */

public static final int ERROR_RES_INVALID_NAME = 10504; /* 0x2908 */ /* Invalid resource file name */

public static final int ERROR_RES_INVALID_ID = 10505; /* 0x2909 */ /* Invalid resource ID */

public static final int ERROR_RES_INVALID_IMG = 10506; /* 0x290A */ /* Invalid resource image pointer */

public static final int ERROR_RES_WRITE= 10507; /* 0x290B */ /* Write read-only resource */

public static final int ERROR_RES_LEAK = 10508; /* 0x290C */ /* Resource leak out */

public static final int ERROR_RES_HEAD = 10509; /* 0x290D */ /* Resource head currupt */

public static final int ERROR_RES_DATA = 10510; /* 0x290E */ /* Resource data currupt */

public static final int ERROR_RES_SKIP = 10511; /* 0x290F */ /* Resource file skipped */

/* Error codes of TTS 10600(0x2968)*/

public static final int ERROR_TTS_GENERAL= 10600; /* 0x2968 */

public static final int ERROR_TTS_TEXTEND = 10601; /* 0x2969 */ /* Meet text end */

public static final int ERROR_TTS_TEXT_EMPTY= 10602; /* 0x296A */ /* no synth text */

/* Error codes of Recognizer 10700(0x29CC) */

public static final int ERROR_REC_GENERAL= 10700; /* 0x29CC */

public static final int ERROR_REC_INACTIVE= 10701; /* 0x29CD */

public static final int ERROR_REC_GRAMMAR_ERROR= 10702; /* 0x29CE */

public static final int ERROR_REC_NO_ACTIVE_GRAMMARS = 10703; /* 0x29CF */

public static final int ERROR_REC_DUPLICATE_GRAMMAR= 10704; /* 0x29D0 */

public static final int ERROR_REC_INVALID_MEDIA_TYPE = 10705; /* 0x29D1 */

public static final int ERROR_REC_INVALID_LANGUAGE= 10706; /* 0x29D2 */

public static final int ERROR_REC_URI_NOT_FOUND= 10707; /* 0x29D3 */

public static final int ERROR_REC_URI_TIMEOUT= 10708; /* 0x29D4 */

public static final int ERROR_REC_URI_FETCH_ERROR= 10709; /* 0x29D5 */

/* Error codes of Speech Detector 10800(0x2A30) */

public static final int ERROR_EP_GENERAL= 10800; /* 0x2A30 */

public static final int ERROR_EP_NO_SESSION_NAME= 10801; /* 0x2A31 */

public static final int ERROR_EP_INACTIVE = 10802; /* 0x2A32 */

public static final int ERROR_EP_INITIALIZED = 10803; /* 0x2A33 */

/* Error codes of TUV */

public static final int ERROR_TUV_GENERAL= 10900; /* 0x2A94 */

public static final int ERROR_TUV_GETHIDPARAM = 10901; /* 0x2A95 */ /* Get Busin Param huanid*/

public static final int ERROR_TUV_TOKEN= 10902; /* 0x2A96 */ /* Get Token */

public static final int ERROR_TUV_CFGFILE= 10903; /* 0x2A97 */ /* Open cfg file */

public static final int ERROR_TUV_RECV_CONTENT = 10904; /* 0x2A98 */ /* received content is error */

public static final int ERROR_TUV_VERFAIL = 10905; /* 0x2A99 */ /* Verify failure */

/* Error codes of IMTV */

public static final int ERROR_LOGIN_SUCCESS= 11000; /* 0x2AF8 */ /* 成功 */

public static final int ERROR_LOGIN_NO_LICENSE = 11001; /* 0x2AF9 */ /* 试用次数结束,用户需要付费 */

public static final int ERROR_LOGIN_SESSIONID_INVALID = 11002; /* 0x2AFA */ /* SessionId失效,需要重新登录通行证 */

public static final int ERROR_LOGIN_SESSIONID_ERROR= 11003; /* 0x2AFB */ /* SessionId为空,或者非法 */

public static final int ERROR_LOGIN_UNLOGIN = 11004; /* 0x2AFC */ /* 未登录通行证 */

public static final int ERROR_LOGIN_INVALID_USER = 11005; /* 0x2AFD */ /* 用户ID无效 */

public static final int ERROR_LOGIN_INVALID_PWD = 11006; /* 0x2AFE */ /* 用户密码无效 */

public static final int ERROR_LOGIN_SYSTEM_ERROR= 11099; /* 0x2B5B */ /* 系统错误 */

/* Error codes of HCR */

public static final int ERROR_HCR_GENERAL= 11100;

public static final int ERROR_HCR_RESOURCE_NOT_EXIST = 11101;

public static final int ERROR_HCR_CREATE= 11102;

public static final int ERROR_HCR_DESTROY= 11103;

public static final int ERROR_HCR_START= 11104;

public static final int ERROR_HCR_APPEND_STROKES= 11105;

public static final int ERROR_HCR_GET_RESULT= 11106;

public static final int ERROR_HCR_SET_PREDICT_DATA= 11107;

public static final int ERROR_HCR_GET_PREDICT_RESULT = 11108;

/* Error codes of http 12000(0x2EE0) */

public static final int ERROR_HTTP_BASE= 12000; /* 0x2EE0 */

/*Error codes of ISV */

public static final int ERROR_ISV_NO_USER = 13000; /* 32C8 */ /* the user doesn't exist */

/* Error codes of Lua scripts */

public static final int ERROR_LUA_BASE= 14000; /* 0x36B0 */

public static final int ERROR_LUA_YIELD= 14001; /* 0x36B1 */

public static final int ERROR_LUA_ERRRUN= 14002; /* 0x36B2 */

public static final int ERROR_LUA_ERRSYNTAX= 14003; /* 0x36B3 */

public static final int ERROR_LUA_ERRMEM= 14004; /* 0x36B4 */

public static final int ERROR_LUA_ERRERR= 14005; /* 0x36B5 */

之前java的语音识别是调用讯飞的dll文件,但怎么在此基础上编写一个离线的语音识别,求方法

一般那种c#的dll是java不能直接调用的,但C\C++可以,你可以使用JNI。比如你要一个 public native void sengMsg(String msg); 来发送信息,先用native关键字声明这个函数,然后再类里面加一个静态块:

static { System.loadLibrary("msg"); } 这里的msg是你的后来编译的dll文件名,不是短信猫带的。 然后写其他的函数就可以调用这个方法了,写完后用javac编译,得到class文件,然后用 javah -jni 你的class文件 就会得到一个.h的头文件,用visual studio新建一个dll,把那个.h文件包含进去,用C\C++调用你现有的dll,然后编译得到你的msg.dll,把它复制到你的class文件目录,然后就可以调试运行了。

求助语音识别代码的注释,要每一句都写明意思,谢谢

这个是完整的代码,我自己的账号发不了这么长,希望好心人帮忙注释啊,非常感谢!!!

(1)端点检测部分(vad):

function [x1,x2] = vad(x)

%语音信号x幅度归一化到[-1,1]

x = double(x);

x = x / max(abs(x));

%常数设置

FrameLen = 240; %帧长度为240

FrameInc = 80; %帧移为80

amp1 = 10; %短时能量高门限10

amp2 = 2; %短时能量低门限为2

zcr1 = 10; %短时过零率高门限为10

zcr2 = 5; %短时过零率低门限为5

maxsilence =3;%静音时间门限3*10ms= 30ms

minlen= 15;%最小语音时间长度15*10ms = 150ms

status= 0; %

count= 0; %语音时间累计

silence = 0; %静音时间累计

%计算过零率

tmp1= enframe(x(1:end-1), FrameLen, FrameInc);

tmp2= enframe(x(2:end), FrameLen, FrameInc);

signs =(tmp1.*tmp2)0;%符号数组,用于存储相邻两个采样点符号是否相同,即是否穿越0电平

diffs = (tmp1-tmp2)0.02;%度量相邻两个采样点之间距离,如果大于门限0.02(经验值),则1,否则0

zcr = sum(signs.*diffs,2);%过零率

%计算短时能量

amp =sum(abs(enframe(filter([1 -0.9375], 1, x), FrameLen, FrameInc)), 2);

%调整能量门限

amp1 = min(amp1,max(amp)/4);

amp2 = min(amp2,max(amp)/8);

%开始端点检测

x1 = 0;

x2 = 0;

for n=1:length(zcr)

goto = 0;

switch status

case {0,1}% 0 =静音, 1 =可能开始

if amp(n) amp1%确信进入语音段

x1 = max(n-count-1,1);

status= 2;

silence = 0;

count= count + 1;

elseif amp(n) amp2 || ... %可能处于语音段

zcr(n) zcr2

status = 1;

count= count + 1;

else%静音状态

status= 0;

count= 0;

end

case 2,% 2 =语音段

if amp(n) amp2 || ...%保持在语音段

zcr(n) zcr2

count = count + 1;

else%语音将结束

silence = silence+1;

if silence maxsilence %静音还不够长,尚未结束

count= count + 1;

elseif count minlen%语音长度太短,认为是噪声

status= 0;

silence = 0;

count= 0;

else%语音结束

status= 3;

end

end

case 3,

break;

end

end

count = count-silence/2;

x2 = x1 + count -1;

subplot(311)

plot(x)

axis([1 length(x) -1 1])

xlabel('语音信号');

line([x1*FrameIncx1*FrameInc ],[-1,1],'Color','red');

line([x2*FrameIncx2*FrameInc ],[-1,1],'Color','red');

subplot(312)

plot(amp);

axis([1 length(amp) 0max(amp)])

xlabel('短时能量');

line([x1,x1],[min(amp),max(amp)],'Color','red');

line([x2,x2],[min(amp),max(amp)],'Color','red');

subplot(313)

plot(zcr);

axis([1 length(zcr) 0max(zcr)])

xlabel('过零率');

line([x1,x1],[min(zcr),max(zcr)],'Color','red');

line([x2,x2],[min(zcr),max(zcr)],'Color','red');

(2)MFCC部分:

function ccc = mfcc(x)

%归一化mel滤波器组系数

bank=melbankm(24,256,8000,0,0.5,'m');%24滤波器个数,8000采样频率

bank=full(bank);

bank=bank/max(bank(:));

% DCT系数,12*24

for k=1:12

n=0:23;

dctcoef(k,:)=cos((2*n+1)*k*pi/(2*24));

end

%归一化倒谱提升窗口

w = 1 + 6 * sin(pi *(1:12) ./ 12);

w = w/max(w);

%预加重滤波器

xx=double(x);

xx=filter([1-0.9375],1,xx);

%语音信号分帧,xx是输入语音信号;256是帧长;80是帧移

xx=enframe(xx,256,80);

%计算每帧的MFCC参数

for i=1:size(xx,1)

y = xx(i,:);

s = y' .* hamming(256);%加汉明窗

t = abs(fft(s));%fft变换

t = t.^2;

c1=dctcoef * log(bank * t(1:129));

c2 = c1.*w';

m(i,:)=c2';

end

%差分系数

dtm = zeros(size(m));

for i=3:size(m,1)-2

dtm(i,:) = -2*m(i-2,:) - m(i-1,:) + m(i+1,:)+ 2*m(i+2,:);

end

dtm = dtm / 3;

%合并mfcc参数和一阶差分mfcc参数

ccc = [m dtm];

%去除首尾两帧,因为这两帧的一阶差分参数为0

ccc =ccc(3:size(m,1)-2,:);

(3)dtw计算部分:

function dist = dtw2(test, ref)

global x y_min y_max

global t r

global D d

global m n

t = test;

r = ref;

n = size(t,1);

m = size(r,1);

d = zeros(m,1);

D =ones(m,1) *realmax;

D(1) = 0;

%如果两个模板长度相差过多,匹配失败

if (2*m-n3) || (2*n-m2)

dist =realmax;

return

end

%计算匹配区域

xa = round((2*m-n)/3);

xb = round((2*n-m)*2/3);

if xbxa

%xbxa,按下面三个区域匹配

%1:xa

%xa+1:xb

%xb+1:N

for x =1:xa

y_max= 2*x;

y_min= round(0.5*x);

warp

end

for x =(xa+1):xb

y_max= round(0.5*(x-n)+m);

y_min= round(0.5*x);

warp

end

for x =(xb+1):n

y_max= round(0.5*(x-n)+m);

y_min= round(2*(x-n)+m);

warp

end

elseif xaxb

%xaxb,按下面三个区域匹配

%0:xb

%xb+1:xa

%xa+1:N

for x =1:xb

y_max= 2*x;

y_min= round(0.5*x);

warp

end

for x =(xb+1):xa

y_max= 2*x;

y_min= round(2*(x-n)+m);

warp

end

for x =(xa+1):n

y_max= round(0.5*(x-n)+m);

y_min= round(2*(x-n)+m);

warp

end

elseif xa==xb

%xa=xb,按下面两个区域匹配

%0:xa

%xa+1:N

for x =1:xa

y_max= 2*x;

y_min= round(0.5*x);

warp

end

for x =(xa+1):n

y_max= round(0.5*(x-n)+m);

y_min= round(2*(x-n)+m);

warp

end

end

%返回匹配分数

dist = D(m);

function warp

global x y_min y_max

global t r

global D d

global m n

d = D;

for y = y_min:y_max

D1 = D(y);

if y1

D2= D(y-1);

else

D2 =realmax;

end

if y2

D3= D(y-2);

else

D3 = realmax;

end

d(y) =sum((t(x,:)-r(y,:)).^2) + min([D1,D2,D3]);

end

D = d;

(4)测试函数testdtw部分;

disp('正在计算参考模板的参数...')

for i=1:10

fname = sprintf('G:\\石东东\\语音\\%da.wav',i-1);

x = wavread(fname);

[x1 x2] = vad(x);

m = mfcc(x);

m = m(x1-2:x2-2,:);

ref(i).mfcc = m;

end

disp('正在计算测试模板的参数...')

for i=1:10

fname = sprintf('G:\\石东东\\语音\\%db.wav',i-1);

x = wavread(fname);

[x1 x2] = vad(x);

m = mfcc(x);

m = m(x1-2:x2-2,:);

test(i).mfcc = m;

end

disp('正在进行模板匹配...')

dist = zeros(10,10);

for i=1:10

for j=1:10

dist(i,j) = dtw2(test(i).mfcc, ref(j).mfcc);

end

end

disp('正在计算匹配结果...')

for i=1:10

[d,j] = min(dist(i,:));

fprintf('测试模板%d的识别结果为:%d\n', i-1, j-1);

end

opencv3在安卓中基于Java语言识别颜色(只需要识别红色或者蓝色)的代码您知道吗或者有资料吗?

和C++ CLR类似,我们使用标准的C++语言来实现同样的功能。注意到rand()这个函数是C++标准库里的内容,所以我们在文件开头增加了对stdlib.h这个头文件的引用。

这里需要注意的一点是:所有希望使用DllImport引入C#的C++方法都应该在方法声明中增加__declspec(dllexport)关键字,除非它在.def文件中对这些方法进行显示声明。

java可以实现语音识别吗

这个是可以实现的。

注:test.pcm是语音文件,可以用audacity软件打开,选择 文件-导入-裸数据。 设置采样率为8000Hz。点击播放就能听见声音了。

这个时候程序跑起来还有问题,需要将apiKey 以及secretKey填写上。这两个值是你申请应用对应的分配好的。

cuid填本机mac地址就可以了,这个值我试过好像无所谓没啥要求。

程序能跑起来,并且按照正常返回识别的语音结果。但是返回结果的编码为GBK,所以汉字显示为乱码,需要对其进行一次转码。转码的代码是我自己加上去的

怎样用java做语音识别

这块国内一般都用科大讯飞的语音云来做语音识别。不过那个接口是c/c++的,用JAVA来调用的话要通过java调用dll的技术,类似于 jni 或者 jna 都可以


名称栏目:Java语音识别简单代码,语音识别编程语言
链接地址:http://bjjierui.cn/article/hsceii.html

其他资讯