Add TTS volume, a browser preview, and the split-audio plan
This commit is contained in:
+12
-2
@@ -276,7 +276,7 @@ export class AudioManager {
|
||||
this.modules = [];
|
||||
}
|
||||
|
||||
async play(file: string): Promise<void> {
|
||||
async play(file: string, volume?: number): Promise<void> {
|
||||
if (!this.available) throw new AudioUnavailableError(this.error ?? "audio is not available");
|
||||
|
||||
const binary = process.env.VESKSLOP_FFPLAY ?? "ffplay";
|
||||
@@ -284,7 +284,17 @@ export class AudioManager {
|
||||
// Lead-in silence: give Discord's voice pipeline a moment to settle
|
||||
// before the first syllable, so the attack is not swallowed.
|
||||
const args = ["-nodisp", "-autoexit", "-loglevel", "error"];
|
||||
if (LEAD_MS > 0) args.push("-af", `adelay=${LEAD_MS}:all=1`);
|
||||
const filters: string[] = [];
|
||||
if (LEAD_MS > 0) filters.push(`adelay=${LEAD_MS}:all=1`);
|
||||
|
||||
// Volume percent, 0-200. 100 keeps the level as synthesized. ffplay's own
|
||||
// -volume stops at 100, so use the volume filter and its dB scale.
|
||||
if (typeof volume === "number" && Number.isFinite(volume) && volume !== 100) {
|
||||
const gain = volume > 0 ? `${(20 * Math.log10(volume / 100)).toFixed(2)}dB` : "0";
|
||||
filters.push(`volume=${gain}`);
|
||||
}
|
||||
|
||||
if (filters.length) args.push("-af", filters.join(","));
|
||||
args.push(file);
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user