Skip to content

Commit

Permalink
fix: split template richTranscript into prefix and template
Browse files Browse the repository at this point in the history
  • Loading branch information
dsouza95 committed Jan 9, 2024
1 parent e1aabeb commit a57b874
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/speech/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ export declare class IaraSpeechRecognitionDetail extends IaraEventDetail {
transcript: string;
richTranscript: string;
richTranscriptModifiers?: string[];
richTranscriptWithoutModifiers?: string;
rid?: string;
isFinal: boolean;
isFirst: boolean;
Expand Down
26 changes: 21 additions & 5 deletions src/syncfusion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,34 @@ export class IaraSyncfusionAdapter
this.undo();
}

if (inference.richTranscriptModifiers?.length) {
if (
inference.richTranscriptModifiers?.length &&
inference.richTranscriptWithoutModifiers
) {
const phraseOrTemplate =
this._recognition.richTranscriptTemplates.templates[
inference.richTranscriptModifiers[0]
];
const metadata = phraseOrTemplate.metadata as { category?: string };
if (metadata.category === "Template" || !metadata.category) {
const removeDivTags = inference.richTranscript
.replace(/^<div>/, "")
const index: number | undefined =
inference.richTranscriptWithoutModifiers.match(
`iara texto ${inference.richTranscriptModifiers[0]}`
)?.index;

const templatePrefix = inference.richTranscript
.slice(0, index)
.replace(/^<div>/, "");
const template = inference.richTranscript
.slice(index)
.replace(/<\/div>$/, "");
const removeDivParagraph = removeDivTags.replace(/(<\/div><div>)/, "");
this.insertTemplate(removeDivParagraph);

this.insertInference({
...inference,
...{ richTranscript: templatePrefix, richTranscriptModifiers: [] },
});
this.insertTemplate(template);

return;
}
}
Expand Down

0 comments on commit a57b874

Please sign in to comment.