transcribe.cpp 1.33 KB
Newer Older
1
2
3
4
#include <torch/script.h>

int main(int argc, char* argv[]) {
  if (argc != 3) {
nateanl's avatar
nateanl committed
5
6
    std::cerr << "Usage: " << argv[0] << " <JIT_OBJECT_DIR> <INPUT_AUDIO_FILE>"
              << std::endl;
7
8
9
10
11
12
13
    return -1;
  }

  torch::jit::script::Module loader, encoder, decoder;
  std::cout << "Loading module from: " << argv[1] << std::endl;
  try {
    loader = torch::jit::load(std::string(argv[1]) + "/loader.zip");
nateanl's avatar
nateanl committed
14
  } catch (const c10::Error& error) {
15
16
17
18
19
    std::cerr << "Failed to load the module:" << error.what() << std::endl;
    return -1;
  }
  try {
    encoder = torch::jit::load(std::string(argv[1]) + "/encoder.zip");
nateanl's avatar
nateanl committed
20
  } catch (const c10::Error& error) {
21
22
23
24
25
    std::cerr << "Failed to load the module:" << error.what() << std::endl;
    return -1;
  }
  try {
    decoder = torch::jit::load(std::string(argv[1]) + "/decoder.zip");
nateanl's avatar
nateanl committed
26
  } catch (const c10::Error& error) {
27
28
29
30
31
32
33
34
35
36
37
    std::cerr << "Failed to load the module:" << error.what() << std::endl;
    return -1;
  }

  std::cout << "Loading the audio" << std::endl;
  auto waveform = loader.forward({c10::IValue(argv[2])});
  std::cout << "Running inference" << std::endl;
  auto emission = encoder.forward({waveform});
  std::cout << "Generating the transcription" << std::endl;
  auto result = decoder.forward({emission});
  std::cout << result.toString()->string() << std::endl;
nateanl's avatar
nateanl committed
38
  std::cout << "Done." << std::endl;
39
}