-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
3,309 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
[build-system] | ||
requires = ["setuptools"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
[tool.poetry] | ||
name = "tafrigh" | ||
version = "1.1.4" | ||
description = "تفريغ النصوص وإنشاء ملفات SRT و VTT باستخدام نماذج Whisper وتقنية wit.ai." | ||
authors = ["EasyBooks <[email protected]>"] | ||
license = "MIT" | ||
readme = "README.md" | ||
license = { file = "LICENSE" } | ||
requires-python = ">=3.9" | ||
packages = [{include = "src"}] | ||
keywords = ["tafrigh", "speech-to-text", "wit.ai", "whisper"] | ||
classifiers = [ | ||
"Development Status :: 5 - Production/Stable", | ||
"Intended Audience :: Developers", | ||
|
@@ -17,45 +15,41 @@ classifiers = [ | |
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
"Topic :: Scientific/Engineering :: Artificial Intelligence", | ||
] | ||
authors = [{ name = "الكتب المٌيسّرة", email = "[email protected]" }] | ||
keywords = ["tafrigh", "speech-to-text", "wit.ai", "whisper"] | ||
dependencies = ["tqdm>=4.66.4", "yt-dlp>=2024.4.9"] | ||
homepage = "https://tafrigh.ieasybooks.com" | ||
repository = "https://github.com/ieasybooks/tafrigh" | ||
|
||
[project.optional-dependencies] | ||
wit = [ | ||
"auditok>=0.2.0", | ||
"numpy>=1.26.4", | ||
"pydub>=0.25.1", | ||
"requests>=2.32.0", | ||
] | ||
whisper = [ | ||
"faster-whisper>=1.0.2", | ||
"openai-whisper>=20231117", | ||
"stable-ts>=2.17.2", | ||
] | ||
[tool.poetry.dependencies] | ||
python = ">=3.10,<3.12" | ||
tqdm = ">=4.66.4" | ||
yt-dlp = ">=2024.4.9" | ||
auditok = {version = ">=0.2.0", extras = ["wit"]} | ||
pydub = {version = ">=0.25.1", extras = ["wit"]} | ||
requests = {version = ">=2.32.0", extras = ["wit"]} | ||
faster-whisper = {version = ">=1.0.2", extras = ["whisper"]} | ||
openai-whisper = {git = "https://github.com/openai/whisper.git", extras = ["whisper"]} | ||
stable-ts = {version = ">=2.17.2", extras = ["whisper"]} | ||
|
||
[project.urls] | ||
homepage = "https://github.com/ieasybooks/tafrigh" | ||
repository = "https://github.com/ieasybooks/tafrigh" | ||
[tool.poetry.scripts] | ||
tafrigh = "src.cli:main" | ||
|
||
[project.scripts] | ||
tafrigh = "tafrigh.cli:main" | ||
[tool.poetry.group.dev.dependencies] | ||
pre-commit = "^3.7.1" | ||
|
||
[tool.black] | ||
line-length = 120 | ||
skip-string-normalization = true | ||
[tool.autopep8] | ||
max-line-length = 120 | ||
indent-size = 2 | ||
ignore = ["E121"] | ||
|
||
[tool.isort] | ||
profile = "black" | ||
src_paths = "tafrigh" | ||
line_length = 120 | ||
src_paths = ["src"] | ||
lines_between_types = 1 | ||
lines_after_imports = 2 | ||
case_sensitive = true | ||
include_trailing_comma = true | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
__all__ = [ | ||
"farrigh", | ||
"Config", | ||
"Downloader", | ||
"TranscriptType", | ||
"Writer", | ||
"WhisperRecognizer", | ||
"AudioSplitter", | ||
"WitRecognizer", | ||
] | ||
|
||
|
||
from .cli import farrigh | ||
from .config import Config | ||
from .downloader import Downloader | ||
from .types.transcript_type import TranscriptType | ||
from .writer import Writer | ||
|
||
|
||
try: | ||
from .recognizers.whisper_recognizer import WhisperRecognizer | ||
except ModuleNotFoundError: | ||
pass | ||
|
||
try: | ||
from .audio_splitter import AudioSplitter | ||
from .recognizers.wit_recognizer import WitRecognizer | ||
except ModuleNotFoundError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import os | ||
|
||
from auditok import AudioRegion | ||
from auditok.core import split | ||
from pydub import AudioSegment | ||
from pydub.generators import WhiteNoise | ||
|
||
|
||
class AudioSplitter: | ||
def split( | ||
self, | ||
file_path: str, | ||
output_dir: str, | ||
min_dur: float = 0.5, | ||
max_dur: float = 15, | ||
max_silence: float = 0.5, | ||
energy_threshold: float = 50, | ||
expand_segments_with_noise: bool = False, | ||
noise_seconds: int = 1, | ||
noise_amplitude: int = 0, | ||
) -> list[tuple[str, float, float]]: | ||
segments = split( | ||
file_path, | ||
min_dur=min_dur, | ||
max_dur=max_dur, | ||
max_silence=max_silence, | ||
energy_threshold=energy_threshold, | ||
) | ||
|
||
if expand_segments_with_noise: | ||
segments = [ | ||
( | ||
self._expand_segment_with_noise(segment, noise_seconds, noise_amplitude), | ||
segment.meta.start, | ||
segment.meta.end, | ||
) for segment in segments | ||
] | ||
|
||
return self._save_segments(output_dir, segments) | ||
|
||
def _expand_segment_with_noise( | ||
self, | ||
segment: AudioRegion, | ||
noise_seconds: int, | ||
noise_amplitude: int, | ||
) -> AudioSegment: | ||
|
||
audio_segment = AudioSegment( | ||
segment._data, | ||
frame_rate=segment.sampling_rate, | ||
sample_width=segment.sample_width, | ||
channels=segment.channels, | ||
) | ||
|
||
pre_noise = WhiteNoise().to_audio_segment(duration=noise_seconds * 1000, volume=noise_amplitude) | ||
post_noise = WhiteNoise().to_audio_segment(duration=noise_seconds * 1000, volume=noise_amplitude) | ||
|
||
return pre_noise + audio_segment + post_noise | ||
|
||
def _save_segments( | ||
self, | ||
output_dir: str, | ||
segments: list[AudioSegment | tuple[AudioSegment, float, float]], | ||
) -> list[tuple[str, float, float]]: | ||
segment_paths = [] | ||
|
||
for i, segment in enumerate(segments): | ||
output_file = os.path.join(output_dir, f'segment_{i + 1}.mp3') | ||
|
||
if isinstance(segment, tuple): | ||
segment[0].export(output_file, format='mp3') | ||
segment_paths.append((output_file, segment[1], segment[2])) | ||
else: | ||
segment.save(output_file) | ||
segment_paths.append((output_file, segment.meta.start, segment.meta.end)) | ||
|
||
return segment_paths |
Oops, something went wrong.