Skip to content

Commit

Permalink
add video-retalking
Browse files Browse the repository at this point in the history
  • Loading branch information
halfzm committed Feb 9, 2024
1 parent ccff6d5 commit ed04b7b
Show file tree
Hide file tree
Showing 197 changed files with 23,992 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ snakers
*.txt
processed
pretrained_models
video-retalking
temp
49 changes: 40 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import subprocess
import shutil
import gradio as gr

Expand All @@ -12,6 +13,7 @@

s2st = Speech2SpeechTranslation()


def extract_audio_from_video(video_fp):
os.system(f"ffmpeg -y -i {video_fp} -loglevel error -vn ./tmp/src.wav")
os.system(f"ffmpeg -y -i {video_fp} -loglevel error -an ./tmp/novoice_src.mp4")
Expand All @@ -27,13 +29,34 @@ def embed_subtitle_to_video(sub_fp, video_fp, tgt_fp):
)


def video_to_video_translation(video_fp):
def video_retalk():
base_dir = os.getcwd()

video_fp = os.path.join(base_dir, "./tmp/novoice_src.mp4")
audio_fp = os.path.join(base_dir, "./tmp/tgt.wav")
output_fp = os.path.join(base_dir, "./tmp/tgt.mp4")
command = f"python inference.py --face {video_fp} --audio {audio_fp} --outfile {output_fp}"

os.chdir(os.path.join(base_dir, "video-retalking"))
if os.path.exists("./temp"):
shutil.rmtree("./temp")
os.mkdir("./temp")
os.mkdir("./temp/temp")
os.mkdir("./temp/face")
else:
os.mkdir("./temp")
subprocess.run(command)
os.chdir(base_dir)


# def video_to_video_translation(video_fp, video_retalking=False:
def video_to_video_translation(video_fp, video_retalking=True):
print("extract audio from video...")
if not os.path.exists("./tmp"):
os.mkdir("./tmp")
else:
shutil.rmtree('./tmp')
os.mkdir('./tmp')
shutil.rmtree("./tmp")
os.mkdir("./tmp")

extract_audio_from_video(video_fp)

Expand All @@ -42,29 +65,37 @@ def video_to_video_translation(video_fp):
sub_fp = "./tmp/sub.srt"
s2st.speech_to_speech_translation(audio_fp, sub_fp)

if video_retalking:
print("video retalking...")
video_retalk()

print("embed audio to video...")
audio_fp = "./tmp/tgt.wav"
video_fp = "./tmp/novoice_src.mp4"
tgt_fp = "./tmp/tgt.mp4"
if video_retalking:
video_fp = "./tmp/tgt_enhanced.mp4"
else:
video_fp = "./tmp/novoice_src.mp4"
tgt_fp = "./tmp/tgt_retalk.mp4"
embed_audio_to_video(audio_fp, video_fp, tgt_fp)

print("embed subtitle to video...")
sub_fp = "./tmp/sub.srt"
video_fp = "./tmp/tgt.mp4"
sub_fp = "./tmp/sub.srt"
video_fp = "./tmp/tgt_retalk.mp4"
tgt_fp = "output.mp4"
embed_subtitle_to_video(sub_fp, video_fp, tgt_fp)

print("finished!")
shutil.rmtree("./tmp")
# shutil.rmtree("./tmp")
return tgt_fp


def v2vt_app():
demo = gr.Blocks()
with demo:
gr.Markdown(
"""
<div style="text-align:center;">
<span style="font-size:3em; font-weight:bold;">加成有声音克隆的视频翻译</span>
<span style="font-size:3em; font-weight:bold;">带有口型同步的视频翻译</span>
</div>
"""
)
Expand Down
31 changes: 21 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
## 效果演示
详见`res.mp4`

<video>
<!-- <video>
<source src="res.mp4" type="video/mp4">
</video>
</video> -->

## 技术栈
- 语音识别 [fast-whisper](https://github.com/SYSTRAN/faster-whisper)
- 文本翻译 [facebook/m2m](https://huggingface.co/facebook/m2m100_1.2B)
- 音色克隆 [openvoice](https://github.com/myshell-ai/OpenVoice)(对于中文,使用微软的[TTS](https://github.com/skygongque/tts)替换openvoice自带的TTS模型)
- 口型同步:[videotalking](https://github.com/OpenTalker/video-retalking)
- 脸部超分:[gfpgan](https://github.com/TencentARC/GFPGAN)
- 视频整合 [pyvideotrans](https://github.com/jianchang512/pyvideotrans)



## 环境搭建
Expand All @@ -30,6 +39,7 @@ cd v2vt_clone
pip install -r requirements.txt
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
```

3. 把openvoice中需要的[模型](https://myshell-public-repo-hosting.s3.amazonaws.com/checkpoints_1226.zip)放到`openvoice_checkpoints`文件夹中,目录结构应该如下
```
openvoice_checkpoints
Expand All @@ -40,6 +50,14 @@ openvoice_checkpoints
...
```

1. 把video_retalking中需要的[模型](https://drive.google.com/drive/folders/18rhjMpxK8LVVxf7PI6XwOidt8Vouv_H0?usp=share_link)放到`video-retalking/checkpoints`文件夹中,目录结构应该如下
```
video-retalking
|- checkpoints
|- ...
...
```


## 使用说明
- 快速启动
Expand All @@ -56,14 +74,7 @@ python app.py
## TODO
- [ ] 人声分离:提升whisper输入的音频质量([spleeter](https://github.com/deezer/spleeter))
- [ ] 音频降噪:音色克隆后的声音电噪明显
- [ ] 口型同步:提升画面的自然度([videoretalking](https://github.com/OpenTalker/video-retalking))


## 参考项目
- 语音识别 [fast-whisper](https://github.com/SYSTRAN/faster-whisper)
- 文本翻译 [facebook/m2m](https://huggingface.co/facebook/m2m100_1.2B)
- 音色克隆 [openvoice](https://github.com/myshell-ai/OpenVoice)(对于中文,使用微软的[TTS](https://github.com/skygongque/tts)替换openvoice自带的TTS模型)
- 音频整合 [pyvideotrans](https://github.com/jianchang512/pyvideotrans)
- [x] 口型同步:提升画面的自然度([videoretalking](https://github.com/OpenTalker/video-retalking))


## 其它
Expand Down
Binary file modified res.mp4
Binary file not shown.
43 changes: 43 additions & 0 deletions video-retalking/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery and unwelcome sexual attention or advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic address, without explicit permission
- Other conduct that could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned with this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project email address, posting via an official social media account, or acting as an appointed representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the Contributor Covenant, version 2.0, available at [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html).
Loading

0 comments on commit ed04b7b

Please sign in to comment.