Spaces:
Runtime error
Runtime error
Upload 7 files
Browse files- audioex.py +16 -0
- edit.py +34 -0
- main.py +31 -0
- texttospeech.py +12 -0
- trans.py +31 -0
- transcribe.py +10 -0
- ytdownloader.py +21 -0
audioex.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
import os
|
3 |
+
import shutil
|
4 |
+
|
5 |
+
def ex():
|
6 |
+
video_directory = "video"
|
7 |
+
video_files = [f for f in os.listdir(video_directory) if f.endswith(".mp4")]
|
8 |
+
for mp4_file in video_files:
|
9 |
+
# Full path to the mp4 file
|
10 |
+
mp4_file_path = os.path.join(video_directory, mp4_file)
|
11 |
+
print(mp4_file_path)
|
12 |
+
os.rename(mp4_file_path, "video.mp4")
|
13 |
+
command2mp3 = f"ffmpeg -i video.mp4 speech.mp3"
|
14 |
+
command2wav = "ffmpeg -i speech.mp3 speech.wav"
|
15 |
+
subprocess.run(command2mp3, shell=True)
|
16 |
+
subprocess.run(command2wav, shell=True)
|
edit.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from moviepy.editor import VideoFileClip, AudioFileClip
|
2 |
+
|
3 |
+
|
4 |
+
def mute_and_add_audio(video_file_path, audio_file_path, output_file_path):
|
5 |
+
try:
|
6 |
+
# Load the video file
|
7 |
+
video = VideoFileClip(video_file_path)
|
8 |
+
|
9 |
+
# Load the new audio file
|
10 |
+
new_audio = AudioFileClip(audio_file_path)
|
11 |
+
|
12 |
+
# Set the new audio to the video (mute the original audio)
|
13 |
+
video_with_new_audio = video.set_audio(new_audio)
|
14 |
+
|
15 |
+
# Write the result to the output file
|
16 |
+
video_with_new_audio.write_videofile(output_file_path, codec='libx264', audio_codec='aac')
|
17 |
+
|
18 |
+
print(f"Video with new audio saved to {output_file_path}")
|
19 |
+
except Exception as e:
|
20 |
+
print(f"An error occurred: {e}")
|
21 |
+
|
22 |
+
|
23 |
+
# # Example usage
|
24 |
+
# if __name__ == "__main__":
|
25 |
+
# # Path to the video file
|
26 |
+
# video_file = "video.mp4"
|
27 |
+
#
|
28 |
+
# # Path to the new audio file
|
29 |
+
# audio_file = "output.wav"
|
30 |
+
#
|
31 |
+
# # Path to save the output video file
|
32 |
+
# output_file = "output_video.mp4"
|
33 |
+
#
|
34 |
+
# mute_and_add_audio(video_file, audio_file, output_file)
|
main.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import ytdownloader
|
2 |
+
import trans
|
3 |
+
import transcribe
|
4 |
+
import texttospeech
|
5 |
+
import audioex
|
6 |
+
from time import sleep
|
7 |
+
import edit
|
8 |
+
import streamlit
|
9 |
+
streamlit.title("Video Dubber")
|
10 |
+
|
11 |
+
def main():
|
12 |
+
link = streamlit.text_input("Please enter Youtube video link = ")
|
13 |
+
if streamlit.button("Submit"):
|
14 |
+
ytdownloader.download_youtube_video(link, "video")
|
15 |
+
sleep(5)
|
16 |
+
audioex.ex()
|
17 |
+
sleep(5)
|
18 |
+
video_text = transcribe.transcibe("speech.wav")
|
19 |
+
sleep(5)
|
20 |
+
trans_text = trans.mixtral(video_text)
|
21 |
+
streamlit.text(trans_text)
|
22 |
+
sleep(5)
|
23 |
+
texttospeech.speak(trans_text)
|
24 |
+
sleep(5)
|
25 |
+
edit.mute_and_add_audio("video.mp4", "output.wav", "output_video.mp4")
|
26 |
+
sleep(5)
|
27 |
+
streamlit.video("output_video.mp4")
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
main()
|
texttospeech.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from TTS.api import TTS
|
3 |
+
|
4 |
+
|
5 |
+
print(TTS().list_models())
|
6 |
+
|
7 |
+
# Init TTS
|
8 |
+
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to('cpu')
|
9 |
+
|
10 |
+
|
11 |
+
def speak(text):
|
12 |
+
tts.tts_to_file(text=text, speaker_wav="speech.wav", language="en", file_path="output.wav")
|
trans.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from groq import Groq
|
2 |
+
|
3 |
+
def mixtral(script):
|
4 |
+
client = Groq(api_key="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")
|
5 |
+
length = len(script)
|
6 |
+
print("lenghth of script is", length)
|
7 |
+
completion = client.chat.completions.create(
|
8 |
+
model="llama3-8b-8192",
|
9 |
+
messages=[
|
10 |
+
{
|
11 |
+
"role": "user",
|
12 |
+
"content": f"""You have to translate the given text into very simple indian english or hinglish language with basic words or you can also include in just {length+10} words
|
13 |
+
Do not include any note.
|
14 |
+
here is the text.
|
15 |
+
|
16 |
+
{script}
|
17 |
+
|
18 |
+
Translation =
|
19 |
+
"""
|
20 |
+
}
|
21 |
+
],
|
22 |
+
temperature=0.3,
|
23 |
+
max_tokens=8192,
|
24 |
+
top_p=1,
|
25 |
+
stream=False,
|
26 |
+
stop=None,
|
27 |
+
|
28 |
+
)
|
29 |
+
print(completion.choices[0].message.content)
|
30 |
+
print("length of response is ", len(completion.choices[0].message.content))
|
31 |
+
return completion.choices[0].message.content
|
transcribe.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import whisper
|
2 |
+
import numpy as np
|
3 |
+
from scipy.io.wavfile import read
|
4 |
+
import torch
|
5 |
+
import whisper
|
6 |
+
def transcibe(audio):
|
7 |
+
model = whisper.load_model("base")
|
8 |
+
result = model.transcribe(audio)
|
9 |
+
print(result["text"])
|
10 |
+
return result["text"]
|
ytdownloader.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import subprocess
|
2 |
+
# subprocess.run("pip install pytube", shell=True)
|
3 |
+
|
4 |
+
from pytube import YouTube
|
5 |
+
|
6 |
+
def download_youtube_video(url, output_path):
|
7 |
+
try:
|
8 |
+
# Create a YouTube object
|
9 |
+
yt = YouTube(url)
|
10 |
+
|
11 |
+
# Get the highest resolution stream available
|
12 |
+
stream = yt.streams.get_highest_resolution()
|
13 |
+
|
14 |
+
# Download the video
|
15 |
+
stream.download(output_path=output_path)
|
16 |
+
|
17 |
+
print(f"Video downloaded successfully and saved to {output_path}")
|
18 |
+
except Exception as e:
|
19 |
+
print(f"An error occurred: {e}")
|
20 |
+
|
21 |
+
|