0001 function [cmObj, dosCmd, time, exeStatus, exeResult, pitchObj0, pitchObj]=waveAssess(waveFile, text, language, plotOpt, pitchFile, cmFile, labFile, plpFile)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 if nargin<1, selfdemo; return; end
0059 if nargin<4, plotOpt=0; end
0060 if nargin<5, pitchFile=[]; end
0061 if nargin<6, cmFile=[]; end
0062 if nargin<7, labFile=[]; end
0063 if nargin<8, plpFile=[]; end
0064
0065 if exist(waveFile)~=2
0066 error(sprintf('Cannot find %s within %s!\n', waveFile, mfilename));
0067 end
0068
0069
0070 [a, b, waveFileExtName, d]=fileparts(waveFile);
0071 switch lower(waveFileExtName)
0072 case '.raw'
0073 fs=16000; nbits=16;
0074 wave=rawRead(waveFile, nbits);
0075 waveFile=[tempname, '.wav'];
0076 wavwrite(wave/32768, fs, nbits, waveFile);
0077 case {'.wav', '.flv', '.wa1'}
0078
0079 otherwise
0080 error(sprintf('Unknown audio file extension = %s!\n', waveFileExtName));
0081 end
0082
0083
0084 if isstr(language)
0085 rp=saParamSet(language);
0086 else
0087 rp=language;
0088 end
0089
0090
0091 [parentDir, mainName, textFileExtName, junk]=fileparts(text);
0092 if strcmp(lower(textFileExtName), '.txt')
0093 textFile=text;
0094 else
0095 textFile=[tempname, '.txt'];
0096 if strcmp(rp.language, 'chinese')
0097 text=text(isTradChinese(text));
0098 end
0099 fid=fopen(textFile, 'w'); fprintf(fid, '%s\n', text); fclose(fid);
0100 tempTxtFile=textFile;
0101 end
0102
0103 if ~isempty(pitchFile) & ~isnan(pitchFile)
0104 rp.getPitch=1;
0105 end
0106
0107
0108 [parentDir, junk, junk, junk]=fileparts(which(mfilename));
0109 exeDir=[parentDir, '\exe'];
0110
0111
0112 if ~isAbsPath(waveFile)
0113 waveFile=which(waveFile);
0114 end
0115 dosCmd=sprintf('"assess.exe" "%s" "%s" "%s" %d "%s" "%s" "%s" "%s" %d', rp.file, waveFile, textFile, rp.useEpd, rp.outputDir, rp.sylFile, rp.netFile, rp.wpaFile, rp.getPitch);
0116
0117 currDir=pwd;
0118 cd(exeDir);
0119 cd('output'); delete('*.*');
0120 cd(exeDir);
0121
0122 t0=clock; [exeStatus, exeResult]=dos(dosCmd); time=etime(clock, t0);
0123 cd(currDir);
0124
0125 debug=0;
0126 if isempty(findstr('Done!', exeResult))
0127 debug=1;
0128 fprintf('dosCmd=%s\n', dosCmd);
0129 fprintf('exeStatus=%d\n', exeStatus);
0130 fprintf('exeResult=%s\n', exeResult);
0131 fprintf('Something went wrong!\nYou can copy the dosCmd and run it under DOS window within {asrToolbox}\\exe directory to see the results for debugging.\n');
0132 cmObj=[];
0133 pitchObj0=[];
0134 pitchObj=[];
0135 return;
0136 end
0137
0138
0139 xmlFile=[exeDir, '\output\output.xml'];
0140 output=asraOutputXmlRead(xmlFile);
0141 cmObj=output.confidenceMeasure;
0142
0143
0144
0145 origCmFile=[exeDir, '\output\phone.cm'];
0146 if ~exist(origCmFile)
0147 msg=sprintf('Cannot find %s!\n', origCmFile);
0148 error(msg);
0149 end
0150 cmObj=cmRead(origCmFile);
0151 if ~(isempty(cmFile) | isnan(cmFile))
0152
0153 myCopyFile(origCmFile, cmFile);
0154 else
0155 cmFile=origCmFile;
0156 end
0157
0158
0159 origLabFile=[exeDir, '\output\phone.lab'];
0160 if ~exist(origLabFile)
0161 msg=sprintf('Cannot find %s!\n', origLabFile);
0162 error(msg);
0163 end
0164 if ~(isempty(labFile) | isnan(labFile))
0165
0166 myCopyFile(origLabFile, labFile);
0167 else
0168 labFile=origLabFile;
0169 end
0170
0171
0172 origPlpFile=[exeDir, '\output\phone.plp'];
0173 if ~exist(origPlpFile)
0174 msg=sprintf('Cannot find %s!\n', origPlpFile);
0175 error(msg);
0176 end
0177 if ~(isempty(plpFile) | isnan(plpFile))
0178
0179 myCopyFile(origPlpFile, plpFile);
0180 else
0181 plpFile=origPlpFile;
0182 end
0183
0184
0185 if ~(isempty(pitchFile) | isnan(pitchFile))
0186 origPitchFile=[exeDir, '\output\pitch.txt'];
0187 if ~exist(origPitchFile)
0188 msg=sprintf('Cannot find %s!\n', origPitchFile);
0189 error(msg);
0190 end
0191
0192 myCopyFile(origPitchFile, pitchFile);
0193 end
0194
0195
0196 fid=fopen([exeDir, '\output\score.txt'], 'r'); score=fscanf(fid, '%f'); fclose(fid);
0197
0198
0199 if rp.getPitch
0200 qiYin=textread(rp.qiYinFile, '%s', 'delimiter', '\n', 'whitespace', '');
0201 pitch0=asciiRead(pitchFile);
0202
0203
0204
0205 extendedPointNum=cmObj.word(end).phone(end).interval(2)*100-length(pitch0);
0206 pitch0=[pitch0, pitch0(end)*ones(1, extendedPointNum)];
0207 for i=1:length(cmObj.word)
0208 wordName=cmObj.word(i).name;
0209 volume=cmObj.word(i).volume;
0210 wordStartIndex=cmObj.word(i).phone(1).interval(1)*100+1;
0211 for j=1:length(cmObj.word(i).phone)
0212 startIndex=cmObj.word(i).phone(j).interval(1)*100+1;
0213 endIndex=cmObj.word(i).phone(j).interval(2)*100;
0214 cmObj.word(i).phone(j).pitch0=pitch0(startIndex:endIndex);
0215 cmObj.word(i).phone(j).pitch=pitch0(startIndex:endIndex);
0216 cmObj.word(i).phone(j).volume=volume((startIndex:endIndex)-wordStartIndex+1);
0217 phoneName=cmObj.word(i).phone(j).name;
0218 plusIndex=findstr(phoneName, '+');
0219 monoPhoneName=phoneName;
0220 if length(plusIndex)==1
0221 monoPhoneName=phoneName(1:plusIndex-1);
0222 end
0223 index=find(strcmp(qiYin, monoPhoneName));
0224 if ~isempty(index)
0225 cmObj.word(i).phone(j).pitch=0*cmObj.word(i).phone(j).pitch;
0226 end
0227 end
0228
0229 cmObj.word(i).pitch0=[cmObj.word(i).phone.pitch0];
0230 cmObj.word(i).pitch=[cmObj.word(i).phone.pitch];
0231 end
0232 end
0233
0234
0235
0236 tempWaveFile='';
0237 if plotOpt
0238
0239 if strcmp(lower(waveFileExtName), '.flv')
0240 tempWaveFile=[tempname, '.wav'];
0241 flv2wav(waveFile, tempWaveFile);
0242 waveFile=tempWaveFile;
0243 end
0244
0245 tempWaveFile=[tempname, '.wav'];
0246 wave2wave(waveFile, tempWaveFile, 16000, 16);
0247 if ~exist(tempWaveFile)
0248 error(sprintf('Cannot find %s within %s!\n', tempWaveFile, mfilename));
0249 end
0250
0251 if ~rp.getPitch
0252 waveCmPlot(tempWaveFile, xmlFile);
0253 else
0254 [y, fs, nbits]=wavread(tempWaveFile);
0255 frameSize=640; overlap=480;
0256 pitchObj0.frameRate=fs/(frameSize-overlap);
0257 pitchObj0.signal=[cmObj.word.pitch];
0258 cmObj2=cmObj;
0259 for i=1:length(cmObj2.word)
0260 for j=1:length(cmObj2.word(i).phone)
0261 if ~cmObj2.word(i).phone(j).pitched
0262 cmObj2.word(i).phone(j).pitch=0*cmObj2.word(i).phone(j).pitch;
0263 end
0264 end
0265 cmObj2.word(i).pitch=[cmObj2.word(i).phone.pitch];
0266 end
0267 pitchObj=pitchObj0;
0268 pitchObj.signal=[cmObj2.word.pitch];
0269 waveCmPitchPlot(tempWaveFile, xmlFile, pitchObj0, pitchObj);
0270 legend('Pitch1: unbroken', 'Pitch2: segmented');
0271 end
0272 end
0273
0274
0275 if ~debug
0276 if exist(tempWaveFile)==2, delete(tempWaveFile); end
0277 if exist(tempTxtFile)==2, delete(tempTxtFile); end
0278 end
0279
0280
0281 function selfdemo
0282
0283
0284 waveFile='what_would_you_like_to_know.wav';
0285 text='what would you like to know';
0286 language='english';
0287 plotOpt=1;
0288 pitchFile='test.pitch';
0289 cmObj=waveAssess(waveFile, text, language, plotOpt, pitchFile)
0290 return
0291
0292
0293 waveFile='ka_ko_no_o_mo_i_de_o_hu_ri_ka_e_tte_mi_ru.wav';
0294 text='XXXXXXX';
0295 [parentDir, junk, junk, junk]=fileparts(which('waveAssess'));
0296 exeDir=[parentDir, '\exe'];
0297 rp.file=[exeDir, '\japanese.sa.prm'];
0298 rp.qiYinFile=[exeDir, '\asraData\japanese\japanese.qiYin'];
0299 rp.language='japanese';
0300 rp.useEpd=0;
0301 rp.outputDir='output';
0302 rp.sylFile=[parentDir, '\japanese0001.syl'];
0303 rp.netFile='';
0304 rp.wpaFile='';
0305 rp.getPitch=1;
0306 plotOpt=1;
0307 pitchFile='test.pitch';
0308 cmObj=waveAssess(waveFile, text, rp, plotOpt, pitchFile)
0309 return
0310
0311
0312 waveFile='yi_cuen_xiang_s_yi_cuen_huei.wav';
0313 text='一寸想思一寸灰';
0314 language='chinese';
0315 plotOpt=1;
0316 pitchFile='test.pitch';
0317 cmObj=waveAssess(waveFile, text, language, plotOpt, pitchFile)