Skip to content

Commit 91ebc7e

Browse files
authored
Merge pull request #32 from Laurian/master
alignSTTwithPadding (workaround for low word count freezing alignSTT)
2 parents 8987e60 + e1acf1c commit 91ebc7e

11 files changed

+9610
-2474
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/gallium

demo/main.bundle.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example-usage/example-usage-freeze.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// const alignSTT = require('@bbc/stt-align-node').alignSTT;
2+
const alignSTT = require("../src/index.js").alignSTT;
3+
4+
// Note: this freezes, see the example usage with padding as a workaround
5+
6+
const transcriptText = "friend to hold";
7+
8+
const transcriptSttTest = {
9+
words: [
10+
{
11+
start: 16.27,
12+
end: 16.65,
13+
text: "friend",
14+
},
15+
{
16+
text: "2",
17+
},
18+
{
19+
start: 16.74,
20+
end: 17.2,
21+
text: "held",
22+
},
23+
],
24+
};
25+
26+
const result = alignSTT(transcriptSttTest, transcriptText, 16.19, 17.2);
27+
console.log(JSON.stringify(result, null, 2));
28+
29+
/* original timings
30+
{
31+
"start": 16.27,
32+
"end": 16.65,
33+
"text": "friend"
34+
},
35+
{
36+
"start": 16.65,
37+
"end": 16.74,
38+
"text": "to"
39+
},
40+
{
41+
"start": 16.74,
42+
"end": 17.2,
43+
"text": "hold"
44+
},
45+
*/
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// const alignSTT = require('@bbc/stt-align-node').alignSTT;
2+
const alignSTT = require("../src/index.js").alignSTT;
3+
4+
const transcriptText = "friend to hold MFJrgRpKH pbTFFLsRk vRzcmnrnT";
5+
6+
const transcriptSttTest = {
7+
words: [
8+
{
9+
start: 16.27,
10+
end: 16.65,
11+
text: "friend",
12+
},
13+
{
14+
text: "2",
15+
},
16+
{
17+
start: 16.74,
18+
end: 17.2,
19+
text: "held",
20+
},
21+
{
22+
start: 17.2,
23+
end: 17.2,
24+
text: "MFJrgRpKH",
25+
},
26+
{
27+
start: 17.2,
28+
end: 17.2,
29+
text: "pbTFFLsRk",
30+
},
31+
{
32+
start: 17.2,
33+
end: 17.2,
34+
text: "vRzcmnrnT",
35+
},
36+
],
37+
};
38+
39+
const result = alignSTT(transcriptSttTest, transcriptText, 16.19, 17.2);
40+
console.log(JSON.stringify(result, null, 2));
41+
42+
/* original timings
43+
{
44+
"start": 16.27,
45+
"end": 16.65,
46+
"text": "friend"
47+
},
48+
{
49+
"start": 16.65,
50+
"end": 16.74,
51+
"text": "to"
52+
},
53+
{
54+
"start": 16.74,
55+
"end": 17.2,
56+
"text": "hold"
57+
},
58+
*/
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// const alignSTT = require('@bbc/stt-align-node').alignSTT;
2+
const alignSTT = require("../src/index.js").alignSTT;
3+
const alignSTTwithPadding = require("../src/index.js").alignSTTwithPadding;
4+
5+
const transcriptText = "friend to hold";
6+
7+
const transcriptSttTest = {
8+
words: [
9+
{
10+
start: 16.27,
11+
end: 16.65,
12+
text: "friend",
13+
},
14+
{
15+
text: "2",
16+
},
17+
{
18+
start: 16.74,
19+
end: 17.2,
20+
text: "held",
21+
},
22+
],
23+
};
24+
25+
// this freezes:
26+
// const result = alignSTT(transcriptSttTest, transcriptText, 16.19, 17.2);
27+
28+
// const start = 16.19;
29+
// const end = 17.2;
30+
// const PADLEFT = "Nwxskfsxn HHLPdJNbX KRrdghXzJ";
31+
// const PADRIGHT = "XxjzKsmwK pHcdxnFch LmLXFdCVr";
32+
33+
// const result = alignSTT(
34+
// {
35+
// words: [
36+
// ...PADLEFT.split(" ").map((text) => ({ start, end: start, text })),
37+
// ...transcriptSttTest.words,
38+
// ...PADRIGHT.split(" ").map((text) => ({ start: end, end, text })),
39+
// ],
40+
// },
41+
// `${PADLEFT} ${transcriptText} ${PADRIGHT}`,
42+
// start,
43+
// end
44+
// );
45+
46+
// console.log(JSON.stringify(result, null, 2));
47+
// console.log(
48+
// JSON.stringify(
49+
// result.slice(PADLEFT.split(" ").length, -PADRIGHT.split(" ").length),
50+
// null,
51+
// 2
52+
// )
53+
// );
54+
55+
const result2 = alignSTTwithPadding(
56+
transcriptSttTest,
57+
transcriptText,
58+
16.19,
59+
17.2
60+
);
61+
console.log(JSON.stringify(result2, null, 2));
62+
63+
/* original timings
64+
{
65+
"start": 16.27,
66+
"end": 16.65,
67+
"text": "friend"
68+
},
69+
{
70+
"start": 16.65,
71+
"end": 16.74,
72+
"text": "to"
73+
},
74+
{
75+
"start": 16.74,
76+
"end": 17.2,
77+
"text": "hold"
78+
},
79+
*/

lib/index.js

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)