Skip to content

Instantly share code, notes, and snippets.

@laic
Last active November 17, 2021 09:32
Show Gist options
  • Save laic/8673c9aaf24e83785721008e7c9e9572 to your computer and use it in GitHub Desktop.
Save laic/8673c9aaf24e83785721008e7c9e9572 to your computer and use it in GitHub Desktop.
Install HTK on a mac

Installing HTK on a MacBook (Nov 2021)

Install Homebrew and command line tools

You'll need to install https://brew.sh (a Mac software manager) if you haven't already. This will let you download various packages on from the terminal with ease!

You may first need to install Mac commandline tools. These usually come with the very large Xcode software development package. But you can just install the commandline tools: Open up the terminal app and enter the following command

xcode-select --install

You can also install the whole Xcode package, though it takes quite a long time and the download is quite big. See links here: https://docs.brew.sh/Installation

Then to install homebrew, run the following command in the terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

This will start the install, printing out lots of info. At points it will ask you to enter some info:

  • Enter your computer password when it asks
  • Press RETURN (or ENTER) to continue, when it asks

Then you'll need to wait for a while. Check that you get an "Installation Successful!" message on the terminal.

Now get homebrew cask - this basically allows you to easily install more applications, including Graphical User Interface based ones like Atom or Chrome. We don't need GUI apps for this assignment, but we do need cask to install some HTK dependencies:

brew install cask

Again, this might take a while.

Install xquartz

Now you can install xquartz which provides the X11 libraries that HTK needs:

brew install --cask xquartz

Download the HTK source files

Go to the HTK website: https://htk.eng.cam.ac.uk

To download the source code and read the documentation (the HTK book), you'll need to register for an account: https://htk.eng.cam.ac.uk/register.shtml

Once you're account is setup, go to the Download page: https://htk.eng.cam.ac.uk/download.shtml

Download the "stable" version of HTK 3.4.1: https://htk.eng.cam.ac.uk/ftp/software/HTK-3.4.1.tar.gz

Make a note of where you downloaded it to! I downloaded it to /Users/clai/speech_processing/tools

Install HTK

Open your terminal and go to the directory that you downloaded the HTK-3.4.1.tar.gz to. The terminal usually starts off in your home directory (for me /Users/clai), but I'll just use the full path here to demonstrate

cd /Users/clai/speech_processing/tools

Use the ls command to check that the zip file is in the directory

ls

Sometimes Macs will unzip archives for you automatically. If you see the file HTK-3.4.1.tar (i.e. no .gz), you can run the following command to unpack the archive:

tar xvf HTK-3.4.1.tar

Otherwise, use the following command (which tells the tar command to unzip the archive before unpacking it):

tar xvzf HTK-3.4.1.tar.gz

If you type ls in the terminal now, you should see a directory called htk. Go into that directory:

cd htk

Fix the malloc.h issue

There is a reference to a deprecated library in the file HTKLib/strarr.c that we need to edit to fix.
You can open that file with a command line text editor like nano (you could also use atom instead, or any other text editor you are familiar with, but NOT Word!):

nano HTKLib/strarr.c 

If you use nano to edit:

  • Change the line near the top that says #include <malloc.h> to #include <stdlib.h>
  • Exit and save the file by pressing Control-X
  • Press Y in response to "save modified buffer",
  • Press ENTER to keep the file name as it was.

Configure the installation parameters

Now configure things before compiling all the code:

CFLAGS="-I/opt/X11/include" ./configure --x-includes=/opt/X11/include/

Compile and install the code using make

Now type in the following command, which will start compiling the source code into the actual application we want to use@

make all

If that all goes well, you use the following command to install the binaries into your path:

make install

As an initial test of whether it's working, try:

HVite

You should see a bunch of help information printed out.

Getting the scripts and data from the PPLS AT lab servers

It's good to keep a separation between tools and the actual data you use and generate for the assignment. So, now we will go to the directory you actually want to do the assignment work in. I'll just try to mirror the directory structure given in the assignment instructions.

Let's get the data:

Make sure you have the University VPN on if you're not on campus.

In the following, set YOUR_UUN to your actual UUN rather than mine

YOUR_UUN=clai

make the directory ~/Documents/sp if you didn't already do that for assignment 1:

mkdir -p  ~/Documents/sp/

Get the scripts:

rsync -avz $YOUR_UUN@scp1.ppls.ed.ac.uk:/Volumes/Network/courses/sp/digit_recogniser ~/Documents/sp

Get the data, excluding the previous wav files for now (features have already been extracted):

rsync --exclude 'wav' -avz $YOUR_UUN@scp1.ppls.ed.ac.uk:/Volumes/Network/courses/sp/data  ~/Documents/sp

Now go to the directory you just downloaded the scripts, i.e. digit_recognizer:

cd ~/Documents/sp/digit_recognizer

Things to note about running the scripts:

  • You'll need to run scripts from the digit_recognizer directory, not the scripts directory below it. e.g.:
./scripts/initialise_models

Remember not to skip the ./ at the beginning of that line. It tells the computer to run the command using the file scripts/initialise_models relative to you current directory. Otherwise, the computer it will look for the command in all the directories listed in your PATH environment variable (and probably give you an error).

  • The scripts assume you are using the bash shell, but the path to bash at the top of each the scripts is not quite right for a Mac. For example, the first line in scripts/initialise_models is #!/usr/bin/bash, but you will need to change it to #!/bin/bash instead.

  • If you are running zsh as your default shell (maybe on newer MacBooks), you might need to change it to bash using the following command:

chsh -s /bin/bash
  • Since we're not collecting and labelling data as the first step, you'll need to change the scripts to build a speaker dependent model from an existing speaker. So, each of the script change the beginning from this:
#!/usr/bin/bash

# to use your own data, this automatically sets USER to be your username
USER=${USER:-`whoami`}
# and this is the path to where your data was placed by the make_mfccs script
DATA=${DATA:-/Volumes/Network/courses/sp/data_upload}

# later, to use another user's data, for example "simonk"
# USER=simonk
# and to access all data from all years, use this path
# DATA=${DATA:-/Volumes/Network/courses/sp/data}

to this:

#!/bin/bash

## to use your own data, this automatically sets USER to be your username
#USER=${USER:-`whoami`}
## and this is the path to where your data was placed by the make_mfccs script
##DATA=${DATA:-~/Documents/sp/data}

# Use another user's data, for example "simonk"
USER=simonk
# and to access all data from all years, use this path
DATA=~/Documents/sp/data}

Assuming you downloaded the data as per the instructions above.

These steps worked for me on a Macbook Air 2017 which already had lots of things installed on it. So do let me know if you run into issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment