pi-reply-reader 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +143 -0
- package/README.md +402 -39
- package/dist/src/cli.js +137 -10
- package/dist/src/listener.js +532 -0
- package/dist/src/music.js +452 -0
- package/dist/src/outputs.js +29 -4
- package/dist/src/playback.js +170 -46
- package/dist/src/player.js +265 -0
- package/dist/src/project.js +50 -0
- package/dist/src/reading-lock.js +296 -68
- package/dist/src/settings.js +32 -3
- package/dist/src/speech-text.js +581 -64
- package/examples/reply-reader-desktop-audio.service +23 -10
- package/examples/reply-reader-vps-audio.service +57 -0
- package/extensions/reply-reader.ts +920 -106
- package/package.json +3 -2
- package/src/auto-queue.ts +123 -0
- package/src/cli.ts +131 -10
- package/src/listener.ts +522 -0
- package/src/music.ts +474 -0
- package/src/outputs.ts +37 -5
- package/src/pause-key.ts +105 -0
- package/src/playback.ts +179 -48
- package/src/player.ts +255 -0
- package/src/project.ts +46 -0
- package/src/prompts.ts +142 -0
- package/src/reading-lock.ts +364 -66
- package/src/settings.ts +34 -3
- package/src/speech-text.ts +692 -56
package/src/settings.ts
CHANGED
|
@@ -59,11 +59,42 @@ export function loadSpeed(env: NodeJS.ProcessEnv): { speed: number; problem?: st
|
|
|
59
59
|
return inRange(speed) ? { speed } : ignored("speed must be a number from 0.5 to 2.0");
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/** What `/read-auto` saves (S24): `on` reads in full, `questions` only the questions section. */
|
|
63
|
+
export type SavedAuto = "on" | "questions" | "off";
|
|
64
|
+
const AUTO_VALUES: readonly string[] = ["on", "questions", "off"];
|
|
65
|
+
|
|
62
66
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
67
|
+
* The auto-read mode and output the last session chose (S24), from settings.json `autoRead` and `output`. A missing
|
|
68
|
+
* file, key, or a value of the wrong kind means none saved (an unreadable or invalid file is reported by `loadSpeed`
|
|
69
|
+
* at the first reading). Nothing throws.
|
|
65
70
|
*/
|
|
71
|
+
export function loadSaved(env: NodeJS.ProcessEnv): { autoRead?: SavedAuto; output?: string } {
|
|
72
|
+
const path = configFile(env, SETTINGS);
|
|
73
|
+
if (!path) return {};
|
|
74
|
+
let parsed: unknown;
|
|
75
|
+
try {
|
|
76
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
77
|
+
} catch {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
81
|
+
const { autoRead, output } = parsed as { autoRead?: unknown; output?: unknown };
|
|
82
|
+
return {
|
|
83
|
+
...(typeof autoRead === "string" && AUTO_VALUES.includes(autoRead) ? { autoRead: autoRead as SavedAuto } : {}),
|
|
84
|
+
...(typeof output === "string" && output ? { output } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Saves `speed` in settings.json, keeping every other key (see `saveSettings`). */
|
|
66
89
|
export function saveSpeed(env: NodeJS.ProcessEnv, speed: number): void {
|
|
90
|
+
saveSettings(env, { speed });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Saves `values` in settings.json, keeping every other key. Throws an Error naming the file and why when it
|
|
95
|
+
* cannot; an existing file that is not a JSON object is left as it is rather than overwritten.
|
|
96
|
+
*/
|
|
97
|
+
export function saveSettings(env: NodeJS.ProcessEnv, values: Record<string, unknown>): void {
|
|
67
98
|
const path = configFile(env, SETTINGS);
|
|
68
99
|
if (!path) throw new Error(`it was not saved: no config folder (set XDG_CONFIG_HOME or HOME to an absolute path)`);
|
|
69
100
|
const fail = (reason: string) => new Error(`it was not saved to ${path}: ${reason}`);
|
|
@@ -87,7 +118,7 @@ export function saveSpeed(env: NodeJS.ProcessEnv, speed: number): void {
|
|
|
87
118
|
}
|
|
88
119
|
try {
|
|
89
120
|
mkdirSync(dirname(path), { recursive: true });
|
|
90
|
-
writeFileSync(path, `${JSON.stringify({ ...settings,
|
|
121
|
+
writeFileSync(path, `${JSON.stringify({ ...settings, ...values }, null, 2)}\n`);
|
|
91
122
|
} catch (error) {
|
|
92
123
|
throw fail((error as Error).message);
|
|
93
124
|
}
|