Commit 5859923a authored by Joao Gomes's avatar Joao Gomes Committed by Facebook GitHub Bot
Browse files

Apply arc lint to pytorch audio (#2096)

Summary:
Pull Request resolved: https://github.com/pytorch/audio/pull/2096

run: `arc lint --apply-patches --paths-cmd 'hg files -I "./**/*.py"'`

Reviewed By: mthrok

Differential Revision: D33297351

fbshipit-source-id: 7bf5956edf0717c5ca90219f72414ff4eeaf5aa8
parent 0e5913d5
import pytest
import torch
from torchaudio._internal import download_url_to_file
import pytest
class GreedyCTCDecoder(torch.nn.Module):
......@@ -24,7 +24,7 @@ class GreedyCTCDecoder(torch.nn.Module):
for i in best_path:
if i != self.blank:
hypothesis.append(self.labels[i])
return ''.join(hypothesis)
return "".join(hypothesis)
@pytest.fixture
......@@ -33,24 +33,24 @@ def ctc_decoder():
_FILES = {
'en': 'Lab41-SRI-VOiCES-src-sp0307-ch127535-sg0042.flac',
'de': '20090505-0900-PLENARY-16-de_20090505-21_56_00_8.flac',
'en2': '20120613-0900-PLENARY-8-en_20120613-13_46_50_3.flac',
'es': '20130207-0900-PLENARY-7-es_20130207-13_02_05_5.flac',
'fr': '20121212-0900-PLENARY-5-fr_20121212-11_37_04_10.flac',
'it': '20170516-0900-PLENARY-16-it_20170516-18_56_31_1.flac',
"en": "Lab41-SRI-VOiCES-src-sp0307-ch127535-sg0042.flac",
"de": "20090505-0900-PLENARY-16-de_20090505-21_56_00_8.flac",
"en2": "20120613-0900-PLENARY-8-en_20120613-13_46_50_3.flac",
"es": "20130207-0900-PLENARY-7-es_20130207-13_02_05_5.flac",
"fr": "20121212-0900-PLENARY-5-fr_20121212-11_37_04_10.flac",
"it": "20170516-0900-PLENARY-16-it_20170516-18_56_31_1.flac",
}
@pytest.fixture
def sample_speech(tmp_path, lang):
if lang not in _FILES:
raise NotImplementedError(f'Unexpected lang: {lang}')
raise NotImplementedError(f"Unexpected lang: {lang}")
filename = _FILES[lang]
path = tmp_path.parent / filename
if not path.exists():
url = f'https://download.pytorch.org/torchaudio/test-assets/{filename}'
print(f'downloading from {url}')
url = f"https://download.pytorch.org/torchaudio/test-assets/{filename}"
print(f"downloading from {url}")
download_url_to_file(url, path, progress=False)
return path
......@@ -62,13 +62,13 @@ def pytest_addoption(parser):
help=(
"When provided, tests will use temporary directory as Torch Hub directory. "
"Downloaded models will be deleted after each test."
)
),
)
@pytest.fixture(autouse=True)
def temp_hub_dir(tmpdir, pytestconfig):
if not pytestconfig.getoption('use_tmp_hub_dir'):
if not pytestconfig.getoption("use_tmp_hub_dir"):
yield
else:
org_dir = torch.hub.get_dir()
......
import pytest
from torchaudio.pipelines import (
TACOTRON2_GRIFFINLIM_CHAR_LJSPEECH,
TACOTRON2_GRIFFINLIM_PHONE_LJSPEECH,
TACOTRON2_WAVERNN_CHAR_LJSPEECH,
TACOTRON2_WAVERNN_PHONE_LJSPEECH,
)
import pytest
@pytest.mark.parametrize(
'bundle',
"bundle",
[
TACOTRON2_GRIFFINLIM_CHAR_LJSPEECH,
TACOTRON2_GRIFFINLIM_PHONE_LJSPEECH,
TACOTRON2_WAVERNN_CHAR_LJSPEECH,
TACOTRON2_WAVERNN_PHONE_LJSPEECH,
]
],
)
def test_tts_models(bundle):
"""Smoke test of TTS pipeline"""
......
......@@ -8,30 +8,26 @@ import torch
def _parse_args():
parser = argparse.ArgumentParser(
description='Generate opus files for test'
)
parser.add_argument('--num-channels', required=True, type=int)
parser.add_argument('--compression-level', required=True, type=int, choices=list(range(11)))
parser.add_argument('--bitrate', default='96k')
parser = argparse.ArgumentParser(description="Generate opus files for test")
parser.add_argument("--num-channels", required=True, type=int)
parser.add_argument("--compression-level", required=True, type=int, choices=list(range(11)))
parser.add_argument("--bitrate", default="96k")
return parser.parse_args()
def convert_to_opus(
src_path, dst_path,
*, bitrate, compression_level):
def convert_to_opus(src_path, dst_path, *, bitrate, compression_level):
"""Convert audio file with `ffmpeg` command."""
command = ['ffmpeg', '-y', '-i', src_path, '-c:a', 'libopus', '-b:a', bitrate]
command = ["ffmpeg", "-y", "-i", src_path, "-c:a", "libopus", "-b:a", bitrate]
if compression_level is not None:
command += ['-compression_level', str(compression_level)]
command += ["-compression_level", str(compression_level)]
command += [dst_path]
print(' '.join(command))
print(" ".join(command))
subprocess.run(command, check=True)
def _generate(num_channels, compression_level, bitrate):
org_path = 'original.wav'
ops_path = f'{bitrate}_{compression_level}_{num_channels}ch.opus'
org_path = "original.wav"
ops_path = f"{bitrate}_{compression_level}_{num_channels}ch.opus"
# Note: ffmpeg forces sample rate 48k Hz for opus https://stackoverflow.com/a/39186779
# 1. generate original wav
......@@ -46,5 +42,5 @@ def _main():
_generate(args.num_channels, args.compression_level, args.bitrate)
if __name__ == '__main__':
if __name__ == "__main__":
_main()
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment