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") let sound_size_mul: f32 = std::env::var("SUPERTONIC_SIZE_MUL")
.ok() .ok()
.and_then(|v| v.parse().ok()) .and_then(|v| v.parse().ok())
.unwrap_or(1.5); .unwrap_or(1.0f32);
let model_path = PathBuf::from(&model_dir); let model_path = PathBuf::from(&model_dir);
tts::assets::ensure_assets(&model_path, &hf_repo)?; tts::assets::ensure_assets(&model_path, &hf_repo)?;

View file

@ -28,11 +28,20 @@ class VoiceQueue {
return ((connection as any).queue ??= new VoiceQueue(connection)); return ((connection as any).queue ??= new VoiceQueue(connection));
} }
private play() { private play() {
if (!this.list[0]) return; try {
const player = (this.currentPlayer = createAudioPlayer()); if (!this.list[0]) return;
this.connection.subscribe(player); const player = (this.currentPlayer = createAudioPlayer());
player.once(AudioPlayerStatus.Idle, this.next.bind(this)); const sub = this.connection.subscribe(player);
player.play(this.list[0]); 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) { public enqueue(resource: AudioResource) {
this.list.push(resource); this.list.push(resource);
@ -42,7 +51,11 @@ class VoiceQueue {
} }
} }
public next() { 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.list.shift();
this.play(); this.play();
} }

View file

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