C 언어 는 음성 낭독 기능 을 간단하게 실현 한다.

#include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    void selectbuf(unsigned char *buf)
    {
        //printf(">>%s<<
",buf);         unsigned char *p;        for(p=buf;*p!=NULL;)       {                  if((*p-'0'>=0&&*p-'9'<=0)||(*p-'a'>=0&&*p-'z'<=0) ||(*p-'A'>=0&&*p-'Z'<=0) )         {           p++;           continue;          }           else if(*p>=0xb0&&*p<=0xf7&&*(p+1)>=0xa1&&*(p+1)<=0xfe)          {            p+=2;                        continue;          }          else if((*p>='!'&&*p<='/')||(*p>=':'&&*p<='@'))          {                       *p =' ';              p++;               }          else           {            *p=' ';           p++;           *p=' ';           p++;          }                 }     //  printf("
[%s] 
",buf);          }     int main(int argc,char *argv[])     {       system("title  ");       system("mode con cols=80 lines=30") ;       system("color f0");       FILE *fp,*fq;       char buffer[1000],*del;       unsigned char buf[1000];       fp = fopen(argv[1],"r");         if(fp!=NULL)         {           while(fgets(buffer,999,fp)!=NULL)           {                         printf("
:%s",buffer);                while((del=strchr(buffer,' '))!=NULL)           *del =',';           while((del=strchr(buffer,'\t'))!=NULL)           *del =',';           *buf ='\0';               sscanf(buffer,"%s",buf);              selectbuf(buf);                         printf("
:[%s] 
",buf);                          fq =fopen("voice.vbs","w");           if(fq!=NULL)           {           fprintf(fq,"CreateObject(\"SAPI.Spvoice\").Speak\"%s\"",buf);//  CreateObject("SAPI.SpVoice").Speak "I LOVE YOU"            fclose(fq);           system("voice.vbs");           system("del voice.vbs");           }                        }         }         else         {           while(1){                                  printf(" , TXT ( : )!
");           printf("
:");           fflush(stdin);           fgets(buffer,1000,stdin);           if(strstr(buffer,"。 。")!=NULL)           break;            printf("
:%s",buffer);           while((del=strchr(buffer,' '))!=NULL)           *del =',';           while((del=strchr(buffer,'\t'))!=NULL)           *del =',';             sscanf(buffer,"%s",buf);           selectbuf(buf);                           printf("
:[%s] 
",buf);           fq =fopen("voice.vbs","w");           if(fq!=NULL)           {           fprintf(fq,"CreateObject(\"SAPI.Spvoice\").Speak\"%s\"",buf);//  CreateObject("SAPI.SpVoice").Speak "I LOVE YOU"            fclose(fq);           system("voice.vbs");           system("del voice.vbs");           }                    printf(" “。 。 ” !
");              }        }     }

좋은 웹페이지 즐겨찾기