mirror of
https://github.com/DanielSWolf/rhubarb-lip-sync.git
synced 2026-11-21 12:25:08 +00:00
Refactoring
* Rewriting Timeline<T> to be sparse, i.e., allow gaps * Added specialized subclasses BoundedTimeline<T> and ContinuousTimeline<T> * Timed<T> and TimeRange: has-a, not is-a * Introducing Timed<void>
This commit is contained in:
@@ -214,7 +214,12 @@ vector<s3wid_t> getWordIds(const vector<string>& words, dict_t& dictionary) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Timeline<Phone> getPhoneAlignment(const vector<s3wid_t>& wordIds, unique_ptr<AudioStream> audioStream, ps_decoder_t& recognizer, ProgressSink& progressSink) {
|
||||
BoundedTimeline<Phone> getPhoneAlignment(
|
||||
const vector<s3wid_t>& wordIds,
|
||||
unique_ptr<AudioStream> audioStream,
|
||||
ps_decoder_t& recognizer,
|
||||
ProgressSink& progressSink)
|
||||
{
|
||||
// Create alignment list
|
||||
lambda_unique_ptr<ps_alignment_t> alignment(
|
||||
ps_alignment_init(recognizer.d2p),
|
||||
@@ -265,12 +270,14 @@ Timeline<Phone> getPhoneAlignment(const vector<s3wid_t>& wordIds, unique_ptr<Aud
|
||||
|
||||
// Extract phones with timestamps
|
||||
char** phoneNames = recognizer.dict->mdef->ciname;
|
||||
Timeline<Phone> result(audioStream->getTruncatedRange());
|
||||
BoundedTimeline<Phone> result(audioStream->getTruncatedRange());
|
||||
for (ps_alignment_iter_t* it = ps_alignment_phones(alignment.get()); it; it = ps_alignment_iter_next(it)) {
|
||||
// Get phone
|
||||
ps_alignment_entry_t* phoneEntry = ps_alignment_iter_get(it);
|
||||
s3cipid_t phoneId = phoneEntry->id.pid.cipid;
|
||||
char* phoneName = phoneNames[phoneId];
|
||||
string phoneName = phoneNames[phoneId];
|
||||
|
||||
if (phoneName == "SIL") continue;
|
||||
|
||||
// Add entry
|
||||
centiseconds start(phoneEntry->start);
|
||||
@@ -283,14 +290,15 @@ Timeline<Phone> getPhoneAlignment(const vector<s3wid_t>& wordIds, unique_ptr<Aud
|
||||
return result;
|
||||
}
|
||||
|
||||
Timeline<Phone> detectPhones(
|
||||
BoundedTimeline<Phone> detectPhones(
|
||||
unique_ptr<AudioStream> audioStream,
|
||||
boost::optional<std::string> dialog,
|
||||
ProgressSink& progressSink)
|
||||
{
|
||||
// Pocketsphinx doesn't like empty input
|
||||
if (audioStream->getTruncatedRange().getLength() == centiseconds::zero()) {
|
||||
return Timeline<Phone>{};
|
||||
TimeRange audioRange = audioStream->getTruncatedRange();
|
||||
if (audioRange.empty()) {
|
||||
return BoundedTimeline<Phone>(audioRange);
|
||||
}
|
||||
|
||||
// Discard Pocketsphinx output
|
||||
@@ -323,7 +331,7 @@ Timeline<Phone> detectPhones(
|
||||
vector<s3wid_t> wordIds = getWordIds(words, *recognizer->dict);
|
||||
|
||||
// Align the word's phones with speech
|
||||
Timeline<Phone> result = getPhoneAlignment(wordIds, std::move(audioStream), *recognizer.get(), alignmentProgressSink);
|
||||
BoundedTimeline<Phone> result = getPhoneAlignment(wordIds, std::move(audioStream), *recognizer.get(), alignmentProgressSink);
|
||||
return result;
|
||||
}
|
||||
catch (...) {
|
||||
|
||||
Reference in New Issue
Block a user