⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tts_en.cpp

📁 基于dialogic语音卡的IVR系统源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	if (iFlag==0||iLen>18)
		return;
	else
	{strcpy(pSpeech,"");
	if (bSign)
	{strcat(pSpeech,ThePairs[108].pName);
	strcat(pSpeech,",");}}

	//Modified at 2000/12/08 by xyw
	//if (iLen ==0 ) return ;
	//Modified end

	iGrade = (int)((iLen-1)/3);
	pTemp = pInt ;
	strcpy(cTemp,"");
//
	for (iCount=0;iCount<(iLen - (int)((iLen-1)/3)*3);iCount++)
	{  
	cTemp[iCount] = *pTemp ;
	pTemp ++;
	}

	iHundred = (int) (atoi(cTemp)/100);
	iTemp = (int) (atoi(cTemp)%100);
	if (iHundred != 0 )
	{
		strcat(pSpeech,ThePairs[iHundred].pName);			
		strcat(pSpeech,",hundred,");
		if (iTemp!=0)
		{//pxm add this bracket
			if (iFlag ==1 )
			{strcat(pSpeech,"and,");}			
			strcat(pSpeech,ThePairs[iTemp].pName);			
			strcat(pSpeech,",");
		}//pxm add this bracket
	}
	else
	{strcat(pSpeech,ThePairs[iTemp].pName);			
	strcat(pSpeech,",");
	}
	
	 if (iGrade >0&&iGrade<=5 )
	 {strcat(pSpeech,ThePairs[iGrade+100].pName);			
	strcat(pSpeech,",");}
	
	  iGrade --;

	strcpy(cTemp,"");
    iCount = 0 ;
  while (iGrade>=0)
  { 
	cTemp[iCount] = *pTemp ;
	iCount ++;
	pTemp ++;
	if (iCount ==3 )
	{		
		iCount = 0 ;
		iHundred = (int) (atoi(cTemp)/100);
		iTemp = (int) (atoi(cTemp)%100);
		if (iHundred != 0) 
		{				
			strcat(pSpeech,ThePairs[iHundred].pName);			
			strcat(pSpeech,",hundred,");
			if ( iTemp != 0 )
			{if(iFlag==1) strcat(pSpeech,"and,");
			strcat(pSpeech,ThePairs[iTemp].pName);			
			strcat(pSpeech,",");}
		}
		else
		{if (iTemp!=0)
			{if(iFlag==1)	strcat(pSpeech,"and,");
			strcat(pSpeech,ThePairs[iTemp].pName);			
			strcat(pSpeech,",");}		
		}

		if (iGrade >0&&iGrade<=5&&atoi(cTemp)!=0)
			{strcat(pSpeech,ThePairs[iGrade+100].pName);			
			strcat(pSpeech,",");}
		iGrade --;
		strcpy(cTemp,"");
		iCount = 0 ;
	}
 }	

/*
	if (bAnd&&strlen(pSpeech)>4)
	{pIndex = pSpeech +strlen(pSpeech)-1;
	for (iIndex=0;iIndex<4;iIndex++) 
	{*pIndex='\0';
	pIndex--;
	bAnd = FALSE;}
	}
*/

  //deal with decimal

	if (strlen(pDec)>0)
		{strcat(pSpeech,ThePairs[106].pName);			
		strcat(pSpeech,",");}
  
	pTemp = pDec;
	while (*pTemp!=NULL)
	{
		if (*pTemp=='0')
		{
			strcat(pSpeech,ThePairs[162].pName);			
			strcat(pSpeech,",");
		}
		else
		{
			strcat(pSpeech,ThePairs[(int)*pTemp-48].pName);			
			strcat(pSpeech,",");
		}
		pTemp++;
	}
}



void DateToSpeech( char* pText,char *pSpeech,int iFlag )
{
//input text format :YYYYMMDD
//iFlag 0:US english MM-DD-YYYY ,Day read as cardinal number 
//		1:British DD-MM-YYYY,Day read as cardinal number 
//		2:US english MM-DD-YYYY ,Day read as ordinal number
//		3:British DD-MM-YYYY,Day read as ordinal number
char cYear[5]="",cMonth[3]="",cDay[3]="";
int iIndex ;

strcpy(pSpeech,"");
for (iIndex=0 ; iIndex<4;iIndex++) cYear[iIndex]=*(pText+iIndex); 
for (iIndex=0 ; iIndex<2;iIndex++) cMonth[iIndex]=*(pText+iIndex+4);
for (iIndex=0 ; iIndex<2;iIndex++) cDay[iIndex]=*(pText+iIndex+6);

if (iFlag%2==0)
//us
{
	strcat (pSpeech, ThePairs[atoi(cMonth)+110].pName);
	strcat (pSpeech, ",");
	if ((iFlag/2)%2==0)
	{strcat (pSpeech, ThePairs[atoi(cDay)].pName);
	strcat (pSpeech, ",");}
	else
	{strcat (pSpeech, ThePairs[atoi(cDay)+130].pName);
	strcat (pSpeech, ",");}
}
else
//British
{	if ((iFlag/2)%2==0)
	{strcat (pSpeech, ThePairs[atoi(cDay)].pName);
	strcat (pSpeech, ",");}
	else
	{
	strcat (pSpeech, "the");
	strcat (pSpeech, ",");
	strcat (pSpeech, ThePairs[atoi(cDay)+130].pName);
	strcat (pSpeech, ",");
	strcat (pSpeech, "of");
	strcat (pSpeech, ",");
	strcat (pSpeech, ThePairs[atoi(cMonth)+110].pName);
	strcat (pSpeech, ",");}
}

if ((iFlag/4)%2==0)
{if (atoi(cYear)%1000==0)
	{ 
		strcat (pSpeech, ThePairs[atoi(cYear)/1000].pName);
		strcat (pSpeech, ",");
		strcat (pSpeech, ThePairs[101].pName);
		strcat (pSpeech, ",");
	} 
else if( atoi(cYear)%100==0)
	{
		strcat (pSpeech, ThePairs[atoi(cYear)/100].pName);
		strcat (pSpeech, ",");
		strcat (pSpeech, ThePairs[100].pName);
		strcat (pSpeech, ",");
	}
else
	{
	if ((atoi(cYear)/100)%10==0&&(atoi(cYear)/100)!=0)
		{strcat (pSpeech, ThePairs[(atoi(cYear)/100)/10].pName);
		strcat (pSpeech, ",");
		strcat (pSpeech, ThePairs[101].pName);
		strcat (pSpeech, ",");}
	else
		{strcat (pSpeech, ThePairs[atoi(cYear)/100].pName);
		strcat (pSpeech, ",");}
	if (atoi(cYear)%100<10) {
		strcat (pSpeech, "o");
		strcat (pSpeech, ",");}
		strcat (pSpeech, ThePairs[atoi(cYear)%100].pName);
		strcat (pSpeech, ",");
	}
}

}


void TimeToSpeech( char* pText,char *pSpeech,int iFlag )
/*
//Text must be as "HHMMSS"
//iFlag bit0 
//0 not read "second "
//1 read "second" 

//iFlag bit1
//0 12:30:05 as twelve thirty o five
//1  thirty 0 five past twelve , thirty past twelve, half past twelve
*/


{
char cHour[3]="",cMinute[3]="",cSecond[3]="";
int iIndex ;

strcpy(pSpeech,"");
for (iIndex=0 ; iIndex<2;iIndex++) cHour[iIndex]=*(pText+iIndex); 
for (iIndex=0 ; iIndex<2;iIndex++) cMinute[iIndex]=*(pText+iIndex+2);
for (iIndex=0 ; iIndex<2;iIndex++) cSecond[iIndex]=*(pText+iIndex+4);

if (atoi(cSecond)==0 && iFlag%2!=0) iFlag --;

switch (iFlag)
{
case 0:
// 12:11:05 as twelve eleven
	strcat (pSpeech, ThePairs[atoi(cHour)].pName);
	strcat (pSpeech, ",");
	if (atoi(cMinute)==0)
		{strcat (pSpeech, "o\'clock,");}
	else 
	{if	(atoi(cMinute)<10)	strcat (pSpeech, "o,");
		strcat (pSpeech, ThePairs[atoi(cMinute)].pName);
		strcat (pSpeech, ",");
	}
	break;
case 1:
//12:11:05 as twelve eleven o five
	strcat (pSpeech, ThePairs[atoi(cHour)].pName);
	strcat (pSpeech, ",");
	if (atoi(cSecond)==0)
	{	if (atoi(cMinute)==0)
			{strcat (pSpeech, "o\'clock,");}
		else if	(atoi(cMinute)<10)
			{strcat (pSpeech, "o,");
			strcat (pSpeech, ThePairs[atoi(cMinute)].pName);
			strcat (pSpeech, ",");}
		else 
			{strcat (pSpeech, ThePairs[atoi(cMinute)].pName);
			strcat (pSpeech, ",");}
	}
	else 
	{	if	(atoi(cMinute)<10)
			{
			strcat (pSpeech, ThePairs[atoi(cMinute)].pName);
			strcat (pSpeech, ",");}
		else 
			{strcat (pSpeech, ThePairs[atoi(cMinute)].pName);
			strcat (pSpeech, ",");}
			
		if	(atoi(cSecond)<10)
			{strcat (pSpeech, "o,");
			strcat (pSpeech, ThePairs[atoi(cSecond)].pName);
			strcat (pSpeech, ",");}
		else 
			{strcat (pSpeech, ThePairs[atoi(cSecond)].pName);
			strcat (pSpeech, ",");}
			}

	break ;
case 2:
//12:11:05 as eleven past twelve
	switch (atoi(cMinute))
	{
	case 15:
		strcat (pSpeech,"quarter,past,");
		strcat (pSpeech, ThePairs[atoi(cHour)].pName);
		strcat (pSpeech, ",");
		break ;
	case 30:
		strcat (pSpeech,"half,past,");
		strcat (pSpeech, ThePairs[atoi(cHour)].pName);
		strcat (pSpeech, ",");
		break ;
	case 0:
		strcat (pSpeech, ThePairs[atoi(cHour)].pName);
		strcat (pSpeech, ",");
		break ;
	default : 
		if (atoi(cMinute)>= 50)
		{
			strcat (pSpeech, ThePairs[60-atoi(cMinute)].pName);
			strcat (pSpeech, ",to,");
			strcat (pSpeech, ThePairs[(atoi(cHour)+1)>23?atoi(cHour)-23:atoi(cHour)+1].pName);
			strcat (pSpeech, ",");			
		}
		else
		{
			strcat (pSpeech, ThePairs[atoi(cMinute)].pName);
			strcat (pSpeech, ",past,");
			strcat (pSpeech, ThePairs[atoi(cHour)].pName);
			strcat (pSpeech, ",");			
		}
	}
	break;
case 3:
//12:11:05 as eleven o five past twelve
	strcat (pSpeech, ThePairs[atoi(cMinute)].pName);
	strcat (pSpeech, ",");

	if	(atoi(cSecond)<10)
		{strcat (pSpeech, "o,");
		strcat (pSpeech, ThePairs[atoi(cSecond)].pName);
		strcat (pSpeech, ",");}
	else 
		{strcat (pSpeech, ThePairs[atoi(cSecond)].pName);
		strcat (pSpeech, ",");}
	
	strcat (pSpeech, "past,");
	strcat (pSpeech, ThePairs[atoi(cHour)].pName);
	strcat (pSpeech, ",");			
}

}


void TelnumToSpeech( char* pText,char *pSpeech,int iFlag )
{
	char cc ;
	char * pIndex ;
	int iCount ;
	pIndex = pText ;
	do 
	{ cc = *pIndex;
		switch  (cc)  	
		{case '-':
			strcat(pSpeech,"silence,");
			break ;
		case '0':	
			iCount = 1 ;
			while (*(pIndex+iCount) == cc) iCount++;
			if (iCount ==2||iCount>3)
			{strcat(pSpeech,"double,");
			pIndex++;}
			else if (iCount ==3)
			{strcat(pSpeech,"triple,");
			pIndex=pIndex+2;}

			strcat(pSpeech,"o,");
			break;
		default:
			iCount = 1 ;
			while (*(pIndex+iCount) == cc) iCount++;
			if (iCount ==2||iCount>3)
			{strcat(pSpeech,"double,");
			pIndex++;}
			else if (iCount ==3)
			{strcat(pSpeech,"triple,");
			pIndex=pIndex+2;}
			strcat(pSpeech,ThePairs[(int)cc-48].pName);			
			strcat(pSpeech,",");
		}
		pIndex ++;
	}while (*pIndex!=NULL) ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -