AI Personal Learning
and practical guidance
豆包Marscode1

Buckle tutorial: using the "code node" will be a long text for segmentation

In learning to automate the process of generating novels, segmenting long texts and then generating shot scripts in response to the segments is an important part of the work.

扣子教程:使用”代码节点“将长文本进行分段处理-1


 

This method reduces the number of picture images generated, but requires a matching sentence-by-sentence voiceover generation tool. This ensures that the picture and voice are consistent.

A lot of tools to first import the SRT file, in relying on the SRT file in the Chinese version of the time point to generate the screen, so there is noLong text segmentation necessary, just use the text directly to generate audio and SRT for use.

Before for long text segmentation has been using ChatGPT input long text, output CSV format text way. This is not only tired, the output is not too stable, especially when the context is too long. Of course, this approach also has an advantage: it is possible to put theCombine similarly worded text into one paragraphThe

 

扣子教程:使用代码节点将长文本分句处理-1

 

Benefits of using buttons:

  1. You can add "Text Segmentation" to subsequent workflows to complete the scripting process in one step. (Not explained in this article)
  2. Code segmentation is more stable and efficient in execution, and invalid characters can be filtered as required.

 

workflow

 

1. Create a workflow and add code nodes

扣子教程:使用”代码节点“将长文本进行分段处理-1

 

扣子教程:使用”代码节点“将长文本进行分段处理-1

 

2. Enter the code

async function main({ params }: { params: { input: string } }): Promise<{ content: string, rows: string[] }> {

    // 检查 params 和 input 是否存在

    const input = params?.input ?? "";

    // 分割输入文本

    const lines = input.split('\n');

    // 存储处理后的行

    const rows: string[] = [];

    // 处理每一行

    for (let i = 0; i < lines.length; i++) {

        const line = lines[i].trim();

        // 如果行长度大于20,直接加入结果中

        if (line && line.length > 20) {

            rows.push(line);

        } else if (line.length > 0) {

            // 如果当前行长度小于等于20且非空,合并到前一行(如果存在)

            if (rows.length > 0) {

                rows[rows.length - 1] += ' ' + line;

            } else {

                // 如果 rows 为空(即第一行),直接添加该行

                rows.push(line);

            }

        }

    }

    // 返回结果对象

    return {

        content: input, // 返回原始输入内容

        rows: rows,     // 返回处理后的行数据

    };

}

Note: Single lines of text will merge and parallelize if they are too short. You can use ChatGPT to add more filtering features, such as filtering special characters.

 

3. Code node complete configuration

扣子教程:使用”代码节点“将长文本进行分段处理-1

 

4. Link to end node

扣子教程:使用”代码节点“将长文本进行分段处理-1

 

5. Create a Bot

扣子教程:使用”代码节点“将长文本进行分段处理-1

 

6. Select Single Agent Mode

扣子教程:使用”代码节点“将长文本进行分段处理-1

 

7. Add the workflow published in step 4

扣子教程:使用”代码节点“将长文本进行分段处理-1

 

8. Copy the output

扣子教程:使用”代码节点“将长文本进行分段处理-1

 

9. randomly find a JOSN to EXCEL method (search for JSON to EXCEL)

扣子教程:使用”代码节点“将长文本进行分段处理-1

 

10. Finally: you will get a formatted EXCEL

扣子教程:使用”代码节点“将长文本进行分段处理-1

 

concluding remarks

In fact, many AI drawing programs have this feature, usually for a fee, but certain programs allow importing full script files to generate images for free.

Subsequent addition of the Generate Screen Cue Words node will result in a more complete screen script EXCEL.

Why don't you make a full workflow? Because the follow-up is unsustainable for fear of paying for it.

May not be reproduced without permission:Chief AI Sharing Circle " Buckle tutorial: using the "code node" will be a long text for segmentation
en_USEnglish