Home | History | Annotate | Download | only in test_swiarb
      1 /*---------------------------------------------------------------------------*
      2  *  test_swiarb.c                                                            *
      3  *                                                                           *
      4  *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
      5  *                                                                           *
      6  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
      7  *  you may not use this file except in compliance with the License.         *
      8  *                                                                           *
      9  *  You may obtain a copy of the License at                                  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0                           *
     11  *                                                                           *
     12  *  Unless required by applicable law or agreed to in writing, software      *
     13  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
     14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
     15  *  See the License for the specific language governing permissions and      *
     16  *  limitations under the License.                                           *
     17  *                                                                           *
     18  *---------------------------------------------------------------------------*/
     19 
     20 
     21 #include <stdio.h>
     22 #include <stdlib.h>
     23 #include <string.h>
     24 
     25 #include "plog.h"
     26 #include "passert.h"
     27 #include "duk_args.h"
     28 #include "duk_err.h"
     29 #include "ptrd.h"
     30 
     31 #include "srec_arb.h"
     32 #include "simapi.h"
     33 
     34 #include "PFileSystem.h"
     35 #include "PANSIFileSystem.h"
     36 
     37 #define MAX_PATH_LENGTH 256
     38 #define MAX_LINE_LENGTH 256
     39 #define MAX_ENTRY_LENGTH 128
     40 #define MAX_NUM_REC_CONTEXTS 4
     41 #define ANY_SYNTAX syntax_list[0] /* just get around internal checks */
     42 #define NUM_WORDS_TO_ADD 500
     43 #define MAX_INTERACTIVE_NUM 128
     44 
     45 #define printf_vector(HEAD, FMT, PTR, NN) { unsigned int iI; printf(HEAD); for(iI=0;iI<(NN);iI++) printf(FMT, PTR[iI]); printf("\n"); }
     46 
     47 /* #include"scg_arbdata.c" */
     48 //static int debug = 0;
     49 
     50 
     51 int main (int argc, char **argv)
     52 {
     53 	int i, j;
     54 	int interactive_test = 0;
     55     CA_Arbdata             *ca_arbdata = NULL;     /* new, link btw acc/syn */
     56 	//char *modelmap = NULL;
     57 	char *arbfile = NULL;
     58 	char* q;
     59 	modelID model_sequence[128];
     60 	char pronunciation[256];
     61 	int pronunciation_len;
     62 	int rc;
     63 	srec_arbdata *allotree = NULL;
     64 
     65 /* initial memory */
     66 	CHKLOG(rc, PMemInit());
     67 
     68 	if(argc<=1){
     69 	  printf("USAGE: -swiarb <swiarb file> -interactive\n");
     70 	  exit(1);
     71 	}
     72 
     73 
     74 	for(i=1; i<argc; i++) {
     75       if(!strcmp(argv[i],"-swiarb")) {
     76 	if(argc==2){
     77 	  printf("Please specify the swiarb file.\n");
     78 	  exit(1);
     79 	}
     80 	arbfile = argv[++i];
     81 	printf("using swiarb from file %s\n", arbfile);
     82       } else if(!strcmp(argv[i],"-interactive")) {
     83 	interactive_test++;
     84       } else {
     85 	printf("error_usage: argument [%s]\n", argv[i]);
     86 	exit(1);
     87       }
     88     }
     89 
     90 /* get modelID for a triphone */
     91     ca_arbdata = CA_LoadArbdata(arbfile);
     92 
     93     for(i=0; i<MAX_INTERACTIVE_NUM; i++){
     94 
     95       if(interactive_test){
     96 	printf("Type \"quit\" to exit the test.\n");
     97 	printf("pronunciation: ");
     98 	q = fgets(pronunciation, sizeof(pronunciation), stdin);
     99 	if(!strcmp(q,"quit\n")) break;
    100       }
    101       else{
    102 	printf("USAGE: -swiarb <swiarb file> -interactive\n");
    103 	exit(1);
    104       }
    105 
    106       pronunciation_len = strlen(pronunciation)-1;
    107       CA_ArbdataGetModelIdsForPron(ca_arbdata,
    108                                  pronunciation, pronunciation_len,
    109                                  &model_sequence[0]);
    110 
    111 
    112       printf("short pronunciation length is %d.\n", pronunciation_len);
    113       printf("Acoustic model IDs (\"#\" is silence,\"_\" is word boundary):\n");
    114       for (j=0;j<pronunciation_len;j++){
    115 
    116 	if(j==0){
    117 	  if(pronunciation_len==1)
    118 	    printf("triphone:_%c_ -> ModelID:%d\n", pronunciation[j], model_sequence[j]);
    119 	    else
    120 	  printf("triphone:_%c%c -> ModelID:%d\n", pronunciation[j], pronunciation[j+1],
    121 	       model_sequence[j]);
    122 	}
    123 	else if(j==(pronunciation_len-1)){
    124 	  printf("triphone:%c%c_ -> ModelID:%d\n", pronunciation[j-1], pronunciation[j], model_sequence[j]);
    125 	}
    126 	else{
    127 	  printf("triphone:%c%c%c -> ModelID:%d\n", pronunciation[j-1], pronunciation[j], pronunciation[j+1],
    128 	       model_sequence[j]);
    129 	}
    130 
    131 	allotree = (srec_arbdata*)ca_arbdata;
    132 	printf_vector("pel_ids: ", " %d", allotree->hmm_infos[model_sequence[j]].state_indices,
    133 		    (unsigned int) allotree->hmm_infos[model_sequence[j]].num_states);
    134 	printf("\n");
    135 
    136       }
    137     }
    138 
    139   CA_FreeArbdata( ca_arbdata);
    140 
    141   PMemShutdown();
    142   return 0;
    143 CLEANUP:
    144   return 1;
    145 }
    146 
    147