📄 tts_en.cpp
字号:
/****************************
void TextToSpeech(char* pText, char *pSpeech, int iType , int iFlag)
说明
1将文本转换成以的英文单词字符串,每一个单词跟一个","
2入口参数: pText 指向文本串
pSpeech 指向英文单词串
iType = 0 将文本当成数字
1 将文本当成日期
2 将文本当成时间
3 将文本当成电话号码
iFlag 阅读方式
iType = 0 时,iFlag =0 ,逐位读出;
=1,常规读出,百位后加and,如102345,one huandred and two thousand three huandred and fourty_five
=2, 常规读出,百位后不加and,如102345,one huandred two thousand three huandred fourty_five
iType = 1 时,
iFlag bit0:
0 US english MM-DD-YYYY ,
1 British DD-MM-YYYY
bit1
0 Day read as cardinal number
1 Day read as ordinal number
bit2
0 read the year
1 don't read the year
iType = 2 时
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
3返回值:无
4说明本程序对文本合法性不作检测
认为文本是下列:数字: [-]有效数字串[.数字串]
日期: YYYYMMDD
时间: HHMMSS
电话号码: 数字,'-'串
****************************/
// can be canceled
#include "afx.h"
#include "windows.h"
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include "tts_en.h"
typedef struct
{
int iIndex;
char pName[30];
} sPair;
sPair ThePairs[200]={
{0,"zero"},
{1,"one"},
{2,"two"},
{3,"three"},
{4,"four"},
{5,"five"},
{6,"six"},
{7,"seven"},
{8,"eight"},
{9,"nine" },
{10,"ten"},
{11,"eleven"},
{12,"twelve"},
{13,"thirteen"},
{14,"fourteen"},
{15,"fifteen"},
{16,"sixteen"},
{17,"seventeen"},
{18,"eighteen"},
{19,"nineteen"},
{20,"twenty"},
{21,"twenty_one"},
{22,"twenty_two"},
{23,"twenty_three"},
{24,"twenty_four"},
{25,"twenty_five"},
{26,"twenty_six"},
{27,"twenty_seven"},
{28,"twenty_eight"},
{29,"twenty_nine"},
{30,"thirty"},
{31,"thirty_one"},
{32,"thirty_two"},
{33,"thirty_three"},
{34,"thirty_four"},
{35,"thirty_five"},
{36,"thirty_six"},
{37,"thirty_seven"},
{38,"thirty_eight"},
{39,"thirty_nine"},
{40,"forty"},
{41,"forty_one"},
{42,"forty_two"},
{43,"forty_three"},
{44,"forty_four"},
{45,"forty_five"},
{46,"forty_six"},
{47,"forty_seven"},
{48,"forty_eight"},
{49,"forty_nine"},
{50,"fifty"},
{51,"fifty_one"},
{52,"fifty_two"},
{53,"fifty_three"},
{54,"fifty_four"},
{55,"fifty_five"},
{56,"fifty_six"},
{57,"fifty_seven"},
{58,"fifty_eight"},
{59,"fifty_nine"},
{60,"sixty"},
{61,"sixty_one"},
{62,"sixty_two"},
{63,"sixty_three"},
{64,"sixty_four"},
{65,"sixty_five"},
{66,"sixty_six"},
{67,"sixty_seven"},
{68,"sixty_eight"},
{69,"sixty_nine"},
{70,"seventy"},
{71,"seventy_one"},
{72,"seventy_two"},
{73,"seventy_three"},
{74,"seventy_four"},
{75,"seventy_five"},
{76,"seventy_six"},
{77,"seventy_seven"},
{78,"seventy_eight"},
{79,"seventy_nine"},
{80,"eighty"},
{81,"eighty_one"},
{82,"eighty_two"},
{83,"eighty_three"},
{84,"eighty_four"},
{85,"eighty_five"},
{86,"eighty_six"},
{87,"eighty_seven"},
{88,"eighty_eight"},
{89,"eighty_nine"},
{90,"ninety"},
{91,"ninety_one"},
{92,"ninety_two"},
{93,"ninety_three"},
{94,"ninety_four"},
{95,"ninety_five"},
{96,"ninety_six"},
{97,"ninety_seven"},
{98,"ninety_eight"},
{99,"ninety_nine"},
{100,"hundred"},
{101,"thousand"},
{102,"million"},
{103,"billion"},
{104,"trillion"},
{105,"quadrillion"},
{106,"point"},
{107,"and"},
{108,"negative"},
{109,"double"},
{110,"nought"},
{111,"january"},
{112,"february"},
{113,"march"},
{114,"april"},
{115,"may"},
{116,"june"},
{117,"july"},
{118,"august"},
{119,"september"},
{120,"october"},
{121,"november"},
{122,"december"},
{123,"o\'clock"},
{124,"hour"},
{125,"minute"},
{126,"second"},
{127,"past"},
{128,"to"},
{129,"quarter"},
{130,"half"},
{131,"first"},
{132,"second"},
{133,"third"},
{134,"fourth"},
{135,"fifth"},
{136,"sixth"},
{137,"seventh"},
{138,"eighth"},
{139,"ninth"},
{140,"tenth"},
{141,"eleventh"},
{142,"twelfth"},
{143,"thirteenth"},
{144,"fourteenth"},
{145,"fifteenth"},
{146,"sixteenth"},
{147,"seventeenth"},
{148,"eighteenth"},
{149,"nineteenth"},
{150,"twentieth"},
{151,"twenty_first"},
{152,"twenty_second"},
{153,"twenty_third"},
{154,"twenty_fourth"},
{155,"twenty_fifth"},
{156,"twenty_sixth"},
{157,"twenty_seventh"},
{158,"twenty_eighth"},
{159,"twenty_nineth"},
{160,"thirtieth"},
{161,"thirty-first"},
{162,"o"},
{163,"silence"}
};
void TextToSpeech(char* pText, char *pSpeech, int iType , int iFlag)
{
strcpy(pSpeech,"");
switch (iType)
{
case 0 :
//deal with numbers
NumberToSpeech ( pText,pSpeech,iFlag );
return;
case 1 :
//deal with date
DateToSpeech(pText,pSpeech,iFlag);
return ;
case 2 :
//deal with time
TimeToSpeech(pText,pSpeech,iFlag);
return ;
case 3 :
//deal with telnum
TelnumToSpeech(pText,pSpeech,iFlag);
return ;
}
}
//***********************************************************
/***************************************************************
pxm add 首先进行格式格式化: 将"*"变成"."
按数值读时,将首位的0去掉(不包括小数点前的0)
将首位为小数点的前面补0
由于将前面补0会导致重新分配内存,故改变函数声明来使改变最小
***************************************************************/
//void NumberToSpeech ( char* pText,char *pSpeech,int iFlag )
void NumberToSpeech ( char* pText2,char *pSpeech,int iFlag )
{
pSpeech[0] = 0;
if(pText2 == NULL)
{
return;
}
char pText[1000];
//将首位位小数点的前面补0
if(pText2[0] == '.')
{
strcpy(pText, "0");
strcat(pText, pText2);
}
else
strcpy(pText, pText2);
char *pText_Temp;
//去掉首位的0
if(iFlag != 0)
{
pText_Temp = pText;
if(pText_Temp[0] == '-')
pText_Temp ++;
while(1)
{
if(pText_Temp[0] != '0')
break;
if(strlen(pText_Temp) > 1)
{
if(pText_Temp[0] == '0' && pText_Temp[1] == '.')
break;
}
pText_Temp ++;
}
if(pText[0] == '-')
strcpy(pText + 1, pText_Temp);
else
strcpy(pText, pText_Temp);
}
//将"*"替换成"."
pText_Temp = pText;
while(1)
{
pText_Temp = strchr(pText_Temp, '*');
if(pText_Temp != NULL)
{
pText_Temp[0] = '.';
pText_Temp ++;
}
else
break;
}
//**************************************************************
//pText must point to a string ended with Null
char* pIndex , *pTemp ;
char cc , cTemp[4],pInt[200],pDec[200];
int iGrade,iLen,iCount,iHundred,iTemp,iIndex;
bool bInt = TRUE ;
bool bAnd = FALSE,bSign=FALSE;
/*pxm remark
strcpy(cTemp,"");*/
memset(cTemp, 0, sizeof(cTemp)); //pxm add
strcpy(pInt,"");
strcpy(pDec,"");
pTemp = pInt;
pIndex = pText ;
do
{ cc = *pIndex;
switch (cc)
{case '-':
bSign = TRUE ;
strcat(pSpeech,ThePairs[108].pName);
strcat(pSpeech,",");
break ;
case '.':
{strcat(pSpeech,ThePairs[106].pName);
strcat(pSpeech,",");}
bInt = FALSE ;
*pTemp ='\0';
pTemp =pDec ;
break;
default:
{strcat(pSpeech,ThePairs[(int)cc-48].pName);
strcat(pSpeech,",");}
*pTemp=cc;
pTemp ++;
}
pIndex ++;
}while (*pIndex!=NULL) ;
*pTemp = '\0';
//dealwith integer
iIndex = 0;
iLen = (int)strlen(pInt);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -