Skip to content

Commit

Permalink
feat: add assembly ai converter to our captions SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeocodes committed Oct 28, 2023
1 parent a31bd54 commit a55a3c3
Show file tree
Hide file tree
Showing 7 changed files with 1,505 additions and 7 deletions.
60 changes: 60 additions & 0 deletions src/converters/AssemblyAiConverter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { chunkArray } from "../lib/helpers";
import { WordBase } from "../lib/types";
import { IConverter } from "./IConverter";

const wordMap = (word: any): WordBase => {
return {
word: word.text,
start: word.start,
end: word.end,
confidence: word.confidence,
punctuated_word: word.text,
speaker: word.speaker,
};
};

export class AssemblyAiConverter implements IConverter {
constructor(public transcriptionData: any) {}

getLines(lineLength: number = 8): WordBase[][] {
const results = this.transcriptionData;
let content: WordBase[][] = [];

if (results.utterances) {
results.utterances.forEach((utterance: any) => {
if (utterance.words.length > lineLength) {
content.push(
...chunkArray(
utterance.words.map((w: any) => wordMap(w)),
lineLength
)
);
} else {
content.push(utterance.words.map((w: any) => wordMap(w)));
}
});
} else {
content.push(
...chunkArray(
results.words.map((w: any) => wordMap(w)),
lineLength
)
);
}

return content;
}

getHeaders(): string[] {
const output: string[] = [];

output.push("NOTE");
output.push("Transcription provided by Assembly AI");
this.transcriptionData.id ? output.push(`Id: ${this.transcriptionData.id}`) : null;
this.transcriptionData.audio_duration
? output.push(`Duration: ${this.transcriptionData.audio_duration}`)
: null;

return output;
}
}
1 change: 1 addition & 0 deletions src/converters/DeepgramConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class DeepgramConverter implements IConverter {
this.transcriptionData.metadata?.channels
? output.push(`Channels: ${this.transcriptionData.metadata?.channels}`)
: null;

return output;
}
}
1 change: 1 addition & 0 deletions src/converters/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { DeepgramConverter } from "./DeepgramConverter";
export { AssemblyAiConverter } from "./AssemblyAiConverter";
export { IConverter, isConverter } from "./IConverter";
Loading

0 comments on commit a55a3c3

Please sign in to comment.