Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wsanchez committed Oct 26, 2023
1 parent 09c3f8e commit 50bc37e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
7 changes: 2 additions & 5 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ extend-exclude =

# Codes: https://flake8.pycqa.org/en/latest/user/error-codes.html
extend-ignore =

# One-line docstring should fit on one line with quotes
D200,

# No blank lines allowed after function docstring
#D202,

# 1 blank line required between summary line and description
D205,

Expand All @@ -44,7 +41,7 @@ extend-ignore =
N802,

# argument name should be lowercase
#N803,
N803,

# variable in function should be lowercase
N806,
Expand Down
1 change: 1 addition & 0 deletions requirements/requirements-direct.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
attrs==22.2.0
click==8.1.3
openai-whisper==20230918
pydub==0.25.1
Twisted==22.10.0
1 change: 1 addition & 0 deletions requirements/requirements-mypy.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mypy==0.981
pydub-stubs==0.25.1.1
40 changes: 26 additions & 14 deletions src/transmissions/indexer/_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from datetime import timedelta as TimeDelta
from datetime import timezone as TimeZone
from enum import Enum
from hashlib import sha256
from os import walk
from pathlib import Path
from re import Pattern
from re import compile as regex
from typing import ClassVar

from attrs import Factory, frozen
from pydub import AudioSegment
from twisted.logger import Logger
from whisper import Whisper
from whisper import load_model as loadWhisper
Expand Down Expand Up @@ -145,7 +147,9 @@ def whisper() -> Whisper:

_whisper: Whisper = Factory(whisper)

def _transmissionFromFile(self, path: Path) -> Transmission:
def _transmissionFromFile(
self, path: Path, _expensiveParts: bool = False
) -> Transmission:
"""
Returns a Transmission based on the given Path to a file.
"""
Expand Down Expand Up @@ -194,38 +198,46 @@ def _transmissionFromFile(self, path: Path) -> Transmission:
else:
station = f"{stationType} {stationName}"

# # Channel
# Channel

try:
channel = match.group("channel1")
except IndexError:
channel = match.group("channel2")

# # Duration
if _expensiveParts:
# Duration

# duration = TimeDelta(0) # FIXME
audio = AudioSegment.from_wav(str(path))
duration = TimeDelta(milliseconds=len(audio))

# # Checksum
# Checksum

# checksum = sha256()
# with path.open("rb") as f:
# checksum.update(f.read())
hasher = sha256()
with path.open("rb") as f:
hasher.update(f.read())
sha256Digest = hasher.hexdigest()

# # Speech -> text
# text = self._whisper.transcribe(str(path))
# Speech -> text
text = self._whisper.transcribe(str(path))

# Packaged up
else:
duration = None
sha256Digest = None
text = None

# Return result

return Transmission(
eventID=self.eventID,
station=station,
system=system,
channel=channel,
startTime=startTime,
duration=None,
duration=duration,
path=path,
sha256=None, # checksum.hexdigest(),
text=None, # text
sha256=sha256Digest,
text=text,
)

def transmissions(self) -> Iterable[Transmission | None]:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ deps =
coverage: {[testenv:coverage_report]deps}

setenv =
PY_MODULE=deploy
PY_MODULE=transmissions

PYTHONPYCACHEPREFIX={envtmpdir}/pycache

Expand Down

0 comments on commit 50bc37e

Please sign in to comment.