( segment: TranscriptSegment, topics: Topic[] | undefined )
| 62 | } |
| 63 | |
| 64 | function findTopicForSegment( |
| 65 | segment: TranscriptSegment, |
| 66 | topics: Topic[] | undefined |
| 67 | ): string | undefined { |
| 68 | if (!topics?.length) { |
| 69 | return undefined; |
| 70 | } |
| 71 | |
| 72 | const start = segment.start; |
| 73 | const end = segment.start + segment.duration; |
| 74 | |
| 75 | for (const topic of topics) { |
| 76 | const overlaps = topic.segments.some((segmentRange) => { |
| 77 | const overlapStart = Math.max(start, segmentRange.start); |
| 78 | const overlapEnd = Math.min(end, segmentRange.end); |
| 79 | return overlapEnd - overlapStart > Math.min(segment.duration, segmentRange.end - segmentRange.start) * 0.3; |
| 80 | }); |
| 81 | |
| 82 | if (overlaps) { |
| 83 | return topic.title ?? undefined; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return undefined; |
| 88 | } |
| 89 | |
| 90 | function sanitizeText(text: string): string { |
| 91 | return text.replace(/\s+/g, ' ').trim(); |
no outgoing calls
no test coverage detected