From 9b8e6669918a2cc035be80b3348b391efed3fe40 Mon Sep 17 00:00:00 2001 From: dunossauro Date: Thu, 31 Aug 2023 05:31:30 -0300 Subject: [PATCH] Update plot grupo documentation --- README.md | 131 ++++++++++++++++++++++++++++++++++++++++------------ vmh/cli.py | 9 ++-- vmh/plot.py | 38 +++++++++++++++ 3 files changed, 143 insertions(+), 35 deletions(-) create mode 100644 vmh/plot.py diff --git a/README.md b/README.md index 0e4970e..36efee0 100644 --- a/README.md +++ b/README.md @@ -447,39 +447,110 @@ Usage: vmh grammar-check [OPTIONS] FILE [LANG] 3. **Regular Audits**: For long projects with vast subtitle files, consider periodic grammar checks. This will not only help maintain the quality of your content but also ensure that any corrections can be integrated without revisiting large portions of your work. -### All options +### Plot commands -TODO doc +Plotting commands offer tools to visualize audio files, facilitating debugging and comprehension of audio processing. Here's how to use them: + +``` +vmh plot + + Usage: vmh plot [OPTIONS] COMMAND [ARGS]... + + Audio debug tools. + +╭─ Options ───────────────────────────────────────────────────────────────────────────────╮ +│ --help Show this message and exit. │ +╰─────────────────────────────────────────────────────────────────────────────────────────╯ +╭─ Commands ──────────────────────────────────────────────────────────────────────────────╮ +│ compare-waves Plot a figure with N audio waves for comparison. │ +│ plot-wave Plot a figure with audio wave. │ +╰─────────────────────────────────────────────────────────────────────────────────────────╯ +``` + +#### `plot-wave` + +Visualize a single audio waveform to better understand its characteristics. + +##### `--help` + +``` +vmh plot plot-wave --help + + Usage: vmh plot plot-wave [OPTIONS] FILE FIG_NAME + + Plot a figure with audio wave. + +╭─ Arguments ─────────────────────────────────────────────────────────╮ +│ * file TEXT [default: None] [required] │ +│ * fig_name TEXT [default: None] [required] │ +╰─────────────────────────────────────────────────────────────────────╯ +╭─ Options ───────────────────────────────────────────────────────────╮ +│ --help Show this message and exit. │ +╰─────────────────────────────────────────────────────────────────────╯ +``` + +#### `compare-waves` + +Create a comparative plot of multiple audio waves. Useful for comparing the effects of different audio processing steps or algorithms. + +##### `--help` ``` -vmh - - Usage: vmh [OPTIONS] COMMAND [ARGS]... - - Videomaker Helper! - - ╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────╮ - │ --version -v Show VMH version │ - │ --install-completion [bash|zsh|fish|powershell|pwsh] Install completion for the specified │ - │ shell. │ - │ [default: None] │ - │ --show-completion [bash|zsh|fish|powershell|pwsh] Show completion for the specified │ - │ shell, to copy it or customize the │ - │ installation. │ - │ [default: None] │ - │ --help Show this message and exit. │ - ╰───────────────────────────────────────────────────────────────────────────────────────────────────────╯ - ╭─ Commands ────────────────────────────────────────────────────────────────────────────────────────────╮ - │ cache Cache tools. │ - │ cut-silences Removes all silences from an audio file. │ - │ cut-video Edits a video using silences as reference. │ - │ equalize Add Compression and Gain dor audio file. │ - │ extract-audio Extracts the audio from a video. │ - │ grammar-check Check grammar in a tex tfile. │ - │ kdenlive Generates an XML compatible with kdenlive settings. │ - │ silences Checks for silences in a audio file. │ - │ transcribe Transcribes an audio file into subtitles. │ - ╰───────────────────────────────────────────────────────────────────────────────────────────────────────╯ +vmh plot compare-waves --help + + Usage: vmh plot compare-waves [OPTIONS] FILES... FIG_NAME [FORCE_DB] + + Plot a figure with N audio waves for comparison. + +╭─ Arguments ───────────────────────────────────────────────────────────────────────╮ +│ * files FILES... [default: None] [required] │ +│ * fig_name TEXT [default: None] [required] │ +│ force_db [FORCE_DB] Force to use 1 to -1 dbs in plot [default: True] │ +╰───────────────────────────────────────────────────────────────────────────────────╯ +╭─ Options ─────────────────────────────────────────────────────────────────────────╮ +│ --fig-size ... [default: 10, 12] │ +│ --help Show this message and exit. │ +╰───────────────────────────────────────────────────────────────────────────────────╯ +``` + +### All options + +Below are all the available options and commands for Videomaker Helper (VMH): + +To get more details for each command, use vmh ` --help`. + +This condensed guide can serve as a quick reference for anyone using your tool, making it easier to understand at a glance all the capabilities it offers. + +``` +vmh --help + + Usage: vmh [OPTIONS] COMMAND [ARGS]... + + Videomaker Helper! + +╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────╮ +│ --version -v Show VMH version │ +│ --install-completion [bash|zsh|fish|powershell|pwsh] Install completion for the specified │ +│ shell. │ +│ [default: None] │ +│ --show-completion [bash|zsh|fish|powershell|pwsh] Show completion for the specified │ +│ shell, to copy it or customize the │ +│ installation. │ +│ [default: None] │ +│ --help Show this message and exit. │ +╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭─ Commands ─────────────────────────────────────────────────────────────────────────────────────────────╮ +│ cache Cache tools. │ +│ cut-silences Removes all silences from an audio file. │ +│ cut-video Edits a video using silences as reference. │ +│ equalize Add effects for audio file. │ +│ extract-audio Extracts the audio from a video. │ +│ grammar-check Check grammar in a tex tfile. │ +│ kdenlive Generates an XML compatible with kdenlive settings. │ +│ plot Audio debug tools. │ +│ silences Checks for silences in a audio file. │ +│ transcribe Transcribes an audio file into subtitles. │ +╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` ## Distance Flag diff --git a/vmh/cli.py b/vmh/cli.py index 78e99ba..1753507 100644 --- a/vmh/cli.py +++ b/vmh/cli.py @@ -1,13 +1,12 @@ import warnings from pathlib import Path -from shutil import rmtree from typing import Annotated from loguru import logger from rich.console import Console from typer import Argument, Context, Exit, Option, Typer -from vmh import audio, cache, video +from vmh import audio, cache, plot, video from vmh.equalize import process_audio from vmh.kdenlive import cut from vmh.settings import __version__ @@ -19,6 +18,7 @@ app = Typer(help='Videomaker Helper!', no_args_is_help=True) app.add_typer(cache.cache, name='cache', help='Cache tools.') +app.add_typer(plot.plot, name='plot', help='Audio debug tools.') # Options @@ -125,10 +125,9 @@ def cut_silences( def equalize( audio_file: path_arg, output_file: Path = Argument(default='output.wav'), - gain: int = Option(10, '--gain', '-g', help='Add dbs in audio'), ): - """Add Compression and Gain dor audio file.""" - process_audio(str(audio_file.resolve()), str(output_file), gain) + """Add effects for audio file.""" + process_audio(str(audio_file.resolve()), str(output_file)) console.print(f'{output_file} Created') diff --git a/vmh/plot.py b/vmh/plot.py new file mode 100644 index 0000000..bb1049a --- /dev/null +++ b/vmh/plot.py @@ -0,0 +1,38 @@ +import matplotlib.pyplot as plt +from librosa import load +from librosa.display import waveshow +from typer import Typer, Argument + +plot = Typer(no_args_is_help=True) + + +@plot.command() +def plot_wave(file: str, fig_name: str) -> None: + """Plot a figure with audio wave.""" + y, sr = load(file, mono=False) + waveshow(y, sr=sr) + + plt.savefig(fig_name) + + +@plot.command() +def compare_waves( + files: list[str], + fig_name: str, + fig_size: tuple[float, float] = (10, 12), + force_db: bool = Argument(True, help='Force to use 1 to -1 dbs in plot'), +) -> None: + """Plot a figure with N audio waves for comparison.""" + _, ax = plt.subplots( + nrows=len(files), sharex=True, figsize=fig_size, tight_layout=True + ) + + for n, file in enumerate(files): + if force_db: + ax[n].set(ylim=[-1.1, 1.1], title=file) + else: + ax[n].set(title=file) + y_b, sr_b = load(file, mono=False) + waveshow(y_b, sr=sr_b, ax=ax[n]) + + plt.savefig(fig_name)