2015-09-28 19:19:39 +00:00
|
|
|
#include <iostream>
|
2015-11-18 19:59:03 +00:00
|
|
|
#include "audio_input/WaveFileReader.h"
|
|
|
|
#include "phone_extraction.h"
|
2015-11-19 20:17:35 +00:00
|
|
|
#include "platform_tools.h"
|
2015-09-28 19:19:39 +00:00
|
|
|
|
2015-11-19 17:32:14 +00:00
|
|
|
using std::exception;
|
|
|
|
using std::string;
|
2015-11-19 20:17:35 +00:00
|
|
|
using std::wstring;
|
2015-11-19 17:32:14 +00:00
|
|
|
using std::unique_ptr;
|
|
|
|
|
|
|
|
string getMessage(const exception& e) {
|
|
|
|
string result(e.what());
|
|
|
|
try {
|
|
|
|
std::rethrow_if_nested(e);
|
|
|
|
} catch(const exception& innerException) {
|
|
|
|
result += "\n" + getMessage(innerException);
|
|
|
|
} catch(...) {}
|
2015-09-10 19:31:25 +00:00
|
|
|
|
2015-11-19 17:32:14 +00:00
|
|
|
return result;
|
|
|
|
}
|
2015-09-10 19:31:25 +00:00
|
|
|
|
2015-11-19 20:17:35 +00:00
|
|
|
unique_ptr<AudioStream> createAudioStream(boost::filesystem::path filePath) {
|
2015-11-19 17:32:14 +00:00
|
|
|
try {
|
2015-11-19 20:17:35 +00:00
|
|
|
return unique_ptr<AudioStream>(new WaveFileReader(filePath));
|
2015-11-19 17:32:14 +00:00
|
|
|
} catch (...) {
|
|
|
|
std::throw_with_nested(std::runtime_error("Could not open sound file.") );
|
2015-09-10 19:31:25 +00:00
|
|
|
}
|
2015-11-19 17:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
try {
|
2015-11-19 20:17:35 +00:00
|
|
|
// Get sound file name
|
|
|
|
std::vector<wstring> commandLineArgs = getCommandLineArgs(argc, argv);
|
|
|
|
if (commandLineArgs.size() != 2) {
|
|
|
|
throw std::runtime_error("Invalid command line arguments. Call with sound file name as sole argument.");
|
|
|
|
}
|
|
|
|
wstring soundFileName = commandLineArgs[1];
|
|
|
|
|
|
|
|
// Create audio streams
|
|
|
|
unique_ptr<AudioStream> audioStream = createAudioStream(soundFileName);
|
2015-09-10 19:31:25 +00:00
|
|
|
|
2015-11-19 20:17:35 +00:00
|
|
|
// Detect phones
|
2015-11-19 17:32:14 +00:00
|
|
|
std::map<centiseconds, Phone> phones = detectPhones(std::move(audioStream));
|
|
|
|
|
|
|
|
for (auto &pair : phones) {
|
|
|
|
std::cout << pair.first << ": " << phoneToString(pair.second) << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} catch (const exception& e) {
|
|
|
|
std::cout << "An error occurred. " << getMessage(e);
|
|
|
|
return 1;
|
|
|
|
}
|
2015-09-10 18:05:05 +00:00
|
|
|
}
|