-
Notifications
You must be signed in to change notification settings - Fork 17
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
1 parent
9f28750
commit 4290c32
Showing
4 changed files
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,6 @@ __pycache__/ | |
|
||
/.venv/ | ||
*.whl | ||
|
||
/*.so | ||
/*.wav |
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,21 @@ | ||
#!/usr/bin/env python3 | ||
import subprocess | ||
import venv | ||
from pathlib import Path | ||
|
||
_DIR = Path(__file__).parent | ||
_PROGRAM_DIR = _DIR.parent | ||
_VENV_DIR = _PROGRAM_DIR / ".venv" | ||
|
||
# Create virtual environment | ||
builder = venv.EnvBuilder(with_pip=True) | ||
context = builder.ensure_directories(_VENV_DIR) | ||
builder.create(_VENV_DIR) | ||
|
||
# Upgrade dependencies | ||
pip = [context.env_exe, "-m", "pip"] | ||
subprocess.check_call(pip + ["install", "--upgrade", "pip"]) | ||
subprocess.check_call(pip + ["install", "--upgrade", "setuptools", "wheel"]) | ||
|
||
# Install requirements | ||
subprocess.check_call(pip + ["install", "-r", str(_PROGRAM_DIR / "requirements_dev.txt")]) |
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,13 @@ | ||
#!/usr/bin/env python3 | ||
import subprocess | ||
import sys | ||
import venv | ||
from pathlib import Path | ||
|
||
_DIR = Path(__file__).parent | ||
_PROGRAM_DIR = _DIR.parent | ||
_VENV_DIR = _PROGRAM_DIR / ".venv" | ||
_TEST_DIR = _PROGRAM_DIR / "tests" | ||
|
||
context = venv.EnvBuilder().ensure_directories(_VENV_DIR) | ||
subprocess.check_call([context.env_exe, "-m", "pytest", _TEST_DIR] + sys.argv[1:]) |
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,46 @@ | ||
"""Processes a WAV file using the audio processor.""" | ||
|
||
import argparse | ||
import wave | ||
|
||
from webrtc_noise_gain import AudioProcessor | ||
|
||
SAMPLES_10MS = 160 | ||
|
||
|
||
def main() -> None: | ||
"""Main entry point.""" | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("wav_in", help="WAV input file (16Khz 16-bit mono)") | ||
parser.add_argument("wav_out", help="WAV output file") | ||
parser.add_argument("--auto-gain", type=int, default=0, choices=range(32)) | ||
parser.add_argument("--noise-suppression", type=int, default=0, choices=range(5)) | ||
args = parser.parse_args() | ||
|
||
audio_processor = AudioProcessor(args.auto_gain, args.noise_suppression) | ||
|
||
wav_in: wave.Wave_read = wave.open(args.wav_in, "rb") | ||
with wav_in: | ||
assert wav_in.getframerate() == 16000, "Sample rate must be 16Khz" | ||
assert wav_in.getsampwidth() == 2, "Sample width must be 16-bit" | ||
assert wav_in.getnchannels() == 1, "Only mono audio is supported" | ||
|
||
wav_out: wave.Wave_write = wave.open(args.wav_out, "wb") | ||
with wav_out: | ||
wav_out.setframerate(16000) | ||
wav_out.setsampwidth(2) | ||
wav_out.setnchannels(1) | ||
|
||
# Process in 10ms chunks | ||
chunk = wav_in.readframes(SAMPLES_10MS) | ||
while chunk: | ||
if len(chunk) < SAMPLES_10MS: | ||
wav_out.writeframes(chunk) | ||
break | ||
|
||
wav_out.writeframes(audio_processor.Process10ms(chunk).audio) | ||
chunk = wav_in.readframes(SAMPLES_10MS) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |