ghosty
DIAdiscord.js - Imagine an app
•Created by ghosty on 10/16/2023 in #djs-voice
Trying to convert audio to different format
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);
};
5 replies