Skip to content

Commit

Permalink
Abstract out maxCharsAllowed
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Feb 27, 2024
1 parent d7c4648 commit 2861b7a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/src/data/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,25 @@ export function charsPerSec(language: string) {
const perSec =
data[language] ||
/** fallback to max avg */
Math.max(...Object.values(charsPerSec));
/** allow for some variance around avg */
Math.max(...Object.values(data));
return perSec;
}

/** Estimate how many characters would cause an overflow of narration time */
export function maxCharsAllowed(language: string, start: number, end: number): number {
const mult_const: number = 1.1;
const time_buff: number = 0.5;
return mult_const * (charsPerSec(language) * (end - start + time_buff));
}

/** get max length for entry translation text */
export function translationMax(
{ startingTranslation, startingOriginal, timeRange }: Entry,
language: string,
) {
const [start = 0, end = 0] = timeRange || [];
/** for entries with time range, i.e. captions */
if (start && end) return charsPerSec(language) * (end - start);
if (start && end) return maxCharsAllowed(language, start, end);
/** for entries without a time range, i.e. title and description */ else
return (
startingTranslation.length * 1.5 ||
Expand Down

0 comments on commit 2861b7a

Please sign in to comment.