Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add the flag --lang for the voice command #2

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix initial issues from linter
  • Loading branch information
xmnlab committed Aug 29, 2023
commit a9289b217dfec31000e4efb0befb92aac99ea4ff
3 changes: 0 additions & 3 deletions src/artbox/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"""Cli functions to define the arguments and to call Makim."""
import argparse
import os
import sys

from pathlib import Path

from artbox import __version__
from artbox.sounds import Sound
from artbox.videos import Video
Expand Down
3 changes: 1 addition & 2 deletions src/artbox/sounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json

from math import log2
from pathlib import Path

import aubio
import noisereduce as nr
Expand Down Expand Up @@ -292,7 +291,7 @@ def extract_notes_from_mp3(self) -> list:

# Convert frequency to musical note and add to the list
if frequency > 0: # Ignore zero frequencies (silence)
note = frequency_to_note(frequency)
note = self.frequency_to_note(frequency)
notes.append(note)

with open(output_notes, "w") as f:
Expand Down
9 changes: 5 additions & 4 deletions src/artbox/videos.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
"""
Set of tools for video handling.

ref: https://github.com/ethand91/python-youtube/blob/master/main.py
"""
from pathlib import Path

from moviepy.editor import AudioFileClip, VideoFileClip
from pytube import YouTube

from artbox.base import ArtBox


class Video(ArtBox):
"""Set of tools for handing videos."""

def download_from_youtube(self):
"""Download a youtube video."""
video_url = self.args.get("url", "")
Expand All @@ -22,7 +24,7 @@ def download_from_youtube(self):

try:
video.download(str(self.output_path))
except:
except Exception:
print("Failed to download video")

print("Video was downloaded successfully")
Expand Down Expand Up @@ -88,7 +90,6 @@ def extract_audio(self) -> None:

def remove_audio(self) -> None:
"""Remove the audio from an MP4 file."""

# Load the video
video = VideoFileClip(str(self.input_path))

Expand Down
13 changes: 0 additions & 13 deletions tests/test_audios.py

This file was deleted.

50 changes: 31 additions & 19 deletions tests/test_sounds.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
"""Set of tests for the sounds module."""
from pathlib import Path

import pytest

from artbox.sounds import Sound

TMP_PATH = Path("/tmp/artbox")


@pytest.mark.fixture
def sound():
"""Create a fixture for the Sound object."""
return Sound()


@pytest.mark.skip
def test_extract():
# Example usage
videos_path = VIDEOS_PATH / "Super Mario Theme EPIC VERSION.mp4"
output_path = MEDIA_PATH / "sounds" / "smb-epic-theme.mp3"
extract_audio(str(videos_path), str(output_path))
def test_extract(sound):
"""Test the extraction audio from a video."""
videos_path = TMP_PATH / "Super Mario Theme EPIC VERSION.mp4"
output_path = TMP_PATH / "sounds" / "smb-epic-theme.mp3"
sound.extract_audio(str(videos_path), str(output_path))


@pytest.mark.skip
def test_extract_notes_from_mp3():
# Example usage
mp3_path = MEDIA_PATH / "sounds" / "tok-audio.mp3"
output_notes = MEDIA_PATH / "notes" / "tok-audio.txt"
notes = extract_notes_from_mp3(str(mp3_path), str(output_notes))
def test_extract_notes_from_mp3(sound):
"""Test the extraction of notes from mp3 file."""
mp3_path = TMP_PATH / "sounds" / "tok-audio.mp3"
output_notes = TMP_PATH / "notes" / "tok-audio.txt"
notes = sound.extract_notes_from_mp3(str(mp3_path), str(output_notes))
print("Detected notes:", notes)


@pytest.mark.skip
def test_generate_melody():
notes_path = MEDIA_PATH / "notes" / "tok-audio.txt"
generate_melody(notes_path, total_duration=3.54 * 60)
def test_generate_melody(sound):
"""Test the melody generation from notes."""
notes_path = TMP_PATH / "notes" / "tok-audio.txt"
sound.generate_melody(notes_path, total_duration=3.54 * 60)


@pytest.mark.skip
def test_convert_to_8bit_audio():
# Example usage
def test_convert_to_8bit_audio(sound):
"""Test the audio conversion to 8bits style."""
videos_path = (
MEDIA_PATH
TMP_PATH
/ "videos"
/ "The Legend of Zelda Tears of the Kingdom Official Trailer 3.mp4"
/ "The Legend of Zelda Tears of the Kingdom - Official Trailer 3.mp4"
)
output_path = MEDIA_PATH / "sounds" / "tok8bits.mp3"
convert_to_8bit_audio(str(videos_path), str(output_path))
output_path = TMP_PATH / "sounds" / "tok8bits.mp3"
sound.convert_to_8bit_audio(str(videos_path), str(output_path))
38 changes: 27 additions & 11 deletions tests/test_videos.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,48 @@
"""Set of tests for the videos module."""
from pathlib import Path

import pytest

from artbox.videos import Video

TMP_PATH = Path("/tmp/artbox")


@pytest.mark.fixture
def video():
"""Create a fixture for the Video object."""
return Video()


@pytest.mark.skip
def test_combine_video_audio():
def test_combine_video_and_audio(video):
"""Test the function that combines video and audio."""
# Example usage
# "The Legend of Zelda Tears of the Kingdom – Official Trailer 3.mp4"
video_path = RESULTS_PATH / "peachs-no-audio.mp4"
audio_path = SOUNDS_PATH / "smb-epic-theme.mp3"
output_path = RESULTS_PATH / "peachs-with-music.mp4"
combine_video_audio(str(video_path), str(audio_path), str(output_path))
# "The Legend of Zelda Tears of the Kingdom - Official Trailer 3.mp4"
video_path = TMP_PATH / "peachs-no-audio.mp4"
audio_path = TMP_PATH / "smb-epic-theme.mp3"
output_path = TMP_PATH / "peachs-with-music.mp4"
video.combine_video_and_audio(
str(video_path), str(audio_path), str(output_path)
)


@pytest.mark.skip
def test_download():
def test_download_from_youtube(video):
"""Test the method that downloads videos from youtube."""
# "https://www.youtube.com/watch?v=uHGShqcAHlQ"
for url in [
"https://youtube.com/shorts/gmutDetnBLQ",
"https://youtube.com/watch?v=6pjbaE98ftU",
]:
download(url)
video.download_from_youtube(url)


@pytest.mark.skip
def test_remove_audio():
input_file = VIDEOS_PATH / (
def test_remove_audio(video):
"""Test the function that removes audio from a video."""
input_file = TMP_PATH / (
"Princess Peachs Training Course in The Super Mario Bros Movie.mp4"
)
output_file = "peachs-no-audio.mp4"
remove_audio(input_file, RESULTS_PATH / output_file)
video.remove_audio(input_file, TMP_PATH / output_file)
21 changes: 21 additions & 0 deletions tests/test_voices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Set of tests for the voices module."""
from pathlib import Path

import pytest

from artbox.voices import Voice

TMP_PATH = Path("/tmp/artbox")


@pytest.mark.skip
def test_voice_text_conversion() -> None:
"""Test the conversion from text to audio."""
audio = Voice()
texts_path = TMP_PATH / "texts"

with open(texts_path / "totk.txt") as f:
text = f.read()

title = "The Legend of Zelda Tears of the Kingdom"
audio.convert(title, text)
Loading