在Matlab中读取HTK二进制文件

3

我使用HTK软件包从我的数据中提取MFCC特征。但现在这些特征以.mfc文件格式存储,根据htk书籍,这是大端二进制文件。当我在matlab中打开这些文件时,有一些值似乎是头部值或其他内容,有人知道如何将头部值与主数据分离吗?


请检查Matlab文件交换平台 http://www.mathworks.com/matlabcentral/fileexchange ,那里有多个提交,例如此链接 http://www.mathworks.com/matlabcentral/fileexchange/32849-htk-mfcc-matlab/content/mfcc/readhtk_lite.m - Daniel
是的,我看到了,但它的文件已经不存在了! - MMD
我不明白。缺少什么? - Daniel
哦!抱歉,我查了一下Mathwork,看起来他们限制了伊朗的IP访问!所以我无法看到你所说的代码! - MMD
1个回答

1
你可以使用这个代码来自matlab文件交换,发布在BSD许可证下。
function [ features, sampPeriod, parmKind ] = readhtk_lite( filename )
% READHTK_LITE Simple routine for reading HTK feature files.
%
%   [ FEATURES, SAMPPERIOD, PARMKIND ] = READHTK_LITE( FILENAME )
%   returns FEATURES from HTK [1] feature file specified by FILENAME,
%   along with sample period (s) in SAMPPERIOD and parameter kind
%   in PARAMKIND. Note that this function provides a trivial 
%   implementation with limited functionality. For fully featured 
%   support of HTK I/O refer for example to the VOICEBOX toolbox [2].
%   
%   Inputs
%           FILENAME is a filename as string of a HTK feature file
%
%   Outputs
%           FEATURES is a feature matrix with feature vectors 
%           as rows and feature dimensions as columns
%
%           SAMPPERIOD is a sample period (s)
%
%           PARMKIND is a code indicating a sample kind
%           (see Sec. 5.10.1 of [1], pp. 80-81)
%
%   Example
%           [ features, sampPeriod, parmKind ] = readhtk_lite( 'sp10_htk.mfc' );
%
%   References
%
%           [1] Young, S., Evermann, G., Gales, M., Hain, T., Kershaw, D., 
%               Liu, X., Moore, G., Odell, J., Ollason, D., Povey, D., 
%               Valtchev, V., Woodland, P., 2006. The HTK Book (for HTK 
%               Version 3.4.1). Engineering Department, Cambridge University.
%               (see also: http://htk.eng.cam.ac.uk)
%
%           [2] VOICEBOX: MATLAB toolbox for speech processing by Mike Brookes
%               url: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html

%   Author: Kamil Wojcicki, September 2011


    mfcfile = fopen( filename, 'r', 'b' );

    nSamples = fread( mfcfile, 1, 'int32' );
    sampPeriod = fread( mfcfile, 1, 'int32' )*1E-7;
    sampSize = 0.25*fread( mfcfile, 1, 'int16' );
    parmKind = fread( mfcfile, 1, 'int16' );

    features = fread( mfcfile, [ sampSize, nSamples ], 'float' ).';

    fclose( mfcfile );


% EOF

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接