feat: initial commit

This commit is contained in:
Ashhhleyyy 2024-04-15 09:51:06 +01:00
commit b1396eb577
Signed by: ash
GPG key ID: 83B789081A0878FB
6 changed files with 160 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*.mp3
*.wav
.direnv/

61
flake.lock Normal file
View file

@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1712883908,
"narHash": "sha256-icE1IJE9fHcbDfJ0+qWoDdcBXUoZCcIJxME4lMHwvSM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a0c9e3aee1000ac2bfb0e5b98c94c946a5d180a9",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

27
flake.nix Normal file
View file

@ -0,0 +1,27 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem(system:
let
pkgs = import nixpkgs {
inherit system;
};
inherit (pkgs) lib;
in
{
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
(python311.withPackages(ps: [
ps.pydub
]))
ffmpeg_6
mpv
];
};
}
);
}

42
generate.py Normal file
View file

@ -0,0 +1,42 @@
from pydub import AudioSegment
import sys
import random
def main(argv: list[str]):
if len(argv) < 7:
print(f"Usage: {argv[0]} <seconds> <seed> <min gap> <max gap> <output> <...audio files>")
exit(1)
duration = int(argv[1]) * 1000
seed = int(argv[2])
min_gap = int(argv[3]) * 1000
max_gap = int(argv[4]) * 1000
output_name = argv[5]
files = argv[6:]
random.seed(seed)
print(files)
clips = list(map(lambda filename: AudioSegment.from_file(filename), files))
output = AudioSegment.silent(0)
total_duration = 0
while total_duration < duration:
sfx = random.choice(clips)
print(duration, total_duration, len(sfx), max_gap)
remaining = duration - total_duration
if remaining < len(sfx) or remaining < min_gap:
silence_duration = remaining
else:
silence_duration = random.randint(min_gap, min(remaining, max_gap))
clip = AudioSegment.silent(silence_duration)
output = output.append(clip, crossfade=0)
total_duration += len(clip)
if total_duration < duration:
output = output.append(sfx, crossfade=0)
total_duration += len(sfx)
output.export(output_name, format="mp3")
if __name__ == '__main__':
main(sys.argv)

26
infinite-whisper.py Normal file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import random
import subprocess
import sys
import time
def play_sfx(jack_name: str, filename: str):
subprocess.call(['mpv', '--no-video', '--ao=jack', f'--jack-port={jack_name}', filename])
def main(argv: list[str]):
if len(argv) < 5:
print(f"Usage: {argv[0]} <jack-output> <min-delay> <max-delay> <...files>")
exit(1)
jack_output = sys.argv[1]
min_delay = int(sys.argv[2])
max_delay = int(sys.argv[3])
audio_files = sys.argv[4:]
while True:
time.sleep(random.randint(min_delay, max_delay))
sfx = random.choice(audio_files)
play_sfx(jack_output, sfx)
if __name__ == '__main__':
main(sys.argv)