Skip to content

Commit 9e1f9cb

Browse files
Merge pull request #1574 from edisonmartinsmkt/develop
feat(audio): support LPCM and fix waveform distortion
2 parents 614ad7c + 44e0ff2 commit 9e1f9cb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@prisma/client": "^6.1.0",
5959
"@sentry/node": "^8.47.0",
6060
"amqplib": "^0.10.5",
61+
"audio-decode": "^2.2.3",
6162
"axios": "^1.7.9",
6263
"baileys": "github:EvolutionAPI/Baileys",
6364
"class-validator": "^0.14.1",

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3024,6 +3024,8 @@ export class BaileysStartupService extends ChannelStartupService {
30243024
inputAudioStream.end(audioBuffer);
30253025
}
30263026

3027+
const isLpcm = isURL(audio) && /\.lpcm($|\?)/i.test(audio);
3028+
30273029
return new Promise((resolve, reject) => {
30283030
const outputAudioStream = new PassThrough();
30293031
const chunks: Buffer[] = [];
@@ -3041,7 +3043,14 @@ export class BaileysStartupService extends ChannelStartupService {
30413043

30423044
ffmpeg.setFfmpegPath(ffmpegPath.path);
30433045

3044-
ffmpeg(inputAudioStream)
3046+
let command = ffmpeg(inputAudioStream);
3047+
3048+
if (isLpcm) {
3049+
this.logger.verbose('Detected LPCM input – applying raw PCM settings');
3050+
command = command.inputFormat('s16le').inputOptions(['-ar', '24000', '-ac', '1']);
3051+
}
3052+
3053+
command
30453054
.outputFormat('ogg')
30463055
.noVideo()
30473056
.audioCodec('libopus')

0 commit comments

Comments
 (0)