mulmocast 1.1.8 → 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.
@@ -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
- const text = (() => {
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
- return beat.text;
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, LocalizedText, MulmoStudioContext } from "../types/index.js";
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: {
@@ -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 { recursiveSplitJa } from "../utils/string.js";
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: (namedInputs) => {
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",
@@ -1,3 +1,4 @@
1
1
  export * from "./types/index.js";
2
2
  export * from "./utils/provider2agent.js";
3
3
  export * from "./utils/const.js";
4
+ export * from "./utils/string.js";
@@ -2,3 +2,4 @@
2
2
  export * from "./types/index.js";
3
3
  export * from "./utils/provider2agent.js";
4
4
  export * from "./utils/const.js";
5
+ export * from "./utils/string.js";
@@ -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",
@@ -1,3 +1,4 @@
1
+ // node & browser
1
2
  export const provider2TTSAgent = {
2
3
  nijivoice: {
3
4
  agentName: "ttsNijivoiceAgent",
@@ -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 {};
@@ -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
+ };
@@ -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, lang?: string) => string;
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>;
@@ -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, lang) => {
24
- if (lang && multiLingualData?.multiLingualTexts?.[lang]?.text) {
25
- return multiLingualData.multiLingualTexts[lang].text;
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mulmocast",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "lib/index.node.js",