VidLingua 0.1.0a1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: VidLingua
3
+ Version: 0.1.0a1
4
+ Summary: A command-line tool that automates the translation and dubbing of YouTube videos.
5
+ Home-page: https://github.com/vprayag2005/VidLingua
6
+ Author: vprayag2005
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Topic :: Multimedia :: Video
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: yt-dlp
15
+ Requires-Dist: faster-whisper
16
+ Requires-Dist: deep-translator
17
+ Requires-Dist: edge-tts
18
+ Dynamic: author
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ # VidLingua
28
+
29
+ VidLingua is a command-line tool that automates the translation and dubbing of YouTube videos. It downloads the original video, transcribes the audio, translates the text into a target language, generates a new voiceover using neural text-to-speech, and merges the new audio back into the video file.
30
+
31
+ ## Dependencies
32
+
33
+ - **Python 3.8+**
34
+ - **FFmpeg**: Must be installed and accessible in your system's `PATH`.
35
+
36
+ ## Installation
37
+
38
+ 1. Clone or download this repository.
39
+ 2. Navigate to the `VidLingua` directory.
40
+ 3. Install the package using `pip`:
41
+
42
+ ```bash
43
+ pip install -e .
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ```bash
49
+ Vidlingua run --yt-url <URL> --translate-to <LANG_CODE> [OPTIONS]
50
+ ```
51
+
52
+ ### Options
53
+
54
+ | Option | Description | Default |
55
+ | :--- | :--- | :--- |
56
+ | `--yt-url` | **(Required)** The YouTube video URL. | |
57
+ | `--translate-to` | **(Required)** The target language code (e.g., `en`, `hi`, `ml`). | |
58
+ | `--destination` | Directory to save the final video. | `~/Downloads` |
59
+
60
+ ### Examples
61
+
62
+ Translate to English and save to the default Downloads folder:
63
+ ```bash
64
+ Vidlingua run --yt-url "https://youtube.com/watch?v=..." --translate-to "en"
65
+ ```
66
+
67
+ Translate to Hindi and save to a specific directory:
68
+ ```bash
69
+ Vidlingua run --yt-url "https://youtube.com/watch?v=..." --translate-to "hi" --destination "./my_videos"
70
+ ```
71
+
72
+ ## Supported Languages
73
+
74
+ VidLingua maps high-quality Neural TTS voices to the following language codes. Other language codes supported by Google Translate will fall back to a default voice.
75
+
76
+ | Code | Language |
77
+ | :--- | :--- |
78
+ | `en` | English |
79
+ | `hi` | Hindi |
80
+ | `ml` | Malayalam |
81
+ | `ta` | Tamil |
82
+ | `kn` | Kannada |
83
+ | `te` | Telugu |
@@ -0,0 +1,57 @@
1
+ # VidLingua
2
+
3
+ VidLingua is a command-line tool that automates the translation and dubbing of YouTube videos. It downloads the original video, transcribes the audio, translates the text into a target language, generates a new voiceover using neural text-to-speech, and merges the new audio back into the video file.
4
+
5
+ ## Dependencies
6
+
7
+ - **Python 3.8+**
8
+ - **FFmpeg**: Must be installed and accessible in your system's `PATH`.
9
+
10
+ ## Installation
11
+
12
+ 1. Clone or download this repository.
13
+ 2. Navigate to the `VidLingua` directory.
14
+ 3. Install the package using `pip`:
15
+
16
+ ```bash
17
+ pip install -e .
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```bash
23
+ Vidlingua run --yt-url <URL> --translate-to <LANG_CODE> [OPTIONS]
24
+ ```
25
+
26
+ ### Options
27
+
28
+ | Option | Description | Default |
29
+ | :--- | :--- | :--- |
30
+ | `--yt-url` | **(Required)** The YouTube video URL. | |
31
+ | `--translate-to` | **(Required)** The target language code (e.g., `en`, `hi`, `ml`). | |
32
+ | `--destination` | Directory to save the final video. | `~/Downloads` |
33
+
34
+ ### Examples
35
+
36
+ Translate to English and save to the default Downloads folder:
37
+ ```bash
38
+ Vidlingua run --yt-url "https://youtube.com/watch?v=..." --translate-to "en"
39
+ ```
40
+
41
+ Translate to Hindi and save to a specific directory:
42
+ ```bash
43
+ Vidlingua run --yt-url "https://youtube.com/watch?v=..." --translate-to "hi" --destination "./my_videos"
44
+ ```
45
+
46
+ ## Supported Languages
47
+
48
+ VidLingua maps high-quality Neural TTS voices to the following language codes. Other language codes supported by Google Translate will fall back to a default voice.
49
+
50
+ | Code | Language |
51
+ | :--- | :--- |
52
+ | `en` | English |
53
+ | `hi` | Hindi |
54
+ | `ml` | Malayalam |
55
+ | `ta` | Tamil |
56
+ | `kn` | Kannada |
57
+ | `te` | Telugu |
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: VidLingua
3
+ Version: 0.1.0a1
4
+ Summary: A command-line tool that automates the translation and dubbing of YouTube videos.
5
+ Home-page: https://github.com/vprayag2005/VidLingua
6
+ Author: vprayag2005
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Topic :: Multimedia :: Video
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: yt-dlp
15
+ Requires-Dist: faster-whisper
16
+ Requires-Dist: deep-translator
17
+ Requires-Dist: edge-tts
18
+ Dynamic: author
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ # VidLingua
28
+
29
+ VidLingua is a command-line tool that automates the translation and dubbing of YouTube videos. It downloads the original video, transcribes the audio, translates the text into a target language, generates a new voiceover using neural text-to-speech, and merges the new audio back into the video file.
30
+
31
+ ## Dependencies
32
+
33
+ - **Python 3.8+**
34
+ - **FFmpeg**: Must be installed and accessible in your system's `PATH`.
35
+
36
+ ## Installation
37
+
38
+ 1. Clone or download this repository.
39
+ 2. Navigate to the `VidLingua` directory.
40
+ 3. Install the package using `pip`:
41
+
42
+ ```bash
43
+ pip install -e .
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ```bash
49
+ Vidlingua run --yt-url <URL> --translate-to <LANG_CODE> [OPTIONS]
50
+ ```
51
+
52
+ ### Options
53
+
54
+ | Option | Description | Default |
55
+ | :--- | :--- | :--- |
56
+ | `--yt-url` | **(Required)** The YouTube video URL. | |
57
+ | `--translate-to` | **(Required)** The target language code (e.g., `en`, `hi`, `ml`). | |
58
+ | `--destination` | Directory to save the final video. | `~/Downloads` |
59
+
60
+ ### Examples
61
+
62
+ Translate to English and save to the default Downloads folder:
63
+ ```bash
64
+ Vidlingua run --yt-url "https://youtube.com/watch?v=..." --translate-to "en"
65
+ ```
66
+
67
+ Translate to Hindi and save to a specific directory:
68
+ ```bash
69
+ Vidlingua run --yt-url "https://youtube.com/watch?v=..." --translate-to "hi" --destination "./my_videos"
70
+ ```
71
+
72
+ ## Supported Languages
73
+
74
+ VidLingua maps high-quality Neural TTS voices to the following language codes. Other language codes supported by Google Translate will fall back to a default voice.
75
+
76
+ | Code | Language |
77
+ | :--- | :--- |
78
+ | `en` | English |
79
+ | `hi` | Hindi |
80
+ | `ml` | Malayalam |
81
+ | `ta` | Tamil |
82
+ | `kn` | Kannada |
83
+ | `te` | Telugu |
@@ -0,0 +1,17 @@
1
+ README.md
2
+ setup.py
3
+ VidLingua.egg-info/PKG-INFO
4
+ VidLingua.egg-info/SOURCES.txt
5
+ VidLingua.egg-info/dependency_links.txt
6
+ VidLingua.egg-info/entry_points.txt
7
+ VidLingua.egg-info/requires.txt
8
+ VidLingua.egg-info/top_level.txt
9
+ Vidlingua/__init__.py
10
+ Vidlingua/cli.py
11
+ Vidlingua/core.py
12
+ Vidlingua/exceptions.py
13
+ Vidlingua.egg-info/PKG-INFO
14
+ Vidlingua.egg-info/SOURCES.txt
15
+ Vidlingua.egg-info/dependency_links.txt
16
+ Vidlingua.egg-info/entry_points.txt
17
+ Vidlingua.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ Vidlingua = Vidlingua.cli:main
@@ -0,0 +1,4 @@
1
+ yt-dlp
2
+ faster-whisper
3
+ deep-translator
4
+ edge-tts
@@ -0,0 +1 @@
1
+ Vidlingua
@@ -0,0 +1 @@
1
+ # Vidlingua Package
@@ -0,0 +1,67 @@
1
+ import argparse
2
+ import os
3
+ import sys
4
+ import tempfile
5
+
6
+ from Vidlingua.core import (
7
+ download_media,
8
+ speech_to_text,
9
+ translate_text,
10
+ text_to_audio,
11
+ merge_audio_video,
12
+ )
13
+ from Vidlingua.exceptions import VidLinguaError
14
+
15
+
16
+ def main():
17
+ parser = argparse.ArgumentParser(
18
+ description="VidLingua: Video Translation and Dubbing"
19
+ )
20
+ subparsers = parser.add_subparsers(dest="command", required=True)
21
+
22
+ run_parser = subparsers.add_parser("run", help="Run the translation process")
23
+ run_parser.add_argument("--yt-url", required=True, help="YouTube video URL")
24
+ run_parser.add_argument(
25
+ "--translate-to",
26
+ required=True,
27
+ help="Language code to translate to (e.g., 'en', 'es', 'hi')",
28
+ )
29
+ run_parser.add_argument(
30
+ "--destination",
31
+ default=os.path.expanduser("~/Downloads"),
32
+ help="Directory to save the final dubbed video (defaults to system Downloads folder)",
33
+ )
34
+
35
+ args = parser.parse_args()
36
+
37
+ if args.command == "run":
38
+ video_url = args.yt_url
39
+ translate_lang = args.translate_to
40
+
41
+ try:
42
+ with tempfile.TemporaryDirectory() as temp_dir:
43
+ audio_file, video_file = download_media(video_url, temp_dir)
44
+ transcribed_text = speech_to_text(audio_file)
45
+
46
+ if translate_lang.strip():
47
+ lang_code = translate_lang.strip().replace("'", "").replace('"', "")
48
+ final_translated_text = translate_text(transcribed_text, lang_code)
49
+
50
+ if final_translated_text:
51
+ temp_audio_path = os.path.join(temp_dir, "translated_audio.mp3")
52
+ generated_audio_path = text_to_audio(
53
+ final_translated_text, lang_code, temp_audio_path
54
+ )
55
+ if generated_audio_path:
56
+ os.makedirs(args.destination, exist_ok=True)
57
+ final_video_path = os.path.join(
58
+ args.destination, "final_dubbed_video.mp4"
59
+ )
60
+ merge_audio_video(video_file, generated_audio_path, final_video_path)
61
+ except VidLinguaError as e:
62
+ print(f"\n[Error] {e}")
63
+ sys.exit(1)
64
+
65
+
66
+ if __name__ == "__main__":
67
+ main()
@@ -0,0 +1,130 @@
1
+ import asyncio
2
+ import os
3
+ import subprocess
4
+
5
+ import edge_tts
6
+ import yt_dlp
7
+ from deep_translator import GoogleTranslator
8
+ from faster_whisper import WhisperModel
9
+
10
+ from Vidlingua.exceptions import (
11
+ AudioGenerationError,
12
+ DownloadError,
13
+ MergeError,
14
+ TranslationError,
15
+ )
16
+
17
+ VOICE_MAPPING = {
18
+ "en": "en-US-ChristopherNeural",
19
+ "hi": "hi-IN-MadhurNeural",
20
+ "ml": "ml-IN-MidhunNeural",
21
+ "ta": "ta-IN-PallaviNeural",
22
+ "kn": "kn-IN-GaganNeural",
23
+ "te": "te-IN-MohanNeural",
24
+ }
25
+
26
+
27
+ def get_youtube_options(format_str, outtmpl):
28
+ """Returns the yt-dlp configuration options."""
29
+ opts = {
30
+ "format": format_str,
31
+ "outtmpl": outtmpl,
32
+ "extractor_args": {"youtube": {"player_client": ["android", "web"]}},
33
+ }
34
+ return opts
35
+
36
+
37
+ def download_media(url, temp_dir):
38
+ """
39
+ Downloads both the audio (for transcription)
40
+ and the video without audio (for dubbing).
41
+ """
42
+
43
+ audio_opts = get_youtube_options(
44
+ "bestaudio/best", os.path.join(temp_dir, "original_audio.%(ext)s")
45
+ )
46
+ video_opts = get_youtube_options(
47
+ "bestvideo/best", os.path.join(temp_dir, "original_video.%(ext)s")
48
+ )
49
+
50
+ try:
51
+ with yt_dlp.YoutubeDL(audio_opts) as ydl:
52
+ info_dict = ydl.extract_info(url, download=True)
53
+ audio_path = ydl.prepare_filename(info_dict)
54
+
55
+ with yt_dlp.YoutubeDL(video_opts) as ydl:
56
+ info_dict = ydl.extract_info(url, download=True)
57
+ video_path = ydl.prepare_filename(info_dict)
58
+
59
+ return audio_path, video_path
60
+ except yt_dlp.utils.DownloadError as e:
61
+ raise DownloadError(f"Failed to download media: {e}")
62
+
63
+
64
+ def speech_to_text(audio_path):
65
+ model = WhisperModel("base", compute_type="int8", cpu_threads=8)
66
+
67
+ segments, info = model.transcribe(audio_path, beam_size=1, vad_filter=True)
68
+
69
+ text = "".join([segment.text for segment in segments])
70
+
71
+ return text.strip()
72
+
73
+
74
+ def translate_text(text, target_lang):
75
+ try:
76
+ translator = GoogleTranslator(source="auto", target=target_lang)
77
+
78
+ chunk_size = 4500
79
+ chunks = [text[i : i + chunk_size] for i in range(0, len(text), chunk_size)]
80
+
81
+ translated_text = ""
82
+ for i, chunk in enumerate(chunks):
83
+ translated_text += translator.translate(chunk) + " "
84
+
85
+ return translated_text.strip()
86
+ except Exception as e:
87
+ raise TranslationError(f"Failed to translate text: {e}")
88
+
89
+
90
+ def text_to_audio(text, lang_code, output_path):
91
+ try:
92
+ voice = VOICE_MAPPING.get(lang_code.lower(), "en-US-ChristopherNeural")
93
+
94
+ async def _generate():
95
+ communicate = edge_tts.Communicate(text, voice)
96
+ await communicate.save(output_path)
97
+
98
+ asyncio.run(_generate())
99
+
100
+ return output_path
101
+ except Exception as e:
102
+ raise AudioGenerationError(f"Failed to generate audio: {e}")
103
+
104
+
105
+ def merge_audio_video(video_path, audio_path, output_path="final_dubbed_video.mp4"):
106
+ command = [
107
+ "ffmpeg",
108
+ "-y",
109
+ "-i",
110
+ video_path,
111
+ "-i",
112
+ audio_path,
113
+ "-map",
114
+ "0:v:0",
115
+ "-map",
116
+ "1:a:0",
117
+ "-c:v",
118
+ "copy",
119
+ "-c:a",
120
+ "aac",
121
+ "-shortest",
122
+ output_path,
123
+ ]
124
+ try:
125
+ subprocess.run(
126
+ command, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
127
+ )
128
+ return output_path
129
+ except subprocess.CalledProcessError as e:
130
+ raise MergeError("Failed to merge audio and video. Ensure FFmpeg is installed.")
@@ -0,0 +1,28 @@
1
+ class VidLinguaError(Exception):
2
+ """Base exception for all VidLingua errors."""
3
+
4
+ pass
5
+
6
+
7
+ class DownloadError(VidLinguaError):
8
+ """Raised when media downloading fails."""
9
+
10
+ pass
11
+
12
+
13
+ class TranslationError(VidLinguaError):
14
+ """Raised when text translation fails."""
15
+
16
+ pass
17
+
18
+
19
+ class AudioGenerationError(VidLinguaError):
20
+ """Raised when generating audio from text fails."""
21
+
22
+ pass
23
+
24
+
25
+ class MergeError(VidLinguaError):
26
+ """Raised when merging audio and video fails."""
27
+
28
+ pass
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,36 @@
1
+ import os
2
+ from setuptools import setup, find_packages
3
+
4
+ # Read the contents of your README file
5
+ with open("README.md", "r", encoding="utf-8") as fh:
6
+ long_description = fh.read()
7
+
8
+ setup(
9
+ name="VidLingua",
10
+ version="0.1.0a1", # 'a1' indicates Alpha 1
11
+ author="vprayag2005",
12
+ description="A command-line tool that automates the translation and dubbing of YouTube videos.",
13
+ long_description=long_description,
14
+ long_description_content_type="text/markdown",
15
+ url="https://github.com/vprayag2005/VidLingua",
16
+ packages=find_packages(),
17
+ install_requires=[
18
+ "yt-dlp",
19
+ "faster-whisper",
20
+ "deep-translator",
21
+ "edge-tts",
22
+ ],
23
+ entry_points={
24
+ "console_scripts": [
25
+ "Vidlingua=Vidlingua.cli:main",
26
+ ],
27
+ },
28
+ classifiers=[
29
+ "Development Status :: 3 - Alpha",
30
+ "Intended Audience :: Developers",
31
+ "Topic :: Multimedia :: Video",
32
+ "Programming Language :: Python :: 3",
33
+ "Operating System :: OS Independent",
34
+ ],
35
+ python_requires=">=3.8",
36
+ )