├── .gitignore ├── MaoKenWangXingYuan.ttf ├── README.md ├── Scripts ├── Activate.ps1 ├── activate ├── activate.bat ├── deactivate.bat ├── easy_install-3.7.exe ├── easy_install.exe ├── edge-playback.exe ├── edge-tts.exe ├── f2py.exe ├── flask.exe ├── gtts-cli.exe ├── imageio_download_bin.exe ├── imageio_remove_bin.exe ├── nltk.exe ├── normalizer.exe ├── pip.exe ├── pip3.10.exe ├── pip3.7.exe ├── pip3.exe ├── python.exe ├── pythonw.exe └── tqdm.exe ├── app.py ├── config.py ├── content.txt ├── deffer.py ├── index.html ├── main.py ├── pyvenv.cfg ├── requirements.txt ├── show.png ├── show2.png ├── start.bat └── test.py /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | 3 | -------------------------------------------------------------------------------- /MaoKenWangXingYuan.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/MaoKenWangXingYuan.ttf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # textsToVideo 2 | 3 | ![展示](./show.png) 4 | ![展示](./show2.png) 5 | 6 | 7 | [演示视频](https://www.bilibili.com/video/BV1Jj411e7XK/) 8 | 9 | ## 小说推文生成神器 10 | 11 | 12 | [使用视频](https://www.bilibili.com/video/BV1Au4y1W7qz/) 13 | 14 | 使用stable diffusion api生成图片,结合python的一系列对媒体操作的库,生成十分简单的小说推文. 15 | 16 | **喜欢的话请给我一个star** 17 | 18 | 19 | 20 | ## 项目介绍 21 | 22 | - 这个项目涉及了多种技术和工具的使用,具体包括: 23 | - 自然语言处理(NLP):利用正则表达式、分词等技术对文本进行处理和分割,以及使用 NLTK 库进行词性标注和停用词过滤等操作。 24 | - 文本分割:使用正则表达式和分割符号对长文本进行分割成短段落,便于后续处理。 25 | - 语音合成:利用 gTTS(Google Text-to-Speech)和 edge-tts 等工具将文本内容转换成语音文件。在 edge-tts 中,还使用了 subprocess 调用外部命令进行语音合成。 26 | - 图像处理:使用 PIL(Python Imaging Library)和 moviepy 等库将文本内容转换成图片,用于后续视频生成。 27 | - 视频生成:利用 moviepy 库将语音文件和图片合成为视频,生成以文本内容为基础的视频内容。 28 | - 内容翻译:使用百度翻译 API 对文本内容进行翻译,实现中文文本到英文文本的翻译功能。 29 | - 关键词提取:使用 TF-IDF 算法对文本中的关键词进行提取,帮助理解文本的主题和内容。 30 | - 文件操作:利用 os 和 shutil 等库对文件进行操作,包括创建文件夹、删除文件等功能。 31 | - 网络请求:使用 requests 库进行 HTTP 请求,与外部服务进行数据交互,如使用百度翻译 API 进行文本翻译。 32 | - 这些技术和工具的综合应用,实现了将文本转换成多种多媒体内容的功能,丰富了文本内容的表现形式,提升了用户体验。 33 | 34 | 35 | 36 | 37 | 38 | ## 使用教程( windows10 ) 39 | 40 | 1. 安装 python Python 3.7.9 41 | 2. 安装依赖`pip install -r requirements.txt` 42 | 3. 安装[Imagemagick] 并且添加到环境变量 43 | > 参考: 44 | > (https://blog.csdn.net/popboy29/article/details/135587838) (https://zhuanlan.zhihu.com/p/687794898) 45 | 4. 在这个网站 https://github.com/BtbN/FFmpeg-Builds/releases?page=3 46 | 下载 Auto-Build 2023-09-30 的 ffmpeg-N-112236-g2cb2465cc7-win64-gpl.zip 47 | 解压之后 将`bin`目录下的三个 `exe` 文件拷贝到本项目的根目录 48 | 5. 配置`stablediffusion api` : 在`deffer.py`中的指定`stable_diff_api` , 演示中使用的是 2023年10月份的 搭建的`stable_diff` 49 | 6. 点击`start.bat`运行 50 | 51 | 52 | 53 | 54 | 55 | 56 | ## 注意 57 | 为了方便大家调试,代码中使用的是我本人的百度翻译api,后期可能失效 58 | 59 | 60 | 61 | 62 | # English Version 63 | 64 | ## Novel tweet generation artifact 65 | 66 | [Demo Video](https://www.bilibili.com/video/BV1Au4y1W7qz/) 67 | Generate images using the stable diffusion API, combined with a series of media operation libraries in Python, to generate very simple novel tweets 68 | 69 | **If you like, please give me a star** 70 | 71 | 72 | 73 | 74 | ## Project Introduction 75 | 76 | -This project involves the use of various technologies and tools, including: 77 | -Natural Language Processing (NLP): Using techniques such as regular expressions and word segmentation to process and segment text, as well as using the NLTK library for part of speech tagging and stop word filtering. 78 | -Text segmentation: Using regular expressions and segmentation symbols to segment long text into short paragraphs for easier subsequent processing. 79 | -Speech synthesis: Using tools such as gTTS (Google Text to Speech) and edge ts to convert text content into speech files. In edge tts, subprocess is also used to call external commands for speech synthesis. 80 | -Image processing: Use libraries such as PIL (Python Imaging Library) and Moviepy to convert text content into images for subsequent video generation. 81 | -Video generation: Using the Moviepy library to synthesize voice files and images into videos, generating video content based on text content. 82 | -Content translation: Use Baidu Translate API to translate text content, achieving the translation function from Chinese text to English text. 83 | -Keyword extraction: Use TF-IDF algorithm to extract keywords from text, helping to understand the theme and content of the text. 84 | -File operation: Use libraries such as OS and SHUTIL to operate files, including functions such as creating folders and deleting files. 85 | -Network request: Use the requests library for HTTP requests, interact with external services for data, such as using Baidu Translate API for text translation. 86 | -The comprehensive application of these technologies and tools has achieved the function of converting text into various multimedia content, enriched the expression forms of text content, and improved the user experience. 87 | 88 | 89 | 90 | 91 | ## User Guide 92 | 93 | 1. Install Python 3.7.9 94 | 2. Install Dependencies `pip install -r requirements.txt` 95 | 3. Install [Imagemagick] and add it to the environment variable 96 | > 参考: 97 | > ( https://blog.csdn.net/popboy29/article/details/135587838 ) ( https://zhuanlan.zhihu.com/p/687794898 ) 98 | 4. Configure the `stablediffusion api` : specify the `Stable_diff_api` in `deffer.py` 99 | 5. Click on `start.bat` to run 100 | 101 | 102 | 103 | 104 | ## Attention 105 | 106 | For the convenience of debugging, I am using my own Baidu Translate API in the code, which may become invalid in the future 107 | 108 | -------------------------------------------------------------------------------- /Scripts/Activate.ps1: -------------------------------------------------------------------------------- 1 | function global:deactivate ([switch]$NonDestructive) { 2 | # Revert to original values 3 | if (Test-Path function:_OLD_VIRTUAL_PROMPT) { 4 | copy-item function:_OLD_VIRTUAL_PROMPT function:prompt 5 | remove-item function:_OLD_VIRTUAL_PROMPT 6 | } 7 | 8 | if (Test-Path env:_OLD_VIRTUAL_PYTHONHOME) { 9 | copy-item env:_OLD_VIRTUAL_PYTHONHOME env:PYTHONHOME 10 | remove-item env:_OLD_VIRTUAL_PYTHONHOME 11 | } 12 | 13 | if (Test-Path env:_OLD_VIRTUAL_PATH) { 14 | copy-item env:_OLD_VIRTUAL_PATH env:PATH 15 | remove-item env:_OLD_VIRTUAL_PATH 16 | } 17 | 18 | if (Test-Path env:VIRTUAL_ENV) { 19 | remove-item env:VIRTUAL_ENV 20 | } 21 | 22 | if (!$NonDestructive) { 23 | # Self destruct! 24 | remove-item function:deactivate 25 | } 26 | } 27 | 28 | deactivate -nondestructive 29 | 30 | $env:VIRTUAL_ENV="C:\Users\lgh\project\textsToVideo" 31 | 32 | if (! $env:VIRTUAL_ENV_DISABLE_PROMPT) { 33 | # Set the prompt to include the env name 34 | # Make sure _OLD_VIRTUAL_PROMPT is global 35 | function global:_OLD_VIRTUAL_PROMPT {""} 36 | copy-item function:prompt function:_OLD_VIRTUAL_PROMPT 37 | function global:prompt { 38 | Write-Host -NoNewline -ForegroundColor Green '(textsToVideo) ' 39 | _OLD_VIRTUAL_PROMPT 40 | } 41 | } 42 | 43 | # Clear PYTHONHOME 44 | if (Test-Path env:PYTHONHOME) { 45 | copy-item env:PYTHONHOME env:_OLD_VIRTUAL_PYTHONHOME 46 | remove-item env:PYTHONHOME 47 | } 48 | 49 | # Add the venv to the PATH 50 | copy-item env:PATH env:_OLD_VIRTUAL_PATH 51 | $env:PATH = "$env:VIRTUAL_ENV\Scripts;$env:PATH" 52 | -------------------------------------------------------------------------------- /Scripts/activate: -------------------------------------------------------------------------------- 1 | # This file must be used with "source bin/activate" *from bash* 2 | # you cannot run it directly 3 | 4 | deactivate () { 5 | # reset old environment variables 6 | if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then 7 | PATH="${_OLD_VIRTUAL_PATH:-}" 8 | export PATH 9 | unset _OLD_VIRTUAL_PATH 10 | fi 11 | if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then 12 | PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}" 13 | export PYTHONHOME 14 | unset _OLD_VIRTUAL_PYTHONHOME 15 | fi 16 | 17 | # This should detect bash and zsh, which have a hash command that must 18 | # be called to get it to forget past commands. Without forgetting 19 | # past commands the $PATH changes we made may not be respected 20 | if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then 21 | hash -r 22 | fi 23 | 24 | if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then 25 | PS1="${_OLD_VIRTUAL_PS1:-}" 26 | export PS1 27 | unset _OLD_VIRTUAL_PS1 28 | fi 29 | 30 | unset VIRTUAL_ENV 31 | if [ ! "${1:-}" = "nondestructive" ] ; then 32 | # Self destruct! 33 | unset -f deactivate 34 | fi 35 | } 36 | 37 | # unset irrelevant variables 38 | deactivate nondestructive 39 | 40 | VIRTUAL_ENV="C:\Users\lgh\project\textsToVideo" 41 | export VIRTUAL_ENV 42 | 43 | _OLD_VIRTUAL_PATH="$PATH" 44 | PATH="$VIRTUAL_ENV/Scripts:$PATH" 45 | export PATH 46 | 47 | # unset PYTHONHOME if set 48 | # this will fail if PYTHONHOME is set to the empty string (which is bad anyway) 49 | # could use `if (set -u; : $PYTHONHOME) ;` in bash 50 | if [ -n "${PYTHONHOME:-}" ] ; then 51 | _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}" 52 | unset PYTHONHOME 53 | fi 54 | 55 | if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then 56 | _OLD_VIRTUAL_PS1="${PS1:-}" 57 | if [ "x(textsToVideo) " != x ] ; then 58 | PS1="(textsToVideo) ${PS1:-}" 59 | else 60 | if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then 61 | # special case for Aspen magic directories 62 | # see http://www.zetadev.com/software/aspen/ 63 | PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1" 64 | else 65 | PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1" 66 | fi 67 | fi 68 | export PS1 69 | fi 70 | 71 | # This should detect bash and zsh, which have a hash command that must 72 | # be called to get it to forget past commands. Without forgetting 73 | # past commands the $PATH changes we made may not be respected 74 | if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then 75 | hash -r 76 | fi 77 | -------------------------------------------------------------------------------- /Scripts/activate.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem This file is UTF-8 encoded, so we need to update the current code page while executing it 4 | for /f "tokens=2 delims=:." %%a in ('"%SystemRoot%\System32\chcp.com"') do ( 5 | set _OLD_CODEPAGE=%%a 6 | ) 7 | if defined _OLD_CODEPAGE ( 8 | "%SystemRoot%\System32\chcp.com" 65001 > nul 9 | ) 10 | 11 | set VIRTUAL_ENV=C:\Users\lgh\project\textsToVideo 12 | 13 | if not defined PROMPT set PROMPT=$P$G 14 | 15 | if defined _OLD_VIRTUAL_PROMPT set PROMPT=%_OLD_VIRTUAL_PROMPT% 16 | if defined _OLD_VIRTUAL_PYTHONHOME set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME% 17 | 18 | set _OLD_VIRTUAL_PROMPT=%PROMPT% 19 | set PROMPT=(textsToVideo) %PROMPT% 20 | 21 | if defined PYTHONHOME set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME% 22 | set PYTHONHOME= 23 | 24 | if defined _OLD_VIRTUAL_PATH set PATH=%_OLD_VIRTUAL_PATH% 25 | if not defined _OLD_VIRTUAL_PATH set _OLD_VIRTUAL_PATH=%PATH% 26 | 27 | set PATH=%VIRTUAL_ENV%\Scripts;%PATH% 28 | 29 | :END 30 | if defined _OLD_CODEPAGE ( 31 | "%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul 32 | set _OLD_CODEPAGE= 33 | ) 34 | -------------------------------------------------------------------------------- /Scripts/deactivate.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if defined _OLD_VIRTUAL_PROMPT ( 4 | set "PROMPT=%_OLD_VIRTUAL_PROMPT%" 5 | ) 6 | set _OLD_VIRTUAL_PROMPT= 7 | 8 | if defined _OLD_VIRTUAL_PYTHONHOME ( 9 | set "PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%" 10 | set _OLD_VIRTUAL_PYTHONHOME= 11 | ) 12 | 13 | if defined _OLD_VIRTUAL_PATH ( 14 | set "PATH=%_OLD_VIRTUAL_PATH%" 15 | ) 16 | 17 | set _OLD_VIRTUAL_PATH= 18 | 19 | set VIRTUAL_ENV= 20 | 21 | :END 22 | -------------------------------------------------------------------------------- /Scripts/easy_install-3.7.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/easy_install-3.7.exe -------------------------------------------------------------------------------- /Scripts/easy_install.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/easy_install.exe -------------------------------------------------------------------------------- /Scripts/edge-playback.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/edge-playback.exe -------------------------------------------------------------------------------- /Scripts/edge-tts.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/edge-tts.exe -------------------------------------------------------------------------------- /Scripts/f2py.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/f2py.exe -------------------------------------------------------------------------------- /Scripts/flask.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/flask.exe -------------------------------------------------------------------------------- /Scripts/gtts-cli.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/gtts-cli.exe -------------------------------------------------------------------------------- /Scripts/imageio_download_bin.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/imageio_download_bin.exe -------------------------------------------------------------------------------- /Scripts/imageio_remove_bin.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/imageio_remove_bin.exe -------------------------------------------------------------------------------- /Scripts/nltk.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/nltk.exe -------------------------------------------------------------------------------- /Scripts/normalizer.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/normalizer.exe -------------------------------------------------------------------------------- /Scripts/pip.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/pip.exe -------------------------------------------------------------------------------- /Scripts/pip3.10.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/pip3.10.exe -------------------------------------------------------------------------------- /Scripts/pip3.7.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/pip3.7.exe -------------------------------------------------------------------------------- /Scripts/pip3.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/pip3.exe -------------------------------------------------------------------------------- /Scripts/python.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/python.exe -------------------------------------------------------------------------------- /Scripts/pythonw.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/pythonw.exe -------------------------------------------------------------------------------- /Scripts/tqdm.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/Scripts/tqdm.exe -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import * 2 | import os 3 | from main import * 4 | from threading import* 5 | 6 | 7 | app = Flask(__name__,static_folder="", template_folder="") 8 | 9 | 10 | @app.route('/') 11 | def index(): 12 | # 获取图片文件夹中的文件列表 13 | print(os.getcwd()) 14 | split_txt_files = os.listdir('split_txt') 15 | split_txt_files_cont=len(split_txt_files) 16 | text_contents=[] 17 | for item in range(1, split_txt_files_cont + 1): 18 | with open('split_txt/' + str(item) + '.txt', 'r', encoding='utf-8') as file: 19 | text_content = file.read() 20 | text_contents.append(text_content) 21 | return render_template('index.html', split_txt_files_cont=split_txt_files_cont,text_contents=text_contents) 22 | 23 | 24 | 25 | @app.route('/delete_folder_fileser') 26 | def delete_folder_fileser(): 27 | delete_folder_files('split_txt') 28 | delete_folder_files('pictures') 29 | delete_folder_files('tts') 30 | # delete_folder_files('video') 31 | return redirect(url_for('index')) 32 | 33 | @app.route('/make_texter') 34 | def make_texter(): 35 | thread = Thread(target=make_text) 36 | thread.start() 37 | return redirect(url_for('index')) 38 | 39 | @app.route('/make_ttser') 40 | def make_ttser(): 41 | thread = Thread(target=make_tts) 42 | thread.start() 43 | return redirect(url_for('index')) 44 | 45 | 46 | @app.route('/make_picer') 47 | def make_picer(): 48 | thread = Thread(target=make_pic) 49 | thread.start() 50 | return redirect(url_for('index')) 51 | 52 | 53 | @app.route('/make_movieer') 54 | def make_movieer(): 55 | thread = Thread(target=make_movie) 56 | thread.start() 57 | return redirect(url_for('index')) 58 | 59 | # @app.route('/re_make_picer/') 60 | # def re_make_picer(id): 61 | # thread = Thread(target=re_make_pic, args=(id,)) 62 | # thread.start() 63 | # return redirect(url_for('index')) 64 | 65 | 66 | @app.route('/re_make_picer/') 67 | def re_make_picer(id): 68 | thread = Thread(target=re_make_pic, args=(id,)) 69 | thread.start() 70 | 71 | if request.headers.get('X-Requested-With') == 'XMLHttpRequest': 72 | return 'Success' 73 | 74 | return render_template('index.html') 75 | 76 | 77 | 78 | 79 | @app.route('/open_file_contenter') 80 | def open_file_contenter(): 81 | thread = Thread(target=open_file_content) 82 | thread.start() 83 | return redirect(url_for('index')) 84 | 85 | 86 | 87 | @app.route('/open_floder_videoer') 88 | def open_floder_videoer(): 89 | thread = Thread(target=open_floder_video) 90 | thread.start() 91 | return redirect(url_for('index')) 92 | 93 | 94 | 95 | @app.route('/open_floder_picer') 96 | def open_floder_picer(): 97 | thread = Thread(target=open_floder_pic) 98 | thread.start() 99 | return redirect(url_for('index')) 100 | 101 | 102 | if __name__ == '__main__': 103 | app.run(debug=True) 104 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | Stable_diff_api="http://192.168.101.13:7861" 2 | import os 3 | # os.environ["IMAGEMAGICK_BINARY"] = r"C:\Program Files\ImageMagick-7.1.1-Q16-HDRI\magick.exe" 4 | Stable_diff_conf={ 5 | 6 | } 7 | 8 | 9 | ADDER_PROMOTE="" 10 | 11 | # 数组从1开始 12 | 13 | 14 | 15 | # payload = { 16 | # "enable_hr": false, 17 | # "denoising_strength": 0, 18 | # "firstphase_width": 0, 19 | # "firstphase_height": 0, 20 | # "hr_scale": 2, 21 | # "hr_upscaler": "string", 22 | # "hr_second_pass_steps": 0, 23 | # "hr_resize_x": 0, 24 | # "hr_resize_y": 0, 25 | # "prompt": "", # 提示词 26 | # "styles": [ 27 | # "string" 28 | # ], 29 | # "seed": -1, 30 | # "subseed": -1, 31 | # "subseed_strength": 0, 32 | # "seed_resize_from_h": -1, 33 | # "seed_resize_from_w": -1, 34 | # "sampler_name": "string", 35 | # "batch_size": 1, 36 | # "n_iter": 1, 37 | # "steps": 50, 38 | # "cfg_scale": 7, 39 | # "width": 512, 40 | # "height": 512, 41 | # "restore_faces": false, 42 | # "tiling": false, 43 | # "do_not_save_samples": false, 44 | # "do_not_save_grid": false, 45 | # "negative_prompt": "string", # 负面提示词 46 | # "eta": 0, 47 | # "s_churn": 0, 48 | # "s_tmax": 0, 49 | # "s_tmin": 0, 50 | # "s_noise": 1, 51 | # "override_settings": {}, 52 | # "override_settings_restore_afterwards": true, 53 | # "script_args": [], 54 | # "sampler_index": "Euler", 55 | # "script_name": "string", 56 | # "send_images": true, 57 | # "save_images": false, 58 | # "alwayson_scripts": {} 59 | # } 60 | -------------------------------------------------------------------------------- /content.txt: -------------------------------------------------------------------------------- 1 | “老板,活捉的人已经交代是什么人偷袭我们了,这是他交代的内容。”一名WZ公司警衞队成员,把一份文件交到了许秋风的手中。 2 | 3 | 他正在接受医生的包扎,今天在从巴林国回来的时候,私人飞机受到了不明组织的攻击。对方的势力不小,连战斗机都开了过来,他的飞机都给击落,在警衞队拼着命的保护才成功逃离。 4 | 5 | 虽然受了伤,但是和阵亡的几十人相比,他这点伤根本不了算什么。 6 | 7 | 在许秋风看文件的时候,警衞员讲道:“老板,副队长不行了。” 8 | 9 | “嗯?”许秋风停了一下,抬头看着他,警衞队副队长竟然受了这么重的伤? 10 | 11 | 等他来到抢救室,看到了躺在急救床上,下身已经被炸断,上身只剩一只手,内脏都外露的副队长。 12 | 13 | 医生走了过来,低声讲道:“老板,副队长撑不了多久了。现在只能暂时延长她的生命,可最多也就是几十分钟,就算是请世界上最好的医疗队回来,也不可能治活她,伤得太重了。” 14 | 15 | 许秋风一声不吭的走了过去,拉住她剩下的那只手,露出个温柔的笑容,“FX001,你做得很好,我安全了。” 16 | 17 | 床上的人缓缓张开了眼睛,有些无神地看着他,露出了个笑容,“老板,我的任务完成了,以后恐怕不能再保护你了。” 18 | 19 | “我有个任务想交给你,是个有去无回的任务。”许秋风却不在意地讲道。 20 | 21 | FX001愣了一下,“老板,我快死了。” 22 | 23 | “你死了才能去完成这个任务,我得到个情报,有个地方似乎在用人脑做生化武器。这让我很为难,这种武器我们并没有,我想要一个人打入内部。一直没有合适的人选,因为那人必须先死掉。”许秋风保持着微笑,就像在讲情话般温柔。 24 | 25 | “到了这个地步,你还要信任我?”FX001问道。 26 | 27 | “是的,我相信你能够做到,从不失信以人不正是你的性格吗?” 28 | 29 | “我只能尽量完成。” 30 | 31 | 许秋风拉着她的手,一直盯着她的眼睛,“不,必须是全力以赴,我相信它们会刻在你的灵魂中。就算你忘了,身体也会去完成。因为你是最好的警衞队长,FX001。” 32 | 33 | FX001沉默了一会,才讲道:“我明白了。” 34 | 35 | “我现在要送你过去,你忍着点。”许秋风手抬起来,旁边的警衞把枪拔了出来递到了他的手上。 36 | 37 | 他把枪口顶在了FX001的胸口,淡淡地笑道:“再见。” 38 | 39 | “再见……” 40 | 41 | 砰! 42 | 43 | 一天后。 44 | 45 | 无人无聊的自动输入着新送来的大脑,觉得每一个都是那么的无用,难道就没有好点的人吗? 46 | 47 | 突然,一个大脑的消息让他停住了,“WZ公司警衞,来源:走私。”抱着一丝兴趣,他飞快的扫描了这个大脑 -------------------------------------------------------------------------------- /deffer.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | import math 3 | import os 4 | import re 5 | import shutil 6 | import subprocess 7 | import requests 8 | import json 9 | import base64 10 | import random 11 | import string 12 | import time 13 | from gtts import gTTS 14 | from moviepy.editor import * 15 | from pydub import AudioSegment 16 | from PIL import Image 17 | import edge_tts 18 | from sklearn.feature_extraction.text import TfidfVectorizer 19 | from sklearn.metrics.pairwise import cosine_similarity 20 | import hashlib 21 | from nltk import * 22 | import subprocess 23 | from nltk.corpus import stopwords 24 | from nltk.tokenize import word_tokenize 25 | # nltk.download('punkt') 26 | # nltk.download('stopwords') 27 | # nltk.download('averaged_perceptron_tagger') 28 | from moviepy.editor import ImageClip, VideoFileClip 29 | from config import * 30 | 31 | 32 | 33 | # 分割内容 34 | # 保存到文件 35 | # 文本 36 | # 37 | def spliter(novel_text): 38 | # 创建一个名为"txt文件夹"的文件夹(如果不存在) 39 | if not os.path.exists("split_txt"): 40 | os.makedirs("split_txt") 41 | 42 | novel_text=clip_to_whole(novel_text) 43 | # 按句子分割文本 44 | sentences = re.split(r'(?<=[.。!?])', novel_text) 45 | 46 | # 合并相邻的句子 47 | merged_sentences = [] 48 | current_sentence = "" 49 | for sentence in sentences: 50 | current_sentence += sentence 51 | if len(current_sentence) > 50: # 合并后的句子长度超过50个字符时分割 52 | merged_sentences.append(current_sentence) 53 | current_sentence = "" 54 | if current_sentence: 55 | merged_sentences.append(current_sentence) 56 | 57 | # 使用TF-IDF计算句子相似度 58 | tfidf_vectorizer = TfidfVectorizer() 59 | tfidf_matrix = tfidf_vectorizer.fit_transform(merged_sentences) 60 | similarities = cosine_similarity(tfidf_matrix) 61 | 62 | similarity_threshold=0.7 63 | 64 | # 将相似句子组合成场景 65 | scenes = [] 66 | current_scene = [] 67 | for i in range(len(merged_sentences)): 68 | if not current_scene: 69 | current_scene.append(i) 70 | else: 71 | if similarities[current_scene[0]][i] > similarity_threshold: 72 | current_scene.append(i) 73 | else: 74 | scenes.append(current_scene) 75 | current_scene = [i] 76 | 77 | # 保存每个段落到文件 78 | for i, scene in enumerate(scenes): 79 | scene_sentences = [merged_sentences[i] for i in scene] 80 | scene_text = "".join(scene_sentences) 81 | filename = f"split_txt/{i+1}.txt" 82 | with open(filename, 'w', encoding='utf-8') as scene_file: 83 | scene_file.write(scene_text) 84 | print(scene_text) 85 | 86 | # 处理最后一段文本,否则会有丢失的情况 87 | if current_scene: 88 | last_scene_text = "".join([merged_sentences[i] for i in current_scene]) 89 | last_filename = f"split_txt/{len(scenes)+1}.txt" 90 | with open(last_filename, 'w', encoding='utf-8') as last_scene_file: 91 | last_scene_file.write(last_scene_text) 92 | print(last_scene_text) 93 | 94 | 95 | 96 | # add 97 | def clip_to_whole(content): 98 | res_content = content.replace('"', "'").strip().replace("\n", "") 99 | return res_content 100 | 101 | 102 | 103 | # 只是去掉了换行,二维 104 | def text_clip_to_whole(contents): 105 | res_contents = [] 106 | for content in contents: 107 | res_content=clip_to_whole(content) 108 | res_contents.append(res_content) 109 | return res_contents 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | # 返回的是二维数组 118 | def text_to_voice(contents): 119 | try: 120 | shutil.rmtree('./tts') 121 | os.mkdir('./tts') 122 | except: 123 | pass 124 | 125 | voice = [] 126 | 127 | first=1 128 | for lines in contents: 129 | filenames = [] 130 | second=1 131 | for line in lines: 132 | # 执行相应的处理操作,例如: 133 | # line = line.replace('"', "'").strip().replace("\n", "") 134 | # filename = gtts(line) 135 | filename = _edge_tts(first, second, line) 136 | savefile(line,'./tts/'+str(first)+'.'+str(second)+'.txt') 137 | filenames.append(filename) 138 | second+=1 139 | first += 1 140 | voice.append(filenames) 141 | 142 | 143 | # 获取音频文件名 144 | # 0 145 | # 二维 146 | # def loadvoice(): 147 | # result = [] 148 | # current_dir = [] 149 | # base_path = "./tts" 150 | # with os.scandir(base_path) as entries: 151 | # for entry in entries: 152 | # if entry.is_file() and entry.name.endswith(".mp3"): 153 | # current_dir.append(os.path.join("tts", entry.name)) 154 | 155 | # current_dir.sort() 156 | # result.append(current_dir) 157 | 158 | # return result 159 | 160 | 161 | 162 | #add 163 | # 转换为音频 164 | def _edge_tts(first,second,content): 165 | # voice = 'zh-CN-YunxiNeural' 166 | # rate = '-4%' 167 | # volume = '+0%' 168 | # filename = './tts/%s.mp3' % content 169 | # tts = edge_tts.Communicate(text=content, voice=voice, rate=rate, volume=volume) 170 | # tts.save(filename) 171 | filename = 'tts/'+str(first)+"."+str(second)+'.mp3' 172 | cmd = 'edge-tts --voice zh-CN-YunxiNeural --text "' + content + '" --write-media %s' % filename 173 | res = subprocess.call(cmd, shell=True) 174 | 175 | sound = AudioSegment.from_mp3(filename) 176 | duration = int(sound.duration_seconds) 177 | update_name = '%s.%s_duration_%f.mp3' % (filename.split('.')[0],filename.split('.')[1], duration) 178 | os.rename(filename, update_name) 179 | return update_name 180 | 181 | 182 | 183 | 184 | # 文本生成图片 185 | # 一维数组 186 | # 187 | def text_to_pic(contents): 188 | i=1 189 | for content in contents: 190 | getTxt2Image(','.join(content),ADDER_PROMOTE,"./",i) 191 | i=i+1 192 | 193 | 194 | 195 | #add 196 | def getTxt2Image(text_prompt,add_prompt,localPythonExePath,num):#文生图核心方法#localPythonExePath是本地存储路径 197 | serverName = "server001" 198 | txt2img_url = Stable_diff_api+'/sdapi/v1/txt2img' 199 | print("提示词:"+text_prompt) 200 | data = {'prompt': text_prompt+add_prompt+'(masterpiece:1,2), best quality, highres, original, extremely detailed wallpaper, perfect lighting,(extremely detailed CG:1.2),', 201 | 'brach_size': 1, 202 | # "sampler_name": "DPM++ 2m Karras",#可自行选择 203 | "steps": 20, 204 | "cfg_scale": 8, #提示词相关性 205 | "width" : 740, 206 | "height": 580, 207 | "restore_faces": "true", 208 | "negative_prompt": "NSFW, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, (ugly:1.331), (duplicate:1.331), (morbid:1.21), (mutilated:1.21), (tranny:1.331), mutated hands, (poorly drawn hands:1.5), blurry, (bad anatomy:1.21), (bad proportions:1.331), extra limbs, (disfigured:1.331), (missing arms:1.331), (extra legs:1.331), (fused fingers:1.61051), (too many fingers:1.61051), (unclear eyes:1.331), lowers, bad hands, missing fingers, extra digit,bad hands, missing fingers, (((extra arms and legs)))," 209 | } 210 | data.update(Stable_diff_conf) 211 | response = submit_post(txt2img_url, data) 212 | save_encoded_image(response.json()['images'][0], ".\pictures\image"+str(num)+".png") 213 | print("图片已经生成,并保存在pictures目录中") 214 | 215 | 216 | #add 217 | def save_encoded_image(b64_image: str, output_path: str): 218 | with open(output_path, "wb") as image_file: 219 | image_file.write(base64.b64decode(b64_image)) 220 | 221 | #add 222 | def submit_post(url: str, data: dict):#发出Post请求 223 | return requests.post(url, data=json.dumps(data)) 224 | 225 | 226 | 227 | 228 | # 生成视频 229 | # 传入两个二维数组 230 | # 231 | def handle_movie(voice,txts): 232 | final_duration_clips = [] 233 | txts=txts 234 | voice=voice 235 | print(len(voice)) 236 | print(len(txts)) 237 | 238 | for item in voice: 239 | duration_clips = [] 240 | for line in item: 241 | filename = str(line.split('/')[-1]) 242 | tmp = filename.split('_') 243 | # 获取语音文件名中的时长 244 | duration_clips.append(float(tmp[-1].replace('.mp3', ''))) 245 | final_duration_clips.append(duration_clips) 246 | 247 | 248 | final_clip_all=None 249 | for i in range(len(txts)): 250 | 251 | # final_duration_clips[i] 252 | # txts[i] 253 | # voice[i] 254 | 255 | # 解说 + 字幕 256 | final_clip=None 257 | for j in range(len(txts[i])): 258 | 259 | # 计算当前行的起始时间和结束时间 260 | 261 | print("="*50) 262 | print("i, j ---> " + str(i) + ", " + str(j)) 263 | print(voice[i][j]) 264 | print(txts[i][j]) 265 | print(final_duration_clips[i][j]) 266 | print(str(i+1)+".png") 267 | 268 | 269 | start = 0 270 | end = start + final_duration_clips[i][j] 271 | 272 | print("strat:"+str(start)) 273 | print("strat:"+str(end)) 274 | 275 | print("="*50) 276 | 277 | 278 | # 添加语音剪辑 279 | voice_clip = AudioFileClip("./"+voice[i][j]).set_start(start).volumex(1.2) 280 | 281 | # 添加字幕剪辑 282 | screensize = (700,200) 283 | # txt_clip = TextClip(txts[i][j], fontsize=30, color='black', font='MaoKenWangXingYuan.ttf', stroke_color='black',stroke_width=0.3,size = screensize, method='caption') 284 | txt_clip = TextClip(txts[i][j], fontsize=30, color='white', font='MaoKenWangXingYuan.ttf',size = screensize, method='caption') 285 | txt_clip = txt_clip.set_pos('bottom').set_duration(final_duration_clips[i][j]) 286 | txt_clip = txt_clip.set_start(start).set_end(end) 287 | 288 | # 计算视频中每张图片的剪辑长度 289 | # 定义镜头焦点效果 290 | def resize_func(t): 291 | # return 1 + 0.001*t 292 | return 1 293 | # 添加每张图片的剪辑,并设置位置、时长、帧率等属性 294 | image_clip = ImageClip("./pictures/image"+str(i+1)+".png").set_duration(final_duration_clips[i][j]).resize(resize_func).set_position(('center', 'center')).set_fps(25) 295 | # image_clip = image_clip.crossfadein(1).crossfadeout(1) 296 | 297 | 298 | # 将图像、字幕和音频剪辑合并为一个剪辑,并添加淡入淡出效果 299 | video_clip = CompositeVideoClip([image_clip,txt_clip]) 300 | video_clip = video_clip.set_audio(voice_clip) 301 | if final_clip is None: # 添加此行代码 302 | final_clip = video_clip # 添加此行代码 303 | else: 304 | final_clip = concatenate_videoclips([final_clip,video_clip]) 305 | 306 | 307 | if final_clip_all is None: # 添加此行代码 308 | final_clip_all = final_clip # 添加此行代码 309 | # 这一行使后来加的 310 | else: 311 | final_clip_all = concatenate_videoclips([final_clip_all,final_clip]) 312 | 313 | # 导出视频剪辑 314 | # final_clip.write_videofile("video/"+str(i+1)+".mp4", fps=25) 315 | 316 | 317 | current_time = datetime.now() 318 | time_string = current_time.strftime("%Y_%m_%d_%H_%M_%S") 319 | print(time_string) 320 | 321 | # 这一行使后来加的 322 | final_clip_all.write_videofile("video/"+time_string+".mp4", fps=25) 323 | print("*"*50) 324 | print("完成!") 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | # 内容翻译 346 | # 一维数组 347 | # 一维数组 348 | def translate(fileContents): 349 | resultered=[] 350 | for fileContent in fileContents: 351 | textTranslatedtoEnglish=json.loads(translater(fileContent)) 352 | resulter=textTranslatedtoEnglish['trans_result'] 353 | resulter=handleResult(resulter) 354 | resultered.append(resulter) 355 | return resultered 356 | 357 | # 358 | # 359 | # 360 | def translater(query): 361 | # Set your own appid/appkey. 362 | appid = '20230925001829106' 363 | appkey = 'GibMVhrk0dwgvV6Lt_iD' 364 | 365 | # For list of language codes, please refer to `https://api.fanyi.baidu.com/doc/21` 366 | from_lang = 'zh' 367 | to_lang = 'en' 368 | 369 | endpoint = 'http://api.fanyi.baidu.com' 370 | path = '/api/trans/vip/translate' 371 | url = endpoint + path 372 | 373 | # Generate salt and sign 374 | def make_md5(s, encoding='utf-8'): 375 | return hashlib.md5(s.encode(encoding)).hexdigest() 376 | 377 | salt = random.randint(32768, 65536) 378 | sign = make_md5(appid + query + str(salt) + appkey) 379 | 380 | # Build request 381 | headers = {'Content-Type': 'application/x-www-form-urlencoded'} 382 | payload = {'appid': appid, 'q': query, 'from': from_lang, 'to': to_lang, 'salt': salt, 'sign': sign} 383 | 384 | # Send request 385 | r = requests.post(url, params=payload, headers=headers) 386 | result = r.json() 387 | 388 | time.sleep(0.2) 389 | 390 | # Show response 391 | return (json.dumps(result, indent=4, ensure_ascii=False)) 392 | 393 | # add 394 | def handleResult(resulter): 395 | returned = "" # 初始化一个空字符串用于存储结果 396 | for i in resulter: 397 | # resulter中的每个元素(假设是一个字典)中的dst值取出来,用逗号连接起来,最终返回一个字符串。 398 | returned += i['dst']+"," # 修正这里的索引 399 | return returned 400 | 401 | 402 | 403 | 404 | 405 | 406 | # 提取关键词 407 | # 一维数组 408 | # 二位数组 409 | def use_extract_keywords(texts): 410 | re_texts=[] 411 | for text in texts: 412 | re_text=extract_keywords(text) 413 | re_texts.append(re_text) 414 | return re_texts 415 | 416 | #add 417 | def extract_keywords(text): 418 | # 将文本拆分成单词 419 | words = text.split() 420 | 421 | # 创建一个用于存储短语的列表 422 | phrases = [] 423 | 424 | # 创建一个集合用于跟踪已经出现过的单词 425 | seen_words = set() 426 | n=3 427 | # 生成n-gram短语 428 | for i in range(len(words) - n + 1): 429 | phrase = ' '.join(words[i:i + n]) 430 | # 检查短语中是否有已经出现的单词 431 | if not any(word in seen_words for word in phrase.split()): 432 | phrases.append(phrase) 433 | # 将短语中的单词添加到已经出现过的单词集合中 434 | seen_words.update(phrase.split()) 435 | 436 | return phrases 437 | 438 | 439 | 440 | # 将每个段落拆分成句子,一维变二维 441 | # 一维数组 442 | # 二维 443 | def dozen_txt_double(contents): 444 | doublelist=[] 445 | for content in contents: 446 | innerlist = [] 447 | lines=split_sentences(content) 448 | for line in lines: 449 | innerlist.append(line) 450 | doublelist.append(innerlist) 451 | return doublelist 452 | 453 | # add 454 | # 将每个段落拆分成句子 455 | 456 | def split_sentences(text): 457 | # 去除文本中的引号 458 | text = text.replace('"', '').replace('“', '').replace('”', '').replace('‘', '').replace('’', '') 459 | # 将文本按照换行符进行切割 460 | lines = text.split('\n') 461 | # 去除每行开头和结尾的空格,并去除空行 462 | lines = [line.strip() for line in lines if line.strip()] 463 | # 将每个段落拆分成句子 464 | sentences = [] 465 | for line in lines: 466 | # 按照句号、问号、感叹号等标点符号进行拆分 467 | sentences.extend(re.split(r'[.!?。?!]+', line)) 468 | 469 | # 去除句子开头和结尾的空格,并去除空句子 470 | sentences = [sentence.strip() for sentence in sentences if sentence.strip()] 471 | # 返回结果 472 | return sentences 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | def delete_files_in_folder(folder_path): 490 | try: 491 | # 获取文件夹中的所有文件列表 492 | file_list = os.listdir(folder_path) 493 | 494 | # 遍历文件列表并删除每个文件 495 | for filename in file_list: 496 | file_path = os.path.join(folder_path, filename) 497 | if os.path.isfile(file_path): 498 | os.remove(file_path) 499 | 500 | print("所有文件已成功删除。") 501 | except Exception as e: 502 | print("发生错误:{str(e)}") 503 | 504 | 505 | def delete_file(file_name): 506 | if os.path.exists(file_name): 507 | os.remove(file_name) 508 | print("成功删除文件"+file_name) 509 | else: 510 | print("文件\""+file_name+"\"不存在,已经忽略") 511 | 512 | 513 | 514 | def get_all_pic_files(path): 515 | files = [] 516 | for i in range(1, get_cont()+1): 517 | filename = f"{i}.png" 518 | file_path = os.path.join(path, filename) 519 | if os.path.exists(file_path): 520 | files.append(file_path) 521 | return files 522 | 523 | 524 | 525 | 526 | def savefile(content,name): 527 | # 打开文件,如果文件不存在将会创建新文件 528 | file = open(name, "w",encoding='utf-8') 529 | # 写入内容到文件 530 | file.write(content) 531 | # 关闭文件 532 | file.close() 533 | 534 | 535 | 536 | # def load_voice(): 537 | 538 | # # 指定文件夹路径 539 | # folder_path = './tts' 540 | 541 | # # 获取文件夹中所有以.mp3结尾的文件 542 | # mp3_files = [filename for filename in os.listdir(folder_path) if filename.endswith('.mp3')] 543 | 544 | # # 定义一个自定义排序函数,按照文件名中的数字部分进行排序 545 | # def custom_sort(filename): 546 | # # 提取文件名中的数字部分作为排序关键字 547 | # match = re.search(r'\d+', filename) 548 | # if match: 549 | # return int(match.group()) 550 | # else: 551 | # return 0 # 如果没有找到数字部分,默认为0 552 | 553 | # # 对文件名进行排序 554 | # sorted_files = sorted(mp3_files, key=custom_sort) 555 | 556 | # return sorted_files 557 | 558 | 559 | 560 | 561 | 562 | def load_voice(): 563 | # 指定文件夹路径 564 | folder_path = './tts' 565 | 566 | # 获取文件夹中所有以.mp3结尾的文件 567 | mp3_files = [filename for filename in os.listdir(folder_path) if filename.endswith('.mp3')] 568 | 569 | # 定义一个自定义排序函数,按照文件名中的数字部分进行排序 570 | def custom_sort(filename): 571 | # 提取文件名中的数字部分作为排序关键字 572 | match = re.search(r'\d+\.\d+', filename) 573 | if match: 574 | return tuple(map(int, match.group().split('.'))) 575 | else: 576 | return (0, 0) # 如果没有找到数字部分,默认为(0,0) 577 | 578 | # 对文件名进行排序 579 | sorted_files = sorted(mp3_files, key=custom_sort) 580 | 581 | # 将文件名按照行号分组,存储在二维列表中 582 | voice = [] 583 | for filename in sorted_files: 584 | match = re.search(r'(\d+)\.\d+', filename) 585 | if match: 586 | line_num = int(match.group(1)) 587 | while line_num > len(voice): 588 | voice.append([]) 589 | voice[-1].append(folder_path+'/'+filename) 590 | return voice 591 | 592 | 593 | 594 | 595 | 596 | 597 | # 获取文本 598 | # 0 599 | # 一维 600 | def loadtxt(): 601 | contents=[] 602 | for i in range(1,get_cont()+1): 603 | helloFile=open("split_txt/"+str(i)+".txt",encoding='utf-8') 604 | fileContent=helloFile.read() 605 | contents.append(fileContent) 606 | helloFile.close() 607 | return contents 608 | 609 | 610 | # 获取章节数 611 | def get_cont(): 612 | cont=0 613 | with os.scandir('split_txt') as entries: 614 | for entry in entries: 615 | if entry.is_file(): 616 | cont=cont+1 617 | return cont 618 | 619 | 620 | 621 | # 读取小说文本 622 | # 文件名 623 | # 文本 624 | def get_whole_file(filename): 625 | with open(filename, 'r', encoding='utf-8') as file: 626 | novel_text = file.read() 627 | return novel_text 628 | 629 | 630 | # def get_cont2(): 631 | # cont=0 632 | # with os.scandir('video') as entries: 633 | # for entry in entries: 634 | # if entry.is_file(): 635 | # cont=cont+1 636 | # return cont 637 | 638 | 639 | 640 | # 二维list 641 | 642 | 643 | def double_txt(contents): 644 | doublelist=[] 645 | for content in contents: 646 | lines=split_sentences(content) 647 | innerlist = [] 648 | for line in lines: 649 | innerlist.append(line) 650 | doublelist.append(innerlist) 651 | return doublelist 652 | 653 | 654 | 655 | 656 | 657 | 658 | # 重构图片 659 | # 序号 附加的关键词 660 | # 0 661 | def re_create_pic(num,prom): 662 | delete_file('image'+str(num)+".png") 663 | getTxt2Image(translater(get_txt_by_num(num)),prom,"./",num) 664 | # getTxt2Image(translater(clip_to_whole(get_txt_by_num(num))),prom,"./",num) 665 | 666 | #add 667 | def get_txt_by_num(num): 668 | helloFile=open("split_txt/"+str(num)+".txt",encoding='utf-8') 669 | fileContent=helloFile.read() 670 | helloFile.close() 671 | return fileContent 672 | 673 | 674 | 675 | 676 | def open_file_content(): 677 | os.startfile('content.txt') 678 | 679 | 680 | 681 | def open_floder_video(): 682 | os.system(f'start explorer "video"') 683 | 684 | 685 | 686 | def open_floder_pic(): 687 | os.system(f'start explorer "pictures"') 688 | 689 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 文件夹展示 6 | 42 | 43 | 67 | 68 | 69 | 70 |

图片文件夹

71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from deffer import * 2 | 3 | def delete_folder_files(folder): 4 | if(folder=='pictures'): 5 | delete_files_in_folder('pictures') 6 | if(folder=='video'): 7 | delete_files_in_folder('video') 8 | if(folder=='split_txt'): 9 | delete_files_in_folder('split_txt') 10 | if(folder=='tts'): 11 | delete_files_in_folder('tts') 12 | 13 | 14 | # delete_file('output.mp4') 15 | 16 | 17 | 18 | def make_text(): 19 | spliter(get_whole_file('content.txt')) 20 | 21 | print("*"*50) 22 | print("完成!") 23 | 24 | def make_tts(): 25 | contents=loadtxt() 26 | contents_double=dozen_txt_double(contents) 27 | text_to_voice(contents_double) 28 | print("*"*50) 29 | print("完成!") 30 | 31 | def make_pic(): 32 | contents=loadtxt() 33 | text_to_pic(use_extract_keywords(translate((contents)))) 34 | 35 | print("*"*50) 36 | print("完成!") 37 | 38 | 39 | def make_movie(): 40 | handle_movie(load_voice(),double_txt(loadtxt())) 41 | print("*"*50) 42 | print("完成!") 43 | 44 | 45 | def re_make_pic(num): 46 | prom='' 47 | re_create_pic(num,prom) 48 | 49 | print("*"*50) 50 | print("完成!") 51 | 52 | 53 | 54 | 55 | 56 | # # # 一维片段 57 | # contents=spliter(clip_to_whole(get_whole_file('content.txt'))) 58 | # # # 对每个维度生成照片 59 | # text_to_pic((use_extract_keywords(translate((contents))))) 60 | # # # 拆分为二维片段,对每一个片段进行内部拆分,一维变二维,方便语音生成和文字配 61 | # contents_double=choose_and_use_split_func(contents) 62 | # # # 转语音 63 | # voice=text_to_voice(contents_double) 64 | # # # 输出为视频 65 | # handle_movie(load_voice(),contents_double) 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /pyvenv.cfg: -------------------------------------------------------------------------------- 1 | home = C:\Users\lgh\AppData\Local\Programs\Python\Python37 2 | include-system-site-packages = false 3 | version = 3.7.9 4 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | moviepy==1.0.3 2 | flask== 2.2.5 3 | gtts==2.5.1 4 | pydub==0.25.1 5 | edge-tts==6.1.12 6 | scikit-learn==1.0.2 7 | nltk==3.8.1 -------------------------------------------------------------------------------- /show.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/show.png -------------------------------------------------------------------------------- /show2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firgk/textsToVideo/dbb41be5b27370787f4dce5bd5717e7b36b7d71f/show2.png -------------------------------------------------------------------------------- /start.bat: -------------------------------------------------------------------------------- 1 | start http://127.0.0.1:5000 2 | start cmd /k "python app.py" 3 | 4 | mkdir tts 5 | mkdir split_txt -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | from threading import * 2 | import time 3 | import os 4 | from flask import Flask, render_template 5 | import os 6 | from main import * 7 | from threading import* 8 | import asyncio 9 | 10 | # make_text() 11 | 12 | import os 13 | 14 | make_movie() 15 | # print(loadtxt()) --------------------------------------------------------------------------------