Skip to content

Commit

Permalink
Added logger and fixed ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpeach committed Mar 16, 2024
1 parent a16ed1f commit 18945b7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
poetry install
- uses: chartboost/ruff-action@v1
- name: mypy
run: mypy dogbarking
run: poetry run mypy dogbarking
7 changes: 4 additions & 3 deletions dogbarking/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from dogbarking.audio import Player, Recorder
from dogbarking.math import get_rms
from loguru import logger

app = typer.Typer()

Expand Down Expand Up @@ -36,7 +37,7 @@ def nogui(
] = 0.1,
# email: Annotated[Optional[str], "The email to send the alert to."]=None
):
print("Remember to turn your volume all the way up!")
logger.warning("Remember to turn your volume all the way up!")

# Start Recording
audio = pyaudio.PyAudio()
Expand All @@ -57,9 +58,9 @@ def nogui(
# If the rms of the waveform is greater than the threshold, play the sound
for waveform in r:
rms = get_rms(waveform)
print(f"RMS: {rms}")
logger.debug(f"RMS: {rms}")
if rms > thresh:
print(f"Dog Barking at {datetime.now()}")
logger.info(f"Dog Barking at {datetime.now()}")

# Stop the recording, don't want to record the sound we are playing
r.stop()
Expand Down
5 changes: 3 additions & 2 deletions dogbarking/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pyaudio import Stream
from pydantic import BaseModel, PrivateAttr
import numpy
from loguru import logger

# REF: https://gist.github.com/mabdrabo/8678538
FORMAT = pyaudio.paFloat32
Expand Down Expand Up @@ -38,11 +39,11 @@ def stop(self):
def device_index(self) -> int:
for i in range(self.audio.get_device_count()):
devinfo = self.audio.get_device_info_by_index(i)
print("Device %d: %s" % (i, devinfo["name"]))
logger.info("Device %d: %s" % (i, devinfo["name"]))

for keyword in ["mic", "input"]:
if keyword in str(devinfo["name"]).lower():
print("Found an input: device %d - %s" % (i, devinfo["name"]))
logger.info("Found an input: device %d - %s" % (i, devinfo["name"]))
return i

raise Exception("No input device found.")
Expand Down
91 changes: 33 additions & 58 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ numpy = "^1.26.4"
pyaudio = "^0.2.14"
typer-config = "^1.4.0"
ruff = "^0.3.3"
loguru = "^0.7.2"

[tool.poetry.group.dev.dependencies]
black = "^24.3.0"
mypy = "^1.9.0"
pre-commit = "^3.6.2"
types-pyaudio = "^0.2.16.20240106"
types-toml = "^0.10.8.20240310"
ruff = "^0.3.3"

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit 18945b7

Please sign in to comment.