From b1396eb577969451a70b451cca15df9f72b7dca9 Mon Sep 17 00:00:00 2001 From: Ashhhleyyy Date: Mon, 15 Apr 2024 09:51:06 +0100 Subject: [PATCH] feat: initial commit --- .envrc | 1 + .gitignore | 3 +++ flake.lock | 61 +++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 27 ++++++++++++++++++++ generate.py | 42 +++++++++++++++++++++++++++++++ infinite-whisper.py | 26 +++++++++++++++++++ 6 files changed, 160 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 generate.py create mode 100644 infinite-whisper.py diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..594f55a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.mp3 +*.wav +.direnv/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..13f9133 --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..305659d --- /dev/null +++ b/flake.nix @@ -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 + ]; + }; + } + ); +} diff --git a/generate.py b/generate.py new file mode 100644 index 0000000..c4a7c84 --- /dev/null +++ b/generate.py @@ -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]} <...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) diff --git a/infinite-whisper.py b/infinite-whisper.py new file mode 100644 index 0000000..c4fa695 --- /dev/null +++ b/infinite-whisper.py @@ -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]} <...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)