Kitt-AI / snowboy

Future versions with model training module will be maintained through a forked version here: https://github.com/seasalt-ai/snowboy
Other
3.08k stars 997 forks source link

add -infile option to read from pre-recorded wav file #47

Closed Sispheor closed 8 years ago

Sispheor commented 8 years ago

For testing, I would like to record my voice and give the recorded sample to snowboy for testing my script without having to speak into my microphone everytime.

On pocket_sphinx continus there is an option to do that pocketsphinx_continuous -infile file.wav

chenguoguo commented 8 years ago

This is easily doable, but you might have to modify the code a little bit.

Taking the C++ demo as an example,

  std::cout << "Listening... Press Ctrl+C to exit" << std::endl;
  std::vector<int16_t> data;
  while (true) {
    pa_wrapper.Read(&data);
    if (data.size() != 0) {
      int result = detector.RunDetection(data.data(), data.size());
      if (result > 0) {
        std::cout << "Hotword " << result << " detected!" << std::endl;
      }
    }
  }

What you have to do is, instead of reading the data using pa_wrapper.Read(&data); which calls PortAudio and captures audio through the microphone, you should read the data from audio file. Make sure your audio file is in the correct format (16k sampling rate, 1 channel, 16 bit signed integer), linear PCM.