00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <stdio.h>
00015 #include <memory.h>
00016 #include <unistd.h>
00017 #include <stdlib.h>
00018 #include <sys/types.h>
00019 #include <sys/stat.h>
00020 #include <AquesTalk2.h>
00021
00022
00023 void * file_load(const char * file, int * psize);
00024
00025 int main(int ac, char **av)
00026 {
00027 char speak_str[65536];
00028 char phont_fname[1024]={"phont/aq_f3a.phont"},
00029 input_fname[1024]={""}, output_fname[1024]={"output.wav"};
00030 int opt;
00031
00032 while ((opt = getopt(ac, av, "p:o:")) != -1) {
00033 switch (opt) {
00034 case 'p':
00035 strncpy(phont_fname,optarg,1024);
00036 break;
00037 case 'o':
00038 strncpy(output_fname,optarg,1024);
00039 break;
00040 default:
00041 fprintf(stderr, "Usage : %s [-p phont_file] [-o output_file] [intput_file]\n", av[0]);
00042 exit(EXIT_FAILURE);
00043 }
00044 }
00045 if (optind < ac ) {
00046 strncpy(input_fname,av[optind],1024);
00047 }
00048 fprintf(stderr, "Phont file : %s\n", phont_fname);
00049 fprintf(stderr, "Input file : %s\n", input_fname);
00050 fprintf(stderr, "Output file : %s\n", output_fname);
00051
00052
00053 int size;
00054 void *pPhont = file_load(phont_fname, &size);
00055 if(pPhont ==0) {
00056 fprintf(stderr, "could not found phont file %s\n", phont_fname);
00057 return-2;
00058 }
00059
00060 FILE *input_fp = stdin;
00061 if ((strlen(input_fname)>0)&&((input_fp = fopen(input_fname, "r"))==NULL)) {
00062 fprintf(stderr, "could not found input file %s\n", input_fname);
00063 return -2;
00064 }
00065 if(fgets(speak_str,65536-1,input_fp)==0) {
00066 fprintf(stderr, "could not get input string");
00067 }
00068 if ( input_fp != stdin ) fclose(input_fp);
00069
00070
00071 unsigned char *wav = AquesTalk2_Synthe_Utf8(speak_str, 100, &size, pPhont);
00072 if(wav==0) {
00073 fprintf(stderr, "ERR %d\n", size);
00074 return -1;
00075 }
00076
00077 free(pPhont);
00078
00079
00080 FILE *fp = fopen(output_fname, "wb");
00081 fwrite(wav, 1, size, fp);
00082 fclose(fp);
00083
00084 AquesTalk2_FreeWave (wav);
00085 return 0;
00086 }
00087
00088
00089 void * file_load(const char * file, int * psize)
00090 {
00091 FILE *fp;
00092 char *data;
00093 struct stat st;
00094 *psize = 0;
00095 if( stat(file, &st)!=0) return NULL;
00096 if((data=(char *)malloc(st.st_size))==NULL){
00097 fprintf(stderr,"can not alloc memory(file_load)¥n");
00098 return NULL;
00099 }
00100 if((fp=fopen(file,"rb"))==NULL) {
00101 free(data);
00102 perror(file);
00103 return NULL;
00104 }
00105 if(fread(data, 1, st.st_size, fp)<(unsigned)st.st_size) {
00106 fprintf(stderr,"can not read data (file_load)¥n");
00107 free(data);
00108 fclose(fp);
00109 return NULL;
00110 }
00111 fclose(fp);
00112 *psize = st.st_size;
00113 return data;
00114 }