mulmocast 1.1.7 → 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actions/captions.js +4 -7
- package/lib/actions/translate.d.ts +2 -2
- package/lib/actions/translate.js +2 -13
- package/lib/index.common.d.ts +1 -0
- package/lib/index.common.js +1 -0
- package/lib/index.node.d.ts +1 -0
- package/lib/index.node.js +1 -0
- package/lib/utils/const.js +1 -1
- package/lib/utils/provider2agent.js +1 -0
- package/lib/utils/string.d.ts +5 -0
- package/lib/utils/string.js +12 -0
- package/lib/utils/utils.d.ts +1 -1
- package/lib/utils/utils.js +6 -3
- package/package.json +1 -1
package/lib/actions/captions.js
CHANGED
|
@@ -2,6 +2,7 @@ import { mulmoCaptionParamsSchema } from "../types/index.js";
|
|
|
2
2
|
import { GraphAI, GraphAILogger } from "graphai";
|
|
3
3
|
import * as agents from "@graphai/vanilla";
|
|
4
4
|
import { getHTMLFile, getCaptionImagePath, getOutputStudioFilePath } from "../utils/file.js";
|
|
5
|
+
import { localizedText } from "../utils/utils.js";
|
|
5
6
|
import { renderHTMLToImage, interpolate } from "../utils/markdown.js";
|
|
6
7
|
import { MulmoStudioContextMethods, MulmoPresentationStyleMethods } from "../methods/index.js";
|
|
7
8
|
import { fileWriteAgent } from "@graphai/vanilla_node_agents";
|
|
@@ -30,14 +31,10 @@ const graph_data = {
|
|
|
30
31
|
const canvasSize = MulmoPresentationStyleMethods.getCanvasSize(context.presentationStyle);
|
|
31
32
|
const imagePath = getCaptionImagePath(context, index);
|
|
32
33
|
const template = getHTMLFile("caption");
|
|
33
|
-
|
|
34
|
-
const multiLingual = context.multiLingual;
|
|
35
|
-
if (captionParams.lang && multiLingual) {
|
|
36
|
-
return multiLingual[index].multiLingualTexts[captionParams.lang].text;
|
|
37
|
-
}
|
|
34
|
+
if (captionParams.lang && !context.multiLingual?.[index]?.multiLingualTexts?.[captionParams.lang]) {
|
|
38
35
|
GraphAILogger.warn(`No multiLingual caption found for beat ${index}, lang: ${captionParams.lang}`);
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
}
|
|
37
|
+
const text = localizedText(beat, context.multiLingual?.[index], captionParams.lang, context.studio.script.lang);
|
|
41
38
|
const htmlData = interpolate(template, {
|
|
42
39
|
caption: text,
|
|
43
40
|
width: `${canvasSize.width}`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
import type { CallbackFunction } from "graphai";
|
|
3
|
-
import { LANG,
|
|
3
|
+
import type { LANG, MulmoStudioContext } from "../types/index.js";
|
|
4
4
|
export declare const translateTextGraph: {
|
|
5
5
|
version: number;
|
|
6
6
|
nodes: {
|
|
@@ -25,7 +25,7 @@ export declare const translateTextGraph: {
|
|
|
25
25
|
};
|
|
26
26
|
splitText: {
|
|
27
27
|
agent: (namedInputs: {
|
|
28
|
-
localizedText: LocalizedText;
|
|
28
|
+
localizedText: import("../types/type.js").LocalizedText;
|
|
29
29
|
targetLang: LANG;
|
|
30
30
|
}) => string[];
|
|
31
31
|
inputs: {
|
package/lib/actions/translate.js
CHANGED
|
@@ -5,7 +5,7 @@ import { GraphAI, assert, isNull, GraphAILogger } from "graphai";
|
|
|
5
5
|
import * as agents from "@graphai/vanilla";
|
|
6
6
|
import { openAIAgent } from "@graphai/openai_agent";
|
|
7
7
|
import { fileWriteAgent } from "@graphai/vanilla_node_agents";
|
|
8
|
-
import {
|
|
8
|
+
import { splitText } from "../utils/string.js";
|
|
9
9
|
import { settings2GraphAIConfig } from "../utils/utils.js";
|
|
10
10
|
import { getMultiLingual } from "../utils/context.js";
|
|
11
11
|
import { currentMulmoScriptVersion } from "../utils/const.js";
|
|
@@ -43,18 +43,7 @@ export const translateTextGraph = {
|
|
|
43
43
|
agent: "openAIAgent",
|
|
44
44
|
},
|
|
45
45
|
splitText: {
|
|
46
|
-
agent:
|
|
47
|
-
const { localizedText, targetLang } = namedInputs;
|
|
48
|
-
// Cache
|
|
49
|
-
if (localizedText.texts) {
|
|
50
|
-
return localizedText.texts;
|
|
51
|
-
}
|
|
52
|
-
if (targetLang === "ja") {
|
|
53
|
-
return recursiveSplitJa(localizedText.text);
|
|
54
|
-
}
|
|
55
|
-
// not split
|
|
56
|
-
return [localizedText.text];
|
|
57
|
-
},
|
|
46
|
+
agent: splitText,
|
|
58
47
|
inputs: {
|
|
59
48
|
targetLang: ":targetLang",
|
|
60
49
|
localizedText: ":localizedText",
|
package/lib/index.common.d.ts
CHANGED
package/lib/index.common.js
CHANGED
package/lib/index.node.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./index.common.js";
|
|
|
2
2
|
export * from "./actions/index.js";
|
|
3
3
|
export * from "./cli/helpers.js";
|
|
4
4
|
export * from "./utils/file.js";
|
|
5
|
+
export * from "./utils/context.js";
|
|
5
6
|
export * from "./utils/ffmpeg_utils.js";
|
|
6
7
|
export * from "./methods/index.js";
|
|
7
8
|
export * from "./agents/index.js";
|
package/lib/index.node.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./index.common.js";
|
|
|
3
3
|
export * from "./actions/index.js";
|
|
4
4
|
export * from "./cli/helpers.js";
|
|
5
5
|
export * from "./utils/file.js";
|
|
6
|
+
export * from "./utils/context.js";
|
|
6
7
|
export * from "./utils/ffmpeg_utils.js";
|
|
7
8
|
export * from "./methods/index.js";
|
|
8
9
|
export * from "./agents/index.js";
|
package/lib/utils/const.js
CHANGED
|
@@ -5,7 +5,7 @@ export const imageDirName = "images";
|
|
|
5
5
|
export const cacheDirName = "cache";
|
|
6
6
|
export const pdf_modes = ["slide", "talk", "handout"];
|
|
7
7
|
export const pdf_sizes = ["letter", "a4"];
|
|
8
|
-
export const languages = ["en", "ja", "fr", "es"];
|
|
8
|
+
export const languages = ["en", "ja", "fr", "es", "de", "zh-CN", "zh-TW", "ko", "it", "pt", "ar", "hi"];
|
|
9
9
|
export const storyToScriptGenerateMode = {
|
|
10
10
|
stepWise: "step_wise",
|
|
11
11
|
oneStep: "one_step",
|
package/lib/utils/string.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LANG, LocalizedText } from "../types/index.js";
|
|
1
2
|
export declare function splitIntoSentencesJa(paragraph: string, divider: string, minimum: number): string[];
|
|
2
3
|
export declare const recursiveSplitJa: (text: string) => string[];
|
|
3
4
|
interface Replacement {
|
|
@@ -6,4 +7,8 @@ interface Replacement {
|
|
|
6
7
|
}
|
|
7
8
|
export declare function replacePairsJa(replacements: Replacement[]): (str: string) => string;
|
|
8
9
|
export declare const replacementsJa: Replacement[];
|
|
10
|
+
export declare const splitText: (namedInputs: {
|
|
11
|
+
localizedText: LocalizedText;
|
|
12
|
+
targetLang: LANG;
|
|
13
|
+
}) => string[];
|
|
9
14
|
export {};
|
package/lib/utils/string.js
CHANGED
|
@@ -56,3 +56,15 @@ export const replacementsJa = [
|
|
|
56
56
|
{ from: "%", to: "パーセント" },
|
|
57
57
|
{ from: "IPO", to: "アイピーオー" },
|
|
58
58
|
];
|
|
59
|
+
export const splitText = (namedInputs) => {
|
|
60
|
+
const { localizedText, targetLang } = namedInputs;
|
|
61
|
+
// Cache
|
|
62
|
+
if (localizedText.texts) {
|
|
63
|
+
return localizedText.texts;
|
|
64
|
+
}
|
|
65
|
+
if (targetLang === "ja") {
|
|
66
|
+
return recursiveSplitJa(localizedText.text);
|
|
67
|
+
}
|
|
68
|
+
// not split
|
|
69
|
+
return [localizedText.text];
|
|
70
|
+
};
|
package/lib/utils/utils.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare const llmPair: (_llm?: LLM, _model?: string) => {
|
|
|
9
9
|
export declare const chunkArray: <T>(array: T[], size?: number) => T[][];
|
|
10
10
|
export declare const isHttp: (fileOrUrl: string) => boolean;
|
|
11
11
|
export declare const text2hash: (input: string) => string;
|
|
12
|
-
export declare const localizedText: (beat: MulmoBeat, multiLingualData?: MulmoStudioMultiLingualData,
|
|
12
|
+
export declare const localizedText: (beat: MulmoBeat, multiLingualData?: MulmoStudioMultiLingualData, targetLang?: string, defaultLang?: string) => string;
|
|
13
13
|
export declare const sleep: (milliseconds: number) => Promise<unknown>;
|
|
14
14
|
export declare function userAssert(condition: boolean, message: string): asserts condition;
|
|
15
15
|
export declare const settings2GraphAIConfig: (settings?: Record<string, string>, env?: Record<string, string | undefined>) => ConfigDataDictionary<DefaultConfigData>;
|
package/lib/utils/utils.js
CHANGED
|
@@ -20,9 +20,12 @@ export const isHttp = (fileOrUrl) => {
|
|
|
20
20
|
export const text2hash = (input) => {
|
|
21
21
|
return crypto.createHash("sha256").update(input).digest("hex");
|
|
22
22
|
};
|
|
23
|
-
export const localizedText = (beat, multiLingualData,
|
|
24
|
-
if (
|
|
25
|
-
return
|
|
23
|
+
export const localizedText = (beat, multiLingualData, targetLang, defaultLang) => {
|
|
24
|
+
if (targetLang === defaultLang) {
|
|
25
|
+
return beat.text;
|
|
26
|
+
}
|
|
27
|
+
if (targetLang && multiLingualData?.multiLingualTexts?.[targetLang]?.text) {
|
|
28
|
+
return multiLingualData.multiLingualTexts[targetLang].text;
|
|
26
29
|
}
|
|
27
30
|
return beat.text;
|
|
28
31
|
};
|