Compare commits

...

2 commits

Author SHA1 Message Date
Geoffrey Frogeye 84268f3c47
Add whisperx 2024-11-15 22:41:32 +01:00
Geoffrey Frogeye 22b844df2c
Misc fixes 2024-11-07 14:48:25 +01:00
6 changed files with 114 additions and 72 deletions

View file

@ -8,7 +8,7 @@
./common.nix
./desktop
./dev
./extra.nix
./extra
./gaming
./git
./gpg

View file

@ -874,7 +874,7 @@ class MprisProvider(Section, ThreadedUpdater):
"{{ playerName }} {{ status }}",
"{{ album }}",
"{{ artist }}",
"{{ duration(position) }}|{{ duration(mpris:length) }}" " {{ title }}",
"{{ duration(position) }}/{{ duration(mpris:length) }}" " {{ title }}",
]
# nf-fd icons don't work (UTF-16?)
@ -894,6 +894,8 @@ class MprisProvider(Section, ThreadedUpdater):
3: "",
}
MAX_SECTION_LENGTH = 40
def __init__(self, theme: int | None = None):
ThreadedUpdater.__init__(self)
Section.__init__(self, theme)
@ -926,6 +928,8 @@ class MprisProvider(Section, ThreadedUpdater):
if text:
if i in self.ICONS:
text = f"{self.ICONS[i]} {text}"
if len(text) > self.MAX_SECTION_LENGTH:
text = text[: self.MAX_SECTION_LENGTH - 1] + ""
section.updateText(text)
else:
section.updateText(None)

View file

@ -21,6 +21,7 @@
# Communication
signal-desktop
(pkgs.callPackage ./whisperx.nix {}) # Transcribe voice messages
# downloading
# transmission TODO Collision if both transmissions are active?

37
hm/extra/whisperx.nix Normal file
View file

@ -0,0 +1,37 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.python3Packages.buildPythonPackage {
pname = "whisperx";
version = "2024-08-19";
# pypi doesn't have the requirements.txt file, and it's required
src = pkgs.fetchFromGitHub {
owner = "m-bain";
repo = "whisperX";
rev = "9e3a9e0e38fcec1304e1784381059a0e2c670be5"; # git doesn't have tags
hash = "sha256-IVtn9fe/yi4+fbH57s9LoiREnMZ2nhEObp1a4R/7gHg=";
};
pyproject = true;
dependencies = [
pkgs.python3Packages.torch
pkgs.python3Packages.torchaudio
(pkgs.python3Packages.faster-whisper.overrideAttrs (old: {
# 1.0.2 is actually breaking APIs (requires hotwords argument)
src = pkgs.fetchFromGitHub {
owner = "SYSTRAN";
repo = "faster-whisper";
rev = "v1.0.0";
hash = "sha256-0fE8X1d6CgDrrHtRudksN/tIGRtBKMvoNwkSVyFNda4=";
};
}))
pkgs.python3Packages.transformers
pkgs.python3Packages.pyannote-audio # Not in the requirements.txt for some reason
pkgs.python3Packages.pandas
pkgs.python3Packages.nltk
];
build-system = [
pkgs.python3Packages.setuptools
];
pythonImportsCheck = [
"whisperx"
];
}

View file

@ -213,13 +213,13 @@ elif sys.argv[1] in ("merge", "mr"):
# so jj has a current bookmark.
mr = glab_get_mr(sys.argv[3])
jj.run("git", "fetch")
if len(JujutsuCommit.log(f"{mr.source_branch} | {mr.target_branch}")) == 1:
if len(jj.log(f"{mr.source_branch} | {mr.target_branch}")) == 1:
title = re.sub(r"^(WIP|Draft): ", "", mr.title)
jj.run("new", mr.source_branch)
jj.run("describe", "-m", title)
jj.run("bookmark", "move", mr.source_branch)
else:
jj.run("bookmark", "edit", mr.source_branch)
jj.run("edit", mr.source_branch)
elif sys.argv[2] in (
# If no MR number/branch is given, insert the current bookmark,
# as the current branch concept doesn't exist in jj

View file

@ -1,7 +1,9 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash --pure
#! nix-shell -p bash coreutils imagemagick libjpeg optipng ffmpeg diffutils
# vim: filetype=sh
set -euo pipefail
# Optimizes everything the script can find in a folder,
# meaning it will compress files as much as possible,
@ -13,14 +15,13 @@
# TODO Lots of dupplicated code there
# TODO Maybe replace part with https://github.com/toy/image_optim?
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
dir=${1:-$PWD}
total=$(mktemp)
echo -n 0 > $total
echo -n 0 > "$total"
function showtotal {
echo "Total saved: $(cat "$total") bytes"
rm $total
rm "$total"
exit
}
@ -28,11 +29,11 @@ trap showtotal SIGTERM SIGINT SIGFPE
function doReplace { # candidate original
mv "$c" "$o"
saved=$(($os - $cs))
perc=$((100 * $saved / $os))
saved=$((os - cs))
perc=$((100 * saved / os))
echo "→ $os ⇒ $cs (saved $saved bytes, or ${perc}%)"
newtotal=$(($(cat $total) + $saved))
echo -n $newtotal > $total
newtotal=$(($(cat "$total") + saved))
echo -n $newtotal > "$total"
}
function replace { # candidate original
@ -52,17 +53,17 @@ function replace { # candidate original
# Size verifications
cs=$(wc -c "$c" | cut -d' ' -f1)
os=$(wc -c "$o" | cut -d' ' -f1)
if [ $cs -le 0 ]; then
if [ "$cs" -le 0 ]; then
echo "→ Candidate is empty, skipping!"
rm "$c"
return
fi
if [ $cs -eq $os ]; then
if [ "$cs" -eq "$os" ]; then
echo "→ Candidate weight the same, skipping."
rm "$c"
return
fi
if [ $cs -gt $os ]; then
if [ "$cs" -gt "$os" ]; then
echo "→ Candidate is larger, skipping."
rm "$c"
return
@ -71,76 +72,75 @@ function replace { # candidate original
doReplace "$c" "$o"
}
function replaceImg { # candidate original
# With bitmap verification
c="$1"
o="$2"
# File verifications
if [ ! -f "$o" ]; then
echo "→ Original is inexistant, skipping!"
return
fi
if [ ! -f "$c" ]; then
echo "→ Candidate is inexistant, skipping!"
return
fi
# Size verifications
cs=$(wc -c "$c" | cut -d' ' -f1)
os=$(wc -c "$o" | cut -d' ' -f1)
if [ $cs -le 0 ]; then
echo "→ Candidate is empty, skipping!"
rm "$c"
return
fi
if [ $cs -eq $os ]; then
echo "→ Candidate weight the same, skipping."
rm "$c"
return
fi
if [ $cs -gt $os ]; then
echo "→ Candidate is larger, skipping."
rm "$c"
return
fi
# Bitmap verification
ppmc="$(mktemp --suffix .ppm)"
ppmo="$(mktemp --suffix .ppm)"
convert "$c" "$ppmc"
convert "$o" "$ppmo"
if cmp --silent "$ppmo" "$ppmc"; then
doReplace "$c" "$o"
else
echo "→ Candidate don't have the same bit map as original, skipping!"
fi
rm -f "$ppmc" "$ppmo" "$c"
}
# function replaceImg { # candidate original
# # With bitmap verification
#
# c="$1"
# o="$2"
#
# # File verifications
# if [ ! -f "$o" ]; then
# echo "→ Original is inexistant, skipping!"
# return
# fi
# if [ ! -f "$c" ]; then
# echo "→ Candidate is inexistant, skipping!"
# return
# fi
#
# # Size verifications
# cs=$(wc -c "$c" | cut -d' ' -f1)
# os=$(wc -c "$o" | cut -d' ' -f1)
# if [ $cs -le 0 ]; then
# echo "→ Candidate is empty, skipping!"
# rm "$c"
# return
# fi
# if [ $cs -eq $os ]; then
# echo "→ Candidate weight the same, skipping."
# rm "$c"
# return
# fi
# if [ $cs -gt $os ]; then
# echo "→ Candidate is larger, skipping."
# rm "$c"
# return
# fi
#
# # Bitmap verification
# ppmc="$(mktemp --suffix .ppm)"
# ppmo="$(mktemp --suffix .ppm)"
# convert "$c" "$ppmc"
# convert "$o" "$ppmo"
#
# if cmp --silent "$ppmo" "$ppmc"; then
# doReplace "$c" "$o"
# else
# echo "→ Candidate don't have the same bit map as original, skipping!"
# fi
# rm -f "$ppmc" "$ppmo" "$c"
#
# }
# JPEG (requires jpegtran)
while read image
while read -r image
do
if [ -z "$image" ]; then continue; fi
echo Processing $image
echo Processing "$image"
prog=$(mktemp --suffix .jpg)
jpegtran -copy all -progressive "$image" > "$prog"
echo "→ Progressive done"
progs=$(wc -c "$prog" | cut -d' ' -f1)
replace "$prog" "$image"
done <<< "$(find "$dir/" -type f -iregex ".+.jpe?g$")"
# PNG (requires optipng)
while read image
while read -r image
do
if [ -z "$image" ]; then continue; fi
echo Processing $image
echo Processing "$image"
temp=$(mktemp --suffix .png)
cp "$image" "$temp"
@ -152,13 +152,13 @@ do
done <<< "$(find "$dir/" -type f -iname "*.png")"
# FLAC (requires ffmpeg)
while read music
while read -r music
do
if [ -z "$music" ]; then continue; fi
echo Processing $music
echo "Processing $music"
temp=$(mktemp --suffix .flac)
ffmpeg -y -i "$music" -compression_level 8 "$temp"
ffmpeg -nostdin -y -i "$music" -compression_level 8 "$temp"
echo "→ Optimize done"
replace "$temp" "$music"
@ -186,6 +186,6 @@ done <<< "$(find "$dir/" -type f -iname "*.flac")"
# - I might want to keep editor data and/or ids for some of them
# So rather use scour explicitely when needed
${SCRIPT_DIR}/cleandev
cleandev
showtotal