Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output word timings #1974

Merged
merged 14 commits into from
Mar 30, 2019
23 changes: 12 additions & 11 deletions native_client/deepspeech.cc
Original file line number Diff line number Diff line change
Expand Up @@ -485,22 +485,23 @@ Metadata* ModelState::decode_metadata(vector<float>& logits)
{
vector<Output> out = decode_raw(logits);

Metadata* metadata = (Metadata*)malloc(sizeof (Metadata));
Metadata* metadata = new Metadata;
dabinat marked this conversation as resolved.
Show resolved Hide resolved
metadata->num_items = out[0].tokens.size();
metadata->items = (MetadataItem*)malloc(sizeof(MetadataItem) * metadata->num_items);
metadata->items = new MetadataItem[metadata->num_items];
dabinat marked this conversation as resolved.
Show resolved Hide resolved

// Loop through each character
for (int i = 0; i < out[0].tokens.size(); ++i) {
MetadataItem item;
item.character = (char*)alphabet->StringFromLabel(out[0].tokens[i]).c_str();
item.timestep = out[0].timesteps[i];
item.start_time = static_cast<float>(out[0].timesteps[i] * AUDIO_WIN_STEP);
MetadataItem *item = new MetadataItem;
dabinat marked this conversation as resolved.
Show resolved Hide resolved
item->character = (char*)alphabet->StringFromLabel(out[0].tokens[i]).c_str();
item->timestep = out[0].timesteps[i];
item->start_time = static_cast<float>(out[0].timesteps[i] * AUDIO_WIN_STEP);

if (item.start_time < 0) {
item.start_time = 0;
if (item->start_time < 0) {
item->start_time = 0;
}

metadata->items[i] = item;
metadata->items[i] = *item;
dabinat marked this conversation as resolved.
Show resolved Hide resolved
delete(item);
dabinat marked this conversation as resolved.
Show resolved Hide resolved
}

return metadata;
dabinat marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -916,8 +917,8 @@ DS_AudioToInputVector(const short* aBuffer,
void
DS_FreeMetadata(Metadata* m)
{
free(m->items);
free(m);
delete(m->items);
dabinat marked this conversation as resolved.
Show resolved Hide resolved
delete(m);
}

void
Expand Down