Compiling HTK 3.4 on Windows XP

Introduction

Here are some notes on my experiences of compiling HTK 3.4 on Windows XP. I compiled HTK successfully, but some research and experiment was necessary. In the end I tried and was successful with Cygwin and with Visual Studio Express. I hope you find these notes useful.

The issues addressed here will obtain whether you’re using the makefiles that come bundled in the htk3.4 zipfile or the winmakefiles makefiles refered to by Anna Langley in her 02/02/07 post to htk-users.

These notes do not cover getting HSLab to run on Windows. I hope to look into that in the near future. In the meantime, I recommend Praat for labelling, and Praat or SpeechRecorder for recording.

From now on (22nd March 2008) I shall not approve comments to this post asking about HSLab.

Preparation

Getting the htk source code

Download the HTK source zipfile form the HTK website. Note you must register - and make sure you read the licence! - before you can download either the code or the documentation.

‘Mac’ format

The source files have multiple carriage returns (’\r’) at line ends. This upsets both make (cygwin) and nmake (VSE). Nmake appears to think the files are in Mac format and won’t touch them. I don’t know why this spurious whitespace is there, or why it should cause such problems. In any case, the first step is to strip out these characters from all source files. Write a little script in your favourite language, or use this Python script:

#! /usr/bin/python
import os

def convert(fn):
    data = open(fn).read().replace('\r\r', '')
    open(fn, 'w').write(data)

def main(dataDir):
    for root, dirs, files in os.walk(dataDir):
        for fn in files:
        fullFn = os.path.join(root, fn)
            convert(fullFn)

if __name__ == '__main__':
    dataDir = 'HTK-3.4/htk/'
    main(dataDir)

Using cygwin

Requirements

You’ll need Cygwin, of course, and make sure you have installed gcc (which might not be included by default).

Prepare HTK source code

The only changes to the source code I found necessary (apart from the line-end changes above), were those pointed out by Mark Huckvale of UCL in his HTK howto.

1. Remove the reference to "-lX11" in the instructions for HSLab:

Change HTKTools/Makefile line 55f

from:

%: %.c $(HTKLIB)
    if [ ! -d $(bindir) -a X_ = X_yes ] ; then mkdir -p $(bindir) ; fi
    if [ x$@ = xHSLab ] ; then
        $(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) -lX11 ;
        else
        $(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) ; fi</pre>

to:

%: %.c $(HTKLIB)
    if [ ! -d $(bindir) -a X_ = X_yes ] ; then mkdir -p $(bindir) ; fi
    if [ x$@ = xHSLab ] ; then
        $(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) ;
        else
        $(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) ; fi</pre>

2. Overwrite HGraf.c

$ cd HTKLib
$ cp HGraf.c HGraf.c.original
$ cp HGraf.null.c HGraf.c
$ cd ..</pre>

Compilation

HTK should now compile with ./configure; make; make install as in the README.

To make HTK available from outside cygwin

HTK is now available only from inside cygwin (e.g., from the cygwin terminal). To make HTK available from the rest of Windows you need to put two things on your PATH:

  • the path to the HTK bin files (e.g.: C:\cygwin\usr\local\bin);
  • the path to the cygwin1.dll (i.e.: C:\cygwin\bin)

Once you’ve put these on your PATH, you should be able to call HTK commands from the Command Prompt window (or anywhere else).

Using visual studio express

Update (27/07/2007): Arlindo Vega has posted to htk-users and created a web page covering compilation of HTK on Windows using Visual Studio 6, 7 (VS.Net2003) and 8 (VS2005).

Set up

Download and install the following (go to the Microsoft VS Express download page and follow the instructions):

  • Visual C++ 2005 Express Edition.
  • Visual Studio Express Editions 2005 Service Pack 1.
  • Microsoft Platform SDK for Microsoft Visual C++ 2005 Express.

n.b.: These are large downloads. Download requires registration.

Make sure the bin/, lib/ & include/ directories of the MS Platform SDK are in your PATH.

Reboot!

Make clean!

Everything should now work as in the README. However, if you get an error message like the following:

C:..htkHTKLib&gt;nmake /f htk_htklib_nt.mkf all

<.../>

Microsoft (R) Program Maintenance Utility Version 8.00.50727.762
Copyright (C) Microsoft Corporation.  All rights reserved.

lib /OUT:HTKLib.win32.lib esig_asc.obj esig_edr.obj esignal.obj
esig_nat.obj HAdapt.obj HAudio.obj HDict.obj HFB.obj  HGraf.null.obj
HLabel.obj HLat.obj HLM.obj HMap.obj HMath.obj HMem.obj HModel.obj
HNet.obj  HParm.obj HRec.obj HShell.obj HSigP.obj HTrain.obj  HUtil.obj
HVQ.obj HWave.obj strarr.obj  HExactMPE.obj HFBLat.obj HArc.obj

Microsoft (R) Library Manager Version 8.00.50727.762
Copyright (C) Microsoft Corporation.  All rights reserved.

esig_asc.obj : fatal error LNK1107: invalid or corrupt file:
 cannot read at 0x1776

NMAKE : fatal error U1077: '"C:Program FilesMicrosoft Visual Studio
8VCBINlib.EXE"' : return code '0x453'

Stop.

Try:

C:pathtohtkHTKLib&gt;nmake /f htk_htklib_nt.mkf clean

And then run your original make again.

Conclusion

HTK will compile on Windows, as long as care is taken over the initial set-up. I hope these notes make that set-up easier.

28 Responses to “Compiling HTK 3.4 on Windows XP”

  1. Nelson Neto Says:

    Hi, could you help me please.
    You could send me the source files without the multiple carriage returns (’\r’) at line ends??? Or where i can get the HTK-3.3 version???
    Because i followed all the steps but i can’t run the HSLab.exe
    When i tried i received the error above:

    C:\Toolkit\htk>HSLab genesis.sig
    ERROR [+6870] MakeXGraf: Not compiled with X11 support: use HGraf.X.c
    FATAL ERROR - Terminating program HSLab

  2. Ivan Says:

    Hi Nelson, thanks for your post.

    Your error is not due to the line-ends, it’s because HTK has been compiled without support for X — in fact I get the same error when I try to run HSLab on an audio file. I get the same error whether I use the cygwin or the VSExpress version of HSLab.

    I can only think of two things to suggest:
    (a) Run it under Linux (which will have X), or;
    (b) if you’re running under cygwin, install X in cygwin,
    recompile htk without making Mark Huckvale’s changes,
    and try again.

    Let me know how you get on — especially if you try plan (b)!

  3. Bereket Kasaye Says:

    Do I need GCC in the case of windows.
    What is the corresponding command for ./configure for window XP.

    Thank you.

  4. Ivan Says:

    Kasaye:

    If you’re compiling within cygwin, use gcc, and you can use ./configure; make; make install - cygwin is a unix environment.

    If you’re using VS, that provides the compiler and the nmake command (see above).

    Ivan

  5. Pradnya Says:

    how to use Cygwin to compile HTK?
    is there any other alternative?

  6. Ivan Says:

    You can also use MS Visual Studio. The article should have a table of contents. Look for the section in the article above ‘Using Visual Studio Express’.

    Ivan

  7. Milton Says:

    hello, how i can install X in cygwin, or exist any other solution for run hslab.exe in windows, without use cygwin
    thanks

  8. amada Says:

    hello,it’s the first time i use HTK.
    I compile it as what sayes in the README.But it doesn’t metioned about cygwin.Shoud i have to use it?
    My english is not so good and i hope you can understand me.
    Thank you!

  9. Ivis Says:

    Hi, I did this C:\path\to\htk\HTKLib>nmake /f htk_htklib_nt.mkf clean but the error continues, can someone help me please?
    Thank you!!!!

  10. daddou Says:

    Hi, I hope that you can help me;
    how can i read waveforms enregistred with praat using htk3.3 version

  11. Ivan Says:

    Dear All,

    Thanks for your comments.

    I’ve reformatted the post slightly, with a table of contents, to make it easier to use.

    I haven’t covered getting hslab to run on Windows, which I think is a separate issue. I hope to look into that in the near future. In the meantime, I recommend Praat for labelling, and Praat or SpeechRecorder for recording.

  12. houssem Says:

    hi,
    When I enter this command “nmake /f htk_htklib_nt.mkf all”, I have this error : htk_htklib_nt.mkf : fatal error U1035: ‘expected : or = seperator
    So can you please help me

  13. Nico Says:

    Hi, when i try to record some signal with HTK tool HSLab,
    there occurs an error when i push the “rec” button:

    $ HSLab blah.sig
    ERROR [+6015] StartAudioInput: null audio device
    FATAL ERROR - Terminating program HSLab

    no idea how to fix this problem…

    p.s: i use HTK-3.4 with cygwin

    thanks a lot

  14. Ivan Says:

    Houssem: Have you removed the extra carriage returns (’\r’s) from line ends? If not, please re-read the section ‘Mac’ Format above.

    Nico: Have you read the introduction to the article, where I say, “These notes do not cover getting hslab to run on Windows”?

  15. Eric Young Says:

    hi,Ivan.

    when i recorded the speech, i received the error just like what the first post said.

    C:\Toolkit\htk>HSLab yes01.sig
    ERROR [+6870] MakeXGraf: Not compiled with X11 support: use HGraf.X.c
    FATAL ERROR - Terminating program HSLab

    would you plz show me how to deal with it???
    thx.

  16. Ivan Says:

    Eric: read the introduction , where I say, “These notes do not cover getting HSLab to run on Windows, …”.

    From now I on shall not approve comments asking about HSLab.

  17. Mahdi Heravi Says:

    Hi,
    could you help me please.
    You could send me the source files without the multiple carriage returns (’\r’) at line ends???

    When I enter this command “nmake /f htk_htklib_nt.mkf all”, I have this error : htk_htklib_nt.mkf : fatal error U1035: ‘expected : or = seperator
    i couldn’t run Python script file for strip out “\r” from all source files.

  18. Ivan Says:

    Mahdi

    Thanks for your comment.

    There was a typo in the convert() function in the script! It should work properly now. Many apologies.

    Ivan

  19. Ravi Says:

    Hi,
    I used the python script to remove the carriage returns… They do get removed but I still continue to get the same error as Mahdi.
    Could u please guide?

  20. Ivan Says:

    Ravi

    If you’ve run the (corrected version of) the script, or otherwise removed the spurious line-endings, then nmake should run fine. Look at which source file is causing your error; look at that file in a text editor; check the line-endings.

    If the line-endings are OK, then I can’t explain your error.

    Ivan

  21. Ravi Says:

    very sorry to bother again…
    If it helps the exact error I get is:
    htk_htklib_nt.mkf :fatal error U1035:syntax error:expected ‘:’ or ‘=’ separator

    Used the corrected version n checked the source files,make files for the line-endings..there doesnt seem to be a problem in them

  22. Ravi Says:

    the error is
    htk_htklib_nt.mkfb6b:(where the b are for angular brackets,didnt get printed above )

  23. amy Says:

    sir will you please help me? sir when i tried to run the HTK Demo, i found that some of the files are missing and they are accs,hmmms,proto and test.will you be able to help me in finding these files… thank you for spending time to read this message

  24. .:: m3rLinEz ::. Says:

    Hi Ivan, I have successfully built HTK 3.4 following your advice. I convert the Mac files to Windows ones using Notepad++ and post the method here. I thought the readers might interest :)

  25. Ivan Says:

    M3rLinEz:

    Thanks for your comment, and that’s a useful-looking technique.

    Ivan

  26. seliz Says:

    Hello Ivan,

    After getting rid of a lot of errors, I finally managed to do things on read me file. However, now there is an error while running HTKDemo which is as below:

    can’t open proto at .\MakeProtoHMMSet line 101, line
    can’t open hmms\hmm.0

    Thanks in advance for your help

    best regards
    seliz

  27. Fouly Says:

    Hi Ivan

    I followed the instructions that m3rLinEz said but still have the same error “htk_htklib_nt.mkf : fatal error U1035: ‘expected : or = seperator”

    Thanks in advance

  28. Ivan Says:

    Dear All

    Thank you for your continued interest in this post. I shall be working with HTK again later this year. I shall write an update of this post and hope to answer your comments then.

    Best wishes

    Ivan