alpha
Login
or
Join now
lass.pds.lassul.us
/
superconfig
Star
0
Fork
1
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
This repository has no description
Star
0
Fork
1
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
1
Pipelines
tools.whatsong: init
author
lassulus
date
8 months ago
(Jan 27, 2026, 3:12 AM CET)
commit
cd18f86b
cd18f86b2c5d3902e754c82eb739d2584fe56efa
parent
fe0dd00d
fe0dd00d740f61542e2df93a24a05066169e8e87
+64
2 changed files
Expand all
Collapse all
Unified
Split
tools
whatsong
flake-module.nix
whatsong.sh
+17
tools/whatsong/flake-module.nix
View file
Reviewed
···
1
1
+
{ ... }:
2
2
+
{
3
3
+
perSystem =
4
4
+
{ pkgs, ... }:
5
5
+
{
6
6
+
packages.whatsong = pkgs.writeShellApplication {
7
7
+
name = "whatsong";
8
8
+
runtimeInputs = [
9
9
+
pkgs.sox
10
10
+
pkgs.songrec
11
11
+
pkgs.jq
12
12
+
pkgs.yt-dlp
13
13
+
];
14
14
+
text = builtins.readFile ./whatsong.sh;
15
15
+
};
16
16
+
};
17
17
+
}
+47
tools/whatsong/whatsong.sh
View file
Reviewed
···
1
1
+
#!/usr/bin/env bash
2
2
+
set -euo pipefail
3
3
+
4
4
+
# Recording duration in seconds (default: 5)
5
5
+
DURATION=${1:-5}
6
6
+
7
7
+
# Temporary file for audio
8
8
+
TEMP_AUDIO=$(mktemp /tmp/whatsong-XXXXXX.wav)
9
9
+
trap 'rm -f "$TEMP_AUDIO"' EXIT
10
10
+
11
11
+
echo "Listening for $DURATION seconds..." >&2
12
12
+
13
13
+
# Record audio from default microphone
14
14
+
# songrec needs specific format: 16kHz mono
15
15
+
rec -q -r 16000 -c 1 -b 16 "$TEMP_AUDIO" trim 0 "$DURATION" 2>/dev/null || true
16
16
+
17
17
+
if [ ! -s "$TEMP_AUDIO" ]; then
18
18
+
echo "Error: No audio recorded" >&2
19
19
+
exit 1
20
20
+
fi
21
21
+
22
22
+
echo "Identifying song..." >&2
23
23
+
24
24
+
# Run songrec and get JSON output
25
25
+
RESULT=$(songrec recognize --json "$TEMP_AUDIO" 2>/dev/null)
26
26
+
27
27
+
if [ -z "$RESULT" ] || [ "$RESULT" = "null" ]; then
28
28
+
echo "Could not identify song" >&2
29
29
+
exit 1
30
30
+
fi
31
31
+
32
32
+
# Extract artist and title
33
33
+
ARTIST=$(echo "$RESULT" | jq -r '.track.subtitle // empty')
34
34
+
TITLE=$(echo "$RESULT" | jq -r '.track.title // empty')
35
35
+
36
36
+
if [ -z "$TITLE" ]; then
37
37
+
echo "Could not identify song" >&2
38
38
+
exit 1
39
39
+
fi
40
40
+
41
41
+
echo "Found: $ARTIST - $TITLE" >&2
42
42
+
43
43
+
# Search YouTube and get first result
44
44
+
SEARCH_QUERY="$ARTIST $TITLE"
45
45
+
echo "Searching YouTube..." >&2
46
46
+
47
47
+
yt-dlp --dump-json "ytsearch1:$SEARCH_QUERY" 2>/dev/null | jq -r '.webpage_url'