home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / speech / 356 < prev    next >
Encoding:
Text File  |  1992-12-14  |  4.1 KB  |  165 lines

  1. Xref: sparky comp.speech:356 comp.dsp:2793 comp.multimedia:3809
  2. Path: sparky!uunet!dziuxsolim.rutgers.edu!eagle.rutgers.edu!assaleh
  3. From: assaleh@eagle.rutgers.edu (Khaled Assaleh)
  4. Newsgroups: comp.speech,comp.dsp,comp.multimedia
  5. Subject: Re: TIMIT speech data
  6. Message-ID: <Dec.12.18.14.55.1992.6067@eagle.rutgers.edu>
  7. Date: 12 Dec 92 23:14:55 GMT
  8. References: <1992Dec9.215649.17696@alw.nih.gov>
  9. Followup-To: comp.speech
  10. Organization: Rutgers Univ., New Brunswick, N.J.
  11. Lines: 151
  12.  
  13. lwang@nss10.ninds.nih.gov (Lipo Wang) writes:
  14.  
  15. >Hello,
  16.  
  17. >I have recently got a CD of the TIMIT speech database. I would 
  18. >appreciate if you could offer advise on any of the following
  19. >questions:
  20.  
  21. >What is the data format in the *.wav files under the header? 
  22. >In other word, what C read function/format should I use to read out 
  23. >the amplitude of the waveform vs. time (here is represented by 
  24. >the integer labels), so I can display it by standard display
  25. >programs such as Mathematica?
  26.  
  27. Here are two C codes that'll hopefully help you solve your problem.
  28. The first program 'timit2linear.c' converts a .wav TIMIT file to
  29. Linear 16-bit PCM. It basically swaps the two bytes of each 16-bit 
  30. word.          
  31.  
  32. The second program 'bin2short' converts linear 16-bit PCM to ascii
  33. short integers. The two programs can be combined in one simple code
  34. also.
  35.  
  36. ------------------------ FIRST PROGRAM ------------------
  37. /*
  38.    Program Name: timit2linear.c
  39.    Date crated : 8, July 1991
  40.    Function: TIMIT to Linear 16-bit PCM
  41.    Usage: <exe> TIMIT_filename output_filename
  42. */
  43. #include <stdio.h>
  44. #define TIMIT_HEADER_BYTES 1024
  45.  
  46. main(argc,argv)
  47. int argc;
  48. char **argv;
  49.  
  50. {
  51.   unsigned char temp[2],
  52.                 header[TIMIT_HEADER_BYTES];
  53.   FILE *fopen(),
  54.        *fp_in,
  55.        *fp_out;
  56.  
  57. if ((fp_in = fopen(argv[1],"r")) == NULL){
  58.   printf("Can't open input file %s\n",argv[1]);
  59.       exit(1);
  60.     }
  61.  
  62. if ((fp_out = fopen(argv[2],"w")) == NULL){
  63.   printf("Can't open outout file  %s\n",argv[2]);
  64.       exit(1);
  65.     }
  66.  
  67.     fread(header,1,TIMIT_HEADER_BYTES,fp_in);  /* READ OFF THE HEADER */
  68.  
  69.    if(argc < 3){
  70.                 printf("ERROR in using the function %s\n",argv[0]);
  71.                 printf("\t %s, <TIMIT_file> <output file>",argv[0]);
  72.     }
  73.  
  74.      while(fread(temp,1,2,fp_in)!=NULL){
  75.      fwrite(&temp[1],1,1,fp_out);
  76.      fwrite(&temp[0],1,1,fp_out);
  77.     }
  78.  
  79.   close(fp_in);
  80.   close(fp_out);
  81. }
  82.  
  83.  
  84. --------------------- SECOND PROGRAM ----------------------
  85. /*
  86.    Program Name: bin2short.c
  87.    Date created : 8, July 1991
  88.    Function: Linear 16-bit to ascii
  89.    Usage: <exe> <input_file> <output_file> <starting_sample> <end_sample> 
  90. */
  91.  
  92. #include <stdio.h>
  93. main(argc, argv)
  94. int argc;
  95. char *argv[];
  96. {
  97.  
  98. FILE *fp1,
  99.      *fp2;
  100. short temp;
  101. int s,
  102.     e,
  103.     i;
  104.  
  105. if(argc != 5){
  106.                 printf("ERROR in using the function %s\n",argv[0]);
  107.                 printf("Usage: %s, <i_f_name> <o_f_name> <s> <e>\n",argv[0]);
  108.                 printf("i_f_name = input file name\n");
  109.                 printf("o_f_name = output file name\n");
  110.                 printf("s = starting sample number\n");
  111.                 printf("s = ending sample number\n");
  112.     }
  113.  
  114.  
  115. if((fp1 = fopen(argv[1], "r")) == NULL){
  116.               printf("Error in opening file %s. EXITing ....\n", argv[1]);
  117.               exit(1);
  118.         }
  119.  
  120. if((fp2 = fopen(argv[2], "w")) == NULL){
  121.          printf("Error in opening output file %s. EXITing ....\n", argv[2]);
  122.               exit(1);
  123.         }
  124.  
  125. s = atoi(argv[3]);
  126. e = atoi(argv[4]);
  127.  
  128. for(i=0;i<s;i++)
  129. fread(&temp,1,2,fp1);
  130.  
  131. while(i<=e && fread(&temp,1,2,fp1)!=NULL){
  132. fprintf(fp2,"%d\n",temp);
  133. i++;
  134. }
  135. close(fp1);
  136. close(fp2);
  137. }
  138.  
  139. If you have any problems running these programs please contact me
  140. via email.
  141.  
  142. >Are there any programs that can output the TIMIT speech from
  143. >the Sun SPARC speaker?
  144.  
  145. You need to convert the output of the first program to 8-bit ulaw.
  146. If you dont have the code for that contact me and I will send you 
  147. the needed code(s).
  148.  
  149. >Thank you very much,
  150. >Lipo
  151.  
  152. >----------
  153.  
  154. >--
  155. >        Lipo Wang, Ph.D.            
  156. >    National Institutes of Health    Internet: lwang@alw.nih.gov
  157. >    9000 Rockville Pike, Park/431   Phone:    (301) 496-8768
  158. >    Bethesda, MD 20892
  159.  
  160. Good Luck,
  161.  
  162. Khaled Assaleh
  163. CAIP Center,
  164. Rutgers Univ.
  165.