Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion scripts/spectrogram.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ while read; do

if [ -n "${analyzing_now}" ] && [ -f "${analyzing_now}" ]; then
spectrogram_png=${EXTRACTED}/spectrogram.png
sox -V1 "${analyzing_now}" -n remix 1 rate 24k spectrogram -c "${analyzing_now//$HOME\//}" -o "${spectrogram_png}"
# Check if RAW_SPECTROGRAM is 1
if [ "$RAW_SPECTROGRAM" == "1" ]; then
# If it is, add "-r" as an argument to the SOX command
sox -V1 "${analyzing_now}" -n remix 1 rate 24k spectrogram -c "${analyzing_now//$HOME\//}" -o "${spectrogram_png}" -r
else
sox -V1 "${analyzing_now}" -n remix 1 rate 24k spectrogram -c "${analyzing_now//$HOME\//}" -o "${spectrogram_png}"
fi
fi
next=$(( now + looptime ))
fi
Expand Down
7 changes: 4 additions & 3 deletions scripts/utils/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ def extract_safe(in_file, out_file, start, stop):
extract(in_file, out_file, safe_start, safe_stop)


def spectrogram(in_file, title, comment, raw=False):
def spectrogram(in_file, title, comment, raw=0):
fd, tmp_file = tempfile.mkstemp(suffix='.png')
os.close(fd)
args = ['sox', '-V1', f'{in_file}', '-n', 'remix', '1', 'rate', '24k', 'spectrogram',
'-t', '', '-c', '', '-o', tmp_file]
args += ['-r'] if raw else []
args += ['-r'] if int(raw) else []

result = subprocess.run(args, check=True, capture_output=True)
ret = result.stdout.decode('utf-8')
err = result.stderr.decode('utf-8')
Expand Down Expand Up @@ -81,7 +82,7 @@ def extract_detection(file: ParseFileName, detection: Detection):
else:
os.makedirs(new_dir, exist_ok=True)
extract_safe(file.file_name, new_file, detection.start, detection.stop)
spectrogram(new_file, detection.common_name, new_file.replace(os.path.expanduser('~/'), ''))
spectrogram(new_file, detection.common_name, new_file.replace(os.path.expanduser('~/'), ''), conf['RAW_SPECTROGRAM'])
return new_file


Expand Down