Skip to content

Commit 718511a

Browse files
committed
added transcript word getter
1 parent 7349986 commit 718511a

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@diffusionstudio/core",
33
"private": false,
4-
"version": "1.1.1",
4+
"version": "1.1.2",
55
"type": "module",
66
"description": "Build bleeding edge video processing applications",
77
"files": [

src/models/transcript.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@ describe('Transcript tests', () => {
188188
expect(subset.groups.at(0)?.words.at(-1)?.stop.seconds).toBe(10.5);
189189
});
190190

191+
it('should be able to get all words', () => {
192+
const transcript = new Transcript([
193+
new WordGroup([new Word('Lorem', 0, 1e3)]),
194+
new WordGroup([new Word('Ipsum', 2e3, 3e3)]),
195+
]);
196+
197+
expect(transcript.words.length).toBe(2);
198+
expect(transcript.words[0].text).toBe('Lorem');
199+
expect(transcript.words[1].text).toBe('Ipsum');
200+
expect(transcript.words[0]).toBeInstanceOf(Word);
201+
expect(transcript.words[1]).toBeInstanceOf(Word);
202+
});
203+
191204
it('should generated a cloned transcript with the max available number of words', () => {
192205
const transcript = new Transcript([
193206
new WordGroup([new Word('Lorem', 4e3, 6e3), new Word('Ipsum', 9e3, 11e3)]),

src/models/transcript.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export class Transcript implements Serializer {
2525
return this.groups.map(({ text }) => text).join(' ');
2626
}
2727

28+
public get words(): Word[] {
29+
return this.groups.flatMap(({ words }) => words);
30+
}
31+
2832
public constructor(groups: WordGroup[] = [], language = Language.en) {
2933
this.groups = groups;
3034
this.language = language;

0 commit comments

Comments
 (0)