Skip to content

Commit

Permalink
Issue 59: allow arbitrary input sound files to mix with. Add tests fo…
Browse files Browse the repository at this point in the history
…r such.
  • Loading branch information
jeffwright13 committed May 26, 2022
1 parent 35f20ae commit 5df6b33
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 5 deletions.
Binary file added apgfiles/beyond_the_infinite.mp4
Binary file not shown.
Binary file added apgfiles/meditation.mp3
Binary file not shown.
2 changes: 1 addition & 1 deletion audio_program_generator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def generate_subcommand(
),
sound_path: Path = typer.Argument(
None,
help="Path to .wav file to mix with generated speech. [optional]",
help="Path to input sound file to mix with generated speech. [optional]",
),
output_path: Path = typer.Option(
None,
Expand Down
2 changes: 1 addition & 1 deletion audio_program_generator/apg.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def invoke(self) -> BytesIO:
with alive_bar(0):
self._gen_speech()
if self.sound_file:
bkgnd = AudioSegment.from_file(self.sound_file, format="wav")
bkgnd = AudioSegment.from_file(self.sound_file)
self.mix_file = self._mix(self.speech_file, bkgnd, self.attenuation)
self.mix_file.export(self.result, format=self.output_format)
else:
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ def phrase_path() -> Path:


@pytest.fixture(scope="session")
def sound_path() -> Path:
"""Path to a known good WAV file.
def sound_path(format=".wav") -> Path:
"""Path to a known good input file.
mustang4.wav
Source: https://freesound.org/people/VacekH/sounds/205507/
License: CC0 1.0
"""
return Path(__file__).absolute().parent / "resources/mustang4.wav"
return Path(__file__).absolute().parent / f"resources/mustang4{format}"


@pytest.fixture(scope="session")
Expand Down
Binary file added tests/resources/mustang.flac
Binary file not shown.
Binary file added tests/resources/mustang.mp3
Binary file not shown.
Binary file added tests/resources/mustang.mp4
Binary file not shown.
Binary file added tests/resources/mustang.ogg
Binary file not shown.
29 changes: 29 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,32 @@ def test_apg_main_specify_output_filetypes(
assert output_path.is_file()
assert output_path.suffix == expected_filetype
assert len(output_path.read_bytes()) > 0


@pytest.mark.parametrize(
"input_format",
[
(".wav"),
(".mp3"),
(".ogg"),
(".mp4"),
(".flac"),
],
)
def test_apg_main_different_input_filetypes(
clean,
phrase_path: Path,
sound_path: Path,
output_path,
input_format
):
sys.argv = ["apg", str(phrase_path), str(sound_path)]
expected_filetype = ".wav"
try:
apg_main()
except SystemExit:
print("f")
assert output_path.exists()
assert output_path.is_file()
assert output_path.suffix == expected_filetype
assert len(output_path.read_bytes()) > 0

0 comments on commit 5df6b33

Please sign in to comment.