Home > asr > text2pa4english.m

text2pa4english

PURPOSE ^

text2pa4english: Text (a sentence) to PA (phonetic alphabet) conversion

SYNOPSIS ^

function output=text2pa4english(text, wpa)

DESCRIPTION ^

 text2pa4english: Text (a sentence) to PA (phonetic alphabet) conversion
    Usage: output=text2pa4english(text)
        output=text2pa4english(text, wpaList)

    For example:
        text='What are you allergic to?';
        output=text2pa4english(text)
        for i=1:length(output)
            fprintf('word=%s, pa=%s\n', output(i).word, cell2str(output(i).pa));
        end

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function output=text2pa4english(text, wpa)
0002 % text2pa4english: Text (a sentence) to PA (phonetic alphabet) conversion
0003 %    Usage: output=text2pa4english(text)
0004 %        output=text2pa4english(text, wpaList)
0005 %
0006 %    For example:
0007 %        text='What are you allergic to?';
0008 %        output=text2pa4english(text)
0009 %        for i=1:length(output)
0010 %            fprintf('word=%s, pa=%s\n', output(i).word, cell2str(output(i).pa));
0011 %        end
0012 
0013 %    Roger Jang, 20100107
0014 
0015 if nargin<1, selfdemo; return; end
0016 if nargin<2, 
0017     [parentDir, junk, junk, junk]=fileparts(which(mfilename));
0018     exeDir=[parentDir, '\exe'];
0019     englishWpaFile=[exeDir, '\asraData\english\english.wpa'];
0020     fprintf('Reading %s...\n', englishWpaFile);
0021     wpa=wpaRead(englishWpaFile);
0022 end
0023 words={wpa.word};
0024 tokens=textNormalize4english(text);
0025 
0026 % Search the dict
0027 for i=1:length(tokens)
0028     output(i).word=tokens{i};
0029     index=find(strcmp(tokens{i}, words));
0030     if length(index)==0
0031         fprintf('Warning: Cannot find "%s" in the WPA list!\n', tokens{i});
0032     end
0033     if length(index)==1
0034         output(i).pa=wpa(index).pa;
0035     end
0036     output(i).pa=split(output(i).pa, '#');
0037 end
0038 
0039 % ====== Self demo
0040 function selfdemo
0041 text='What are you allergic to?';
0042 output=text2pa4english(text)
0043 for i=1:length(output)
0044     fprintf('word=%s, pa=%s\n', output(i).word, cell2str(output(i).pa));
0045 end

Generated on Tue 01-Jun-2010 09:50:19 by m2html © 2003