Skip to content

Commit

Permalink
Added Linux version of the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
danijel3 committed Oct 10, 2022
1 parent 28f2a05 commit 9970567
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 225 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.23)
project(KaldiAligner)

set(CMAKE_CXX_STANDARD 11)

set(KALDI_ROOT /opt/kaldi)

include_directories(include ${KALDI_ROOT}/tools/phonetisaurus-g2p/src/ ${KALDI_ROOT}/tools/phonetisaurus-g2p/src/3rdparty/utfcpp ${KALDI_ROOT}/tools/openfst/include ${KALDI_ROOT}/src /usr/local/cuda/include)
link_directories(${KALDI_ROOT}/tools/openfst/lib ${KALDI_ROOT}/src/lib)

SET(PHONETISAURUS_OBJ ${KALDI_ROOT}/tools/phonetisaurus-g2p/src/lib/phonetisaurus_g2pfst-util.o)

add_compile_definitions(HAVE_CUDA)
add_executable(KaldiAligner src/main.cpp src/g2p.cpp src/lex.cpp src/kaldi.cpp src/signaling.cpp ${PHONETISAURUS_OBJ})
target_link_libraries(KaldiAligner fst kaldi-feat kaldi-base kaldi-util kaldi-matrix kaldi-transform kaldi-ivector kaldi-online2 kaldi-decoder kaldi-hmm kaldi-tree kaldi-nnet3 kaldi-cudamatrix kaldi-lat)
4 changes: 4 additions & 0 deletions include/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class Lexicon {
std::vector<int32_t> load_transcript(const std::string &filename);
std::vector<std::string> int2words(std::vector<int32_t> words);
std::vector<std::string> int2phones(std::vector<int32_t> words);

const std::vector<std::string> &get_phonelist() {
return phonelist;
}
};

#endif //KALDIALIGNER_SRC_LEX_H_
8 changes: 8 additions & 0 deletions include/signaling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef KALDIALIGNER_INCLUDE_SIGNALING_H_
#define KALDIALIGNER_INCLUDE_SIGNALING_H_

void init_wait();
void wait_for_signal();
void do_signal();

#endif //KALDIALIGNER_INCLUDE_SIGNALING_H_
7 changes: 5 additions & 2 deletions src/kaldi.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <feat/wave-reader.h>
#include <transform/cmvn.h>
#include <hmm/hmm-utils.h>
#include <nnet3/nnet-am-decodable-simple.h>
#include <nnet3/nnet-utils.h>
Expand Down Expand Up @@ -69,6 +68,10 @@ KaldiProcess::KaldiProcess(std::string model_dir) {

word_boundary_info = std::unique_ptr<WordBoundaryInfo>(new WordBoundaryInfo(opts, word_boundary_file));

// std::ofstream trans_debug("trans.txt");
// trans_model.Print(trans_debug, lexicon->get_phonelist());
// trans_debug.close();

}

void KaldiProcess::MakeLatticeFromLinear(const std::vector<int32> &ali,
Expand Down Expand Up @@ -98,7 +101,7 @@ Result KaldiProcess::process(std::string wav_file, std::string trans_file) {
Matrix<BaseFloat> features;

WaveData wave_data;
std::ifstream file(wav_file.c_str(),std::ios::binary);
std::ifstream file(wav_file.c_str(), std::ios::binary);
wave_data.Read(file);
file.close();

Expand Down
Loading

0 comments on commit 9970567

Please sign in to comment.