Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394{ config, lib, pkgs, ...}:let cfg = config.services.dictator; command = c: lib.escapeShellArgs ([ (lib.getExe c.package) ] ++ c.args);in{ options.services.dictator = { enable = lib.mkEnableOption "dictation";
record.package = lib.mkOption { type = lib.types.package; default = pkgs.writeShellScriptBin "pw-record" '' exec ${lib.getExe' pkgs.pipewire "pw-record"} "$@" ''; };
record.args = lib.mkOption { type = lib.types.listOf lib.types.str; default = [ "-" ]; };
transcribe.package = lib.mkPackageOption pkgs "ffmpeg-full" { };
transcribe.model = lib.mkOption { type = lib.types.package; };
transcribe.args = lib.mkOption { type = lib.types.listOf lib.types.str; default = [ "-i" "-" "-af" "whisper=model=${cfg.transcribe.model}:queue=20:destination=-" "-f" "null" "-" ]; };
capture.package = lib.mkOption { type = lib.types.package; default = pkgs.writeShellScriptBin "wl-copy" '' exec ${lib.getExe' pkgs.wl-clipboard "wl-copy"} "$@" ''; };
capture.args = lib.mkOption { type = lib.types.listOf lib.types.str; default = [ "--foreground" ]; }; };
config = lib.mkIf cfg.enable { systemd.user.services.dictator.serviceConfig = { Type = "notify"; NotifyAccess = "all"; RuntimeDirectory = "dictator"; StateDirectory = "dictator";
ExecStart = pkgs.writeShellScript "start" '' exec 3> >( ${command cfg.transcribe} > "$STATE_DIRECTORY/$INVOCATION_ID.txt" ) decoder=$! ${command cfg.record} >&3 & echo $! > "$RUNTIME_DIRECTORY/recorder.pid" exec 3>&- ${lib.getExe' pkgs.systemd "systemd-notify"} --ready wait "$decoder" '';
ExecStop = [ (pkgs.writeShellScript "stop" '' kill "$(cat "$RUNTIME_DIRECTORY/recorder.pid")" while kill -0 "$MAINPID" 2>/dev/null; do ${lib.getExe' pkgs.coreutils "sleep"} 0.05 done '') (pkgs.writeShellScript "capture" '' ${lib.getExe' pkgs.systemd "systemd-run"} --user --collect \ --property="StandardInput=file:$STATE_DIRECTORY/$INVOCATION_ID.txt" \ ${command cfg.capture} '') ]; }; };}