shiveshnavin commited on
Commit
53a0583
·
1 Parent(s): 0188f24

Fixed Word and Group sync

Browse files
Files changed (1) hide show
  1. src/ig-reel/IGScene.tsx +23 -22
src/ig-reel/IGScene.tsx CHANGED
@@ -80,6 +80,11 @@ export const IGScene: React.FC<any> = (props: { script: any, item: any }) => {
80
  // });
81
  // }
82
  groups = splitWordsIntoGroups(arr)
 
 
 
 
 
83
  setGroups(groups)
84
 
85
 
@@ -89,12 +94,10 @@ export const IGScene: React.FC<any> = (props: { script: any, item: any }) => {
89
  return (<></>)
90
  }
91
 
92
- let curSecond = frame / fps
93
  let word = findCurrentWord(curSecond, subtitles)
94
- let group = findCurrentGroup(word, groups)
95
- if (group && item.curGroup != group) {
96
- item.curGroup = group
97
- }
98
 
99
  return (
100
  <AbsoluteFill>
@@ -103,7 +106,7 @@ export const IGScene: React.FC<any> = (props: { script: any, item: any }) => {
103
  <Title title={word?.start + ' --- ' + word?.end}></Title> */}
104
 
105
  <Title title={(word?.word || '_____')}></Title>
106
- <Title title={((item.curGroup)?.map(wod => wod.word).join(" ") || '_____')}></Title>
107
  {
108
 
109
  }
@@ -168,14 +171,14 @@ function splitWordsIntoGroups(words) {
168
  finalGroups.push(group);
169
  }
170
 
171
- return finalGroups.map(group => {
172
  return {
173
  words: group
174
  }
175
  });
176
  }
177
 
178
- function findCurrentGroup(wod, group) {
179
  if (!wod) {
180
  return
181
  }
@@ -192,14 +195,21 @@ function findCurrentGroup(wod, group) {
192
  }
193
  }
194
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  function findCurrentWord(timeSec, frames) {
196
  var t = timeSec;
197
  let wds = frames
198
- // var hits = wds.filter(function (x) {
199
- // return (t - x.start) > 0.0001 && (x.end - t) > 0.0001;
200
- // }, wds);
201
- // var currentWord = hits[0];
202
- // return currentWord
203
  for (let i = 0; i < wds.length; i++) {
204
  const x = wds[i];
205
  if (x.start && x.end && (t >= x.start && t < x.end)) {
@@ -225,15 +235,6 @@ function getGroupDuration(group, avgCps) {
225
  const SubTitleFrameGroup: React.FC<{ title?: string, color: string }> = ({ frames }) => {
226
 
227
 
228
- return (
229
- <div style={{ display: 'block' }}>
230
- {
231
- frames.map((frame) => {
232
- return <Title title={frame.word} color="#425211"></Title>
233
- })
234
- }
235
- </div>
236
- );
237
  };
238
 
239
  const Title: React.FC<{ title?: string, color?: string }> = ({ title = "test", color = "#fff" }) => {
 
80
  // });
81
  // }
82
  groups = splitWordsIntoGroups(arr)
83
+ groups.forEach((group) => {
84
+ let words = group.words;
85
+ group.start = words[0]?.start
86
+ group.end = words[words.length - 1].end
87
+ })
88
  setGroups(groups)
89
 
90
 
 
94
  return (<></>)
95
  }
96
 
97
+ let curSecond: Number = frame / fps
98
  let word = findCurrentWord(curSecond, subtitles)
99
+ let group = findCurrentGroupByTime(curSecond, groups)
100
+ item.curGroup = group
 
 
101
 
102
  return (
103
  <AbsoluteFill>
 
106
  <Title title={word?.start + ' --- ' + word?.end}></Title> */}
107
 
108
  <Title title={(word?.word || '_____')}></Title>
109
+ <Title title={((item?.curGroup?.words)?.map(wod => wod.word).join(" ") || '_____')}></Title>
110
  {
111
 
112
  }
 
171
  finalGroups.push(group);
172
  }
173
 
174
+ return finalGroups?.map(group => {
175
  return {
176
  words: group
177
  }
178
  });
179
  }
180
 
181
+ function findCurrentGroupByWord(wod: String, group) {
182
  if (!wod) {
183
  return
184
  }
 
195
  }
196
  }
197
 
198
+ function findCurrentGroupByTime(timeSec: Number, groups) {
199
+ var t = timeSec;
200
+ let wds = groups
201
+ for (let i = 0; i < wds.length; i++) {
202
+ const x = wds[i];
203
+ if (x.start != undefined && x.end != undefined && (t >= x.start && t < x.end)) {
204
+ return x
205
+ }
206
+ }
207
+ }
208
+
209
+
210
  function findCurrentWord(timeSec, frames) {
211
  var t = timeSec;
212
  let wds = frames
 
 
 
 
 
213
  for (let i = 0; i < wds.length; i++) {
214
  const x = wds[i];
215
  if (x.start && x.end && (t >= x.start && t < x.end)) {
 
235
  const SubTitleFrameGroup: React.FC<{ title?: string, color: string }> = ({ frames }) => {
236
 
237
 
 
 
 
 
 
 
 
 
 
238
  };
239
 
240
  const Title: React.FC<{ title?: string, color?: string }> = ({ title = "test", color = "#fff" }) => {