-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Proper access modifiers for Vector * More cleanup and enable lto * Add examples using real audio * Add libpulse-dev to dependencies
- Loading branch information
1 parent
f6cbed7
commit c51cd4e
Showing
43 changed files
with
1,047 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <helper.h> | ||
#include <iostream> | ||
#include <snowboy-detect.h> | ||
#include <pulseaudio.h> | ||
|
||
const static auto root = detect_project_root(); | ||
|
||
namespace pa = pulseaudio; | ||
|
||
int main(int argc, const char** argv) try | ||
{ | ||
std::string model = root + "resources/models/snowboy.umdl"; | ||
if(argc > 1) model = argv[1]; | ||
pa::simple_record_stream audio_in{"Microphone input"}; | ||
pa::simple_playback_stream audio_out{"Ding"}; | ||
|
||
snowboy::SnowboyDetect detector(root + "resources/common.res", model); | ||
detector.SetSensitivity("0.3"); | ||
detector.SetAudioGain(1.0); | ||
detector.ApplyFrontend(true); | ||
|
||
auto ding = read_sample_file(root + "resources/dong.wav"); | ||
std::vector<short> samples; | ||
while (true) { | ||
audio_in.read(samples); | ||
auto s = detector.RunDetection(samples.data(), samples.size(), false); | ||
//std::cout << "\r \r" << s << std::flush; | ||
if (s > 0) { | ||
std::cout << "a " << s << std::endl; | ||
audio_out.write(ding); | ||
} | ||
} | ||
return 0; | ||
} catch (const std::exception& e) { | ||
std::cerr << "Error: " << e.what() << std::endl; | ||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <helper.h> | ||
#include <iostream> | ||
#include <snowboy-detect.h> | ||
#include <pulseaudio.h> | ||
|
||
const static auto root = detect_project_root(); | ||
|
||
namespace pa = pulseaudio; | ||
|
||
std::vector<short> record_word(pa::simple_record_stream& audio_in) { | ||
snowboy::SnowboyVad vad{root + "resources/common.res"}; | ||
std::vector<short> samples; | ||
std::vector<short> result; | ||
audio_in.read(samples); | ||
// Skip leading silence | ||
while (vad.RunVad(samples.data(), samples.size()) == -2) { | ||
std::cout << "S" << std::flush; | ||
audio_in.read(samples); | ||
} | ||
// Keep samples while there is voice | ||
result = samples; | ||
while (vad.RunVad(samples.data(), samples.size()) == 0) { | ||
std::cout << "A" << std::flush; | ||
audio_in.read(samples); | ||
result.insert(result.end(), samples.begin(), samples.end()); | ||
} | ||
std::cout << "D\n" << std::flush; | ||
return result; | ||
} | ||
|
||
int main(int argc, const char** argv) try | ||
{ | ||
std::string output = "model.pmdl", language = "en"; | ||
int64_t num_records = 3; | ||
option_parser parser; | ||
parser.option("--output", &output).set_shortname("-o").set_description("Output filename for the model"); | ||
parser.option("--language", &language).set_shortname("-l").set_description("Language of the enrolled word"); | ||
parser.option("--nrecs", &num_records).set_min(3).set_shortname("-n").set_required(true).set_description("Number of hotword samples to record for the model"); | ||
parser.parse(argc, argv); | ||
|
||
snowboy::SnowboyPersonalEnroll enroll{root + "resources/pmdl/en/personal_enroll.res", "model.pmdl"}; | ||
snowboy::SnowboyTemplateCut cut{root + "resources/pmdl/en/personal_enroll.res"}; | ||
pa::simple_record_stream audio_in{"Microphone input", enroll.SampleRate(), enroll.NumChannels()}; | ||
|
||
for(int64_t i=1; i<=num_records; i++) { | ||
std::cout << "[" << i << "/" << num_records << "] "; | ||
auto sample = record_word(audio_in); | ||
std::cout << "[" << i << "/" << num_records << "] Got sample with length = " << (static_cast<float>(sample.size())/16000.0f) << "s (" << sample.size() << " samples)" << std::endl; | ||
int new_size; | ||
if(cut.CutTemplate(sample.data(), sample.size(), sample.data(), &new_size) != 0) | ||
throw std::runtime_error("Failed to cut template"); | ||
sample.resize(new_size); | ||
std::cout << "[" << i << "/" << num_records << "] length after cutting = " << (static_cast<float>(sample.size())/16000.0f) << "s (" << sample.size() << " samples)" << std::endl; | ||
auto res = enroll.RunEnrollment(sample.data(), sample.size()); | ||
if (res != 0) { | ||
std::cerr << "Training failed with error " << res << std::endl; | ||
return -1; | ||
} | ||
} | ||
return 0; | ||
} catch (const std::exception& e) { | ||
std::cerr << "Error: " << e.what() << std::endl; | ||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.