Skip to content

Commit

Permalink
mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpeach committed Mar 16, 2024
1 parent e927e1f commit 73f48e0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dogbarking/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def nogui(
] = 0.1,
save_path: Annotated[
Path, typer.Argument(help="The path to save the audio file to.")
] = "./outputs",
] = Path("./outputs"),
# email: Annotated[Optional[str], "The email to send the alert to."]=None
):
logger.warning("Remember to turn your volume all the way up!")
Expand Down
8 changes: 7 additions & 1 deletion dogbarking/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def device_index(self) -> int:
def __iter__(self) -> Generator[npt.NDArray[np.float32], None, None]: # type: ignore
while True:
out = self.get_buffer()
if len(self._waveform) > self.keep_historical_buffers:
if self._waveform is None:
self._waveform = []
elif len(self._waveform) > self.keep_historical_buffers:
self._waveform.pop(0)
self._waveform.append(out)
yield out
Expand All @@ -76,6 +78,10 @@ def save(self, filepath: Path) -> None:
if not directory.exists():
os.makedirs(directory)

if self._waveform is None:
logger.error("No waveform to save.")
return

waveform = np.concatenate(self._waveform)
sf.write(filepath, waveform, self.sample_freq)
logger.info(f"Saved {filepath}")
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ build-backend = "poetry.core.masonry.api"

[tool.mypy]
plugins = ["numpy.typing.mypy_plugin"]
ignore_missing_imports = true

0 comments on commit 73f48e0

Please sign in to comment.