Code Monkey home page Code Monkey logo

text2video's Introduction

一个文本转视频的工具

这个工具可以将一段文本转换为视频,并保存到指定的本地,初衷是想实现小说的可视化阅读功能。

效果图如下:

效果图

实现原理

  • 将文本进行分段,现在没有想到好的办法,就是通过标点符号句号分段,分成一个个的句子
  • 通过句子生成图片,生成声音,图片开源的有很多,本方案采用 stable-diffusion,语言转文字使用 edge-tts
  • 在通过 opencv 将图片合并为视频,目前输出 mp4 格式的视频,句子作为字母贴到视频内容的底部区域。
  • 音频是一个有时间概念的东西,恰好可以通过音频控制一张画面的播放时长
  • 在通过 ffmpeg 将音频合并到原始视频中。

最终,一个有画面,有字幕,有声音的视频就出现了,咱们实现了一个 文本转视频

本地开发

安装依赖

开发时,需要安装的环境是 macOS python 3.10.12,其他环境可能存在兼容性问题

pip install -r requirements.txt

生成 huggingface api key

token 申请地址:https://huggingface.co/settings/tokens

因为,该项目中使用了 huggingface 上的开源文生图模型生成图片,中文生成图片效果不大好,因此,本项目对中文进行了翻译,感谢有道,直接使用有道翻译,比较方便。翻译后,生成图的质量有一定的提高。

token 可以写入到 .env 文件里面

如果使用的 pollinations-ai ,则不填写 token 就 ok

安装 ffmpeg

因为视频合成声音需要

开始使用

python3.10 app.py
http://127.0.0.1:5000/

加群讨论

欢迎加群讨论技术?随意打赏,请备注 github 名

image

License: MIT

本项目采用 MIT 许可证授权。

text2video's People

Contributors

brzhang666 avatar bravekingzhang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.