Trying to convert audio to different format

Hello, I'm facing with an issue. I'm trying to convert the Opus audioformat to MuLaw, but idk how to do this. Any ideea ?
3 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
ghosty
ghostyOP14mo ago
I also have this code (the convertMulawToOpus works):
import OpusScript from "opusscript";
import { WaveFile } from "wavefile";
import { mulaw } from "alawmulaw";

const opusHelper = new OpusScript(8000, 1, OpusScript.Application.AUDIO);

export const convertMulawToOpus = (mulawBuffer: Buffer) => {
const frameSize = (8000 * 20) / 1000;
const decodedBuffer = Buffer.from(mulaw.decode(mulawBuffer).buffer);
const packet = opusHelper.encode(decodedBuffer, frameSize);
return packet;
};

export const convertOpusToMulaw = (opusBuffer: Buffer) => {
const decodedBuffer = opusHelper.decode(opusBuffer);
const waveFile = new WaveFile();
waveFile.fromScratch(1, 8000, "16", decodedBuffer);
waveFile.toMuLaw();
return Buffer.from(waveFile.toBuffer().buffer);
};
import OpusScript from "opusscript";
import { WaveFile } from "wavefile";
import { mulaw } from "alawmulaw";

const opusHelper = new OpusScript(8000, 1, OpusScript.Application.AUDIO);

export const convertMulawToOpus = (mulawBuffer: Buffer) => {
const frameSize = (8000 * 20) / 1000;
const decodedBuffer = Buffer.from(mulaw.decode(mulawBuffer).buffer);
const packet = opusHelper.encode(decodedBuffer, frameSize);
return packet;
};

export const convertOpusToMulaw = (opusBuffer: Buffer) => {
const decodedBuffer = opusHelper.decode(opusBuffer);
const waveFile = new WaveFile();
waveFile.fromScratch(1, 8000, "16", decodedBuffer);
waveFile.toMuLaw();
return Buffer.from(waveFile.toBuffer().buffer);
};
ShompiFlen
ShompiFlen14mo ago
uhhh this is not the forum channel nor the server to ask something like this you could try your luck in #other-js-ts but you should definitely check #resources and other programming servers
Want results from more Discord servers?
Add your server