求c/c++代码转成java
源代码如下主要
#include <windows.h>
#include "shpa3api.h"
#define SNDLEN 3000l //单个发音在文件中所占的长度
#define ARRAY_SIZE(a) ( sizeof(a)/sizeof(a[0]) )
char tab_buf[16000]; //用于存放HZK.TAB
bool Loadhzk=false; //语音索引装载标志
int Delay=600;
char ErrMsg[200];
BOOL WINAPI DllMain(HMODULE hModule,DWORD fdwReason,LPVOID lpvReserved)
{
return 1;
}
DWORD WINAPI UnLoadHZK(void) //add by Yang 2006.12.19
{
int index;
for (index=0;index<=1295+36+2;index++)
{
if (SsmFreeIndexData(index)==-1)
{
SsmGetLastErrMsg(ErrMsg);
//return 0;
}
}
Loadhzk = false;
return 0;
}
DWORD WINAPI LoadHZK(void)
{
DWORD index;
long i;
int handle1=-1;
long size;
unsigned long ofs=0;
if(Loadhzk==true)
{
return 2;
}
Loadhzk=false;
// SsmSetMaxIdxSeg(2000);
//将字符语音装入前36个索引
for(index=1;index<=36;index++)
{
//0-9,a-z
// if(LoadIndexFile(index,"char.snd",(index-1)*SNDLEN,SNDLEN)==0)
if (SsmLoadIndexData(index, "", 7, "char.snd", (index-1)*SNDLEN,SNDLEN)==-1)
{
SsmGetLastErrMsg(ErrMsg);
return 0;
}
}
for(i=0;index<=1295+36;index++,i++)
{
//语音库中共有1295个汉字
// if(LoadIndexFile(index,"hzk.snd",i*SNDLEN,SNDLEN)==0)
if (SsmLoadIndexData(index, "", 7, "hzk.snd", i*SNDLEN,SNDLEN)==-1)
{
SsmGetLastErrMsg(ErrMsg);
return 0;
}
}
// if(Delay!=0) LoadIndexFile(index,"hzk.snd",0,Delay); //加载一段空白语音
if(Delay!=0) SsmLoadIndexData(index, "", 7, "hzk.snd", 0,Delay);
// LoadIndexFile(index+1,"hzk.snd",0,SNDLEN);
SsmLoadIndexData(index+1, "", 7, "hzk.snd", 0,SNDLEN);
memset(tab_buf,0x00,16000);
if((handle1 = _lopen("hzk.tab",OF_READ)) == -1)
{
return 0;
}
while(1)
{
size = _lread(handle1,tab_buf+ofs,8192);
ofs += size;
if(size < 8192)
break;
}
_lclose(handle1);
Loadhzk=true;
return 1;
}
int ischn(unsigned char ci)
{
if(ci>=0xa1&&ci<=0xfe)
return 1;
else
return 0;
}
DWORD WINAPI PlayText(DWORD Chsel,char *m_playstr)
{
int i;
unsigned long offset1;
unsigned int address,pp,pp1;
unsigned char p,p1;
char playstring[510*5];//每次最多可播放500段语音
char string[255];
int tmp=0;
if(Loadhzk!=true)
{
return 2;
}
memset(playstring,0x0,255*5);
if(strlen(m_playstr)>0xff)
{
return 0;
}
strcpy(string,m_playstr);
i=0;
while(1)
{
if(string[i]=='\0') break;
if(ischn(string[i]))
{
p=string[i];
p1=string[i+1];
if(p1=='\0') break;
offset1=((unsigned long)(p-(unsigned char)0xb0) * 94 +(unsigned long)(p1-(unsigned char)0xa0));
offset1=offset1*2; //求得该汉字在hzk.tab中的偏移量
pp=(unsigned char)tab_buf[offset1];
pp1=(unsigned char)tab_buf[offset1+1]<<8;//取得该汉字在语音库中索引号
address=pp1|pp;
address+=(36+1); //前36个为字符
i++;
tmp++;
}
else
{
if(string[i]>='0'&&string[i]<='9')
address=(unsigned int )(string[i]-'0'+1);
else if(string[i]>='A' && string[i]<='z')
{
string[i]=tolower(string[i]);
address=(unsigned int )(string[i]-'a'+1+10);
}
else address=1333; //加入延迟的段号
tmp++;
}
i++;
if(address>1333) continue;
if(strlen(playstring)==0)
{
wsprintf(playstring,"%d",address);
if(Delay!=0)
{
address=1332;
wsprintf(playstring,"%s,%d",playstring,address);
}
}
else
{
if(strlen(playstring) >= ARRAY_SIZE(playstring)-5 ) break;
wsprintf(playstring,"%s,%d",playstring,address);
if(Delay!=0)
{
address=1332;
wsprintf(playstring,"%s,%d",playstring,address);
}
}
}
// PlayIndex(Chsel,playstring);
// if (SsmPlayIndexString(Chsel, playstring)==-1) SsmGetLastErrMsg(ErrMsg);
SsmPlayIndexString(Chsel, playstring);
return 1;
}
void WINAPI SetTTSDelay(int delay)
{
if(delay>2500)
delay=2500;
if(delay<=0)
delay=0;
// FreeIndexMem(1332);
SsmFreeIndexData(1332);
Delay=delay;
if(Delay!=0)
// LoadIndexFile(1332,"hzk.snd",100,Delay);
SsmLoadIndexData(1332, "", 7, "hzk.snd", 100,Delay);
}
void WINAPI GetErrorMsg(char *buf)
{
strcpy(buf,ErrMsg);
return ;
}