murpyh
murpyh
DIAdiscord.js - Imagine an app
Created by murpyh on 5/29/2024 in #djs-questions
Streaming .ogg file as it is created
I'm trying to make a bot play text-to-speech audio over voice chat using a speech synthesizer called RHVoice. When invoked from the command line using child_process.exec(), it takes an input file and converts it into speech, inserting into the audio file as it processes words. If I open this file with something like VLC while it's running it adapts to this "stream" behavior and increases the audio length as new information gets added. However, I don't know how to replicate this behavior with @discordjs/voice AudioResources. Originally I waited until RHVoice generated the entire message before streaming into VC:
fs.writeFileSync("./tts-message.txt", arguments[0]);
exec('RHVoice-test -i tts-message.txt -o tts-voice.ogg', (err) => {
if (err) {
throw new Error(err);
}

let resource = createAudioResource(fs.createReadStream('./tts-voice.ogg', {
inputType: StreamType.OggOpus
}));
ttsPlayer.play(resource);
});
fs.writeFileSync("./tts-message.txt", arguments[0]);
exec('RHVoice-test -i tts-message.txt -o tts-voice.ogg', (err) => {
if (err) {
throw new Error(err);
}

let resource = createAudioResource(fs.createReadStream('./tts-voice.ogg', {
inputType: StreamType.OggOpus
}));
ttsPlayer.play(resource);
});
This works, but for longer messages results in a large delay. If I create and play the AudioResource outside of the exec callback then it just plays the last sent TTS message. Any examples of this "play-as-created" behavior would be helpful. I believe bots which stream from music sites like YouTube do the same thing. Also, RHVoice tries to play using system audio if no output file is specified, so it's possible I could get a virtual audio cable and output that, but then it would be difficult to play speech in more than one server at a time discord.js version 14.15.2, node version 16.17.0
5 replies
DIAdiscord.js - Imagine an app
Created by murpyh on 3/17/2023 in #djs-questions
how do i get a description of CombinedPropertyErrors in vscode?
22 replies