feat: fix sound size

This commit is contained in:
kimpure 2026-07-19 09:13:27 +00:00
parent 47aaf81e2d
commit 7e6ad370f4
No known key found for this signature in database
3 changed files with 22 additions and 9 deletions

View file

@ -48,7 +48,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let sound_size_mul: f32 = std::env::var("SUPERTONIC_SIZE_MUL")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(1.5);
.unwrap_or(1.0f32);
let model_path = PathBuf::from(&model_dir);
tts::assets::ensure_assets(&model_path, &hf_repo)?;

View file

@ -28,11 +28,20 @@ class VoiceQueue {
return ((connection as any).queue ??= new VoiceQueue(connection));
}
private play() {
if (!this.list[0]) return;
const player = (this.currentPlayer = createAudioPlayer());
this.connection.subscribe(player);
player.once(AudioPlayerStatus.Idle, this.next.bind(this));
player.play(this.list[0]);
try {
if (!this.list[0]) return;
const player = (this.currentPlayer = createAudioPlayer());
const sub = this.connection.subscribe(player);
if (!sub) {
this.next();
return;
}
player.once(AudioPlayerStatus.Idle, this.next.bind(this));
player.play(this.list[0]);
} catch (err) {
console.error(`VoiceQueue play failed: ${err}`);
this.next();
}
}
public enqueue(resource: AudioResource) {
this.list.push(resource);
@ -42,7 +51,11 @@ class VoiceQueue {
}
}
public next() {
this.currentPlayer?.removeAllListeners(AudioPlayerStatus.Idle);
try {
this.currentPlayer?.removeAllListeners(AudioPlayerStatus.Idle);
} catch (err) {
console.log(`VoiceQueue next listener remove failed: ${err}`);
}
this.list.shift();
this.play();
}

View file

@ -80,11 +80,11 @@ export namespace TTSModelBase {
export function bufferToAudioResource(buf: Buffer): AudioResource {
const stream = Readable.from(buf);
const resource = createAudioResource(stream, {
inlineVolume: true,
// inlineVolume: true,
inputType: StreamType.Arbitrary,
});
resource.volume?.setVolume(0.3);
// resource.volume?.setVolume(0.3);
return resource;
}
export function hashAudioFile(audio: string, suffix: string = ""): string {