Introduction




Download 1,09 Mb.
bet50/62
Sana21.03.2017
Hajmi1,09 Mb.
#917
1   ...   46   47   48   49   50   51   52   53   ...   62
4.3.1 Making voice database

In earlier models the sound files are saved in a directory called voice and according to the token name appropriate file is taken from the directory and appended to the existing output voice files after modifications. In this model the sound files are saved in GDBM database with key as the name of the sound file which is eventually the token name. For example if there is a file in the voice library called 0164179.wav then from this file name the token will be extracted which is filename-extension( 0164179 in this case) and the key value will be set to 0164179. After that the wav file 0164179.wav will be saved in the database with this key value. Later hindiengine will retrieve the sound file using this key value.

The database file voice.db was created on linux platform since directory scanning using system calls is quite easier in linux. GDBM is preinstalled on almost all linux platforms. A GDBM database file created on linux platform can be used in Windows CE using the GDBMCE library function calls. The following code shows how the voice database is made from the voice directory:

/* Linux code */

/* Header files needed */

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include
//Directory pointer to read the contents of voice directory

struct dirent *dpointer;

main()

{

//define the database handler for the music database



GDBM_FILE dbf;

//To make the music database

datum key,content;

int i=0,size;

DIR *dirp;

char *name,*buffer;

char *path;

char *voice = "voice/";

FILE* fpt;

/*

Steps by which music database will be created



1.The directory of sound files are transferred to linux machine.

2.Scan the directory,get the name of each file.

3.key = Name - trailing .wav

4.Content = The wav file.The size of the wav file can be obtained from the

file itself.The 40-44 bytes of the wav file gives the file size.

5.Accordingly the wav file will be stored by the key described above.

*/

dbf=gdbm_open("voice.db",512,GDBM_WRCREAT,777,0);



path = (char*)malloc(30*sizeof(char));

if((dirp=opendir("voice"))==NULL)

{

fprintf(stderr,"Error opening voice\n");



perror("dirlist");

exit(1);


}

//Code to scan the directory and put each wav file into database.

while(dpointer=readdir(dirp))

{

if(i>1)



{

name = strtok(dpointer->d_name,".");

//Inserting values in key

key.dptr = name;

key.dsize = strlen(name);

strcpy(path,voice);

strcat(path,name);

strcat(path,".wav");

fpt = fopen(path,"r+");

fseek(fpt,40,0);

fread(&size,4,1,fpt);

fseek(fpt,0,0);

//Add the 44 bytes of the header

size=size+44;

buffer=(char*)malloc(size*sizeof(char));

fread(buffer,size,1,fpt);

//Inserting values in content

content.dptr = buffer;

content.dsize = size;

//Inserting in database

printf("Inserting in database File no : %d\n",i);

gdbm_store(dbf1,key,content,GDBM_INSERT);

free(buffer);

fclose(fpt);

}

i++;


}

closedir(dirp);

gdbm_close(dbf1);

}
/* compile line */

bash$cc voicedb.c –o voicedb -lgdbm

/* execution */

bash$./voicedb

This will create the voice database in the present working directory. The database will be transferred to Windows CE emulator or device for use.



Download 1,09 Mb.
1   ...   46   47   48   49   50   51   52   53   ...   62




Download 1,09 Mb.