[GH-ISSUE #39] how can I capture voice audios #32

Open
opened 2026-02-27 10:25:31 +03:00 by kerem · 2 comments
Owner

Originally created by @aledc7 on GitHub (Aug 22, 2024).
Original GitHub issue: https://github.com/mimamch/wa-multi-session/issues/39

How can I capture the voice audio of users?

In the docs we have: but nothing about capture audio.

// Send Voice Note

const filename = "myaudio.mp3";
const audio = fs.readFileSync(filename); // return Buffer
const send = await whatsapp.sendVoiceNote({
  sessionId: "session1",
  to: "6281234567890",
  media: audio,
});

how can we archive that?

Thank you

Originally created by @aledc7 on GitHub (Aug 22, 2024). Original GitHub issue: https://github.com/mimamch/wa-multi-session/issues/39 How can I capture the voice audio of users? In the docs we have: but nothing about capture audio. ```js // Send Voice Note const filename = "myaudio.mp3"; const audio = fs.readFileSync(filename); // return Buffer const send = await whatsapp.sendVoiceNote({ sessionId: "session1", to: "6281234567890", media: audio, }); ``` how can we archive that? Thank you
Author
Owner

@Reda-l commented on GitHub (Jan 26, 2025):

Hi! Did you manage to figure this out?

If not, I was able to achieve it using whiskeysockets/baileys. Here's a snippet of my implementation that captures and processes voice audio from users and saves it locally:

`import { downloadMediaMessage } from '@whiskeysockets/baileys';
import * as fs from 'fs';
import * as path from 'path';

private async handleAudioMessage(msg: any, sessionId: string): Promise {
try {
const audioDir = path.join('media_downloads', sessionId, 'audio');
fs.mkdirSync(audioDir, { recursive: true });

const mediaId = msg.message.audioMessage.mediaKey.toString('hex');
const filePath = path.join(audioDir, `${mediaId}.mp3`);

console.log('📥 Downloading audio message...');
const buffer = await downloadMediaMessage(msg, 'buffer', {});
fs.writeFileSync(filePath, buffer);

console.log('✅ Audio saved to:', filePath);
return filePath;

} catch (error) {
console.error(' Error handling audio message:', error);
throw new Error(Failed to process audio message: ${error.message});
}
}`

Good luck! ✌️

<!-- gh-comment-id:2614203638 --> @Reda-l commented on GitHub (Jan 26, 2025): Hi! Did you manage to figure this out? If not, I was able to achieve it using whiskeysockets/baileys. Here's a snippet of my implementation that captures and processes voice audio from users and saves it locally: `import { downloadMediaMessage } from '@whiskeysockets/baileys'; import * as fs from 'fs'; import * as path from 'path'; private async handleAudioMessage(msg: any, sessionId: string): Promise<string> { try { const audioDir = path.join('media_downloads', sessionId, 'audio'); fs.mkdirSync(audioDir, { recursive: true }); const mediaId = msg.message.audioMessage.mediaKey.toString('hex'); const filePath = path.join(audioDir, `${mediaId}.mp3`); console.log('📥 Downloading audio message...'); const buffer = await downloadMediaMessage(msg, 'buffer', {}); fs.writeFileSync(filePath, buffer); console.log('✅ Audio saved to:', filePath); return filePath; } catch (error) { console.error('❌ Error handling audio message:', error); throw new Error(`Failed to process audio message: ${error.message}`); } }` Good luck! ✌️
Author
Owner

@aledc7 commented on GitHub (Jan 26, 2025):

Hi! Did you manage to figure this out?

If not, I was able to achieve it using whiskeysockets/baileys. Here's a snippet of my implementation that captures and processes voice audio from users and saves it locally:

`import { downloadMediaMessage } from '@whiskeysockets/baileys'; import * as fs from 'fs'; import * as path from 'path';

private async handleAudioMessage(msg: any, sessionId: string): Promise { try { const audioDir = path.join('media_downloads', sessionId, 'audio'); fs.mkdirSync(audioDir, { recursive: true });

const mediaId = msg.message.audioMessage.mediaKey.toString('hex');
const filePath = path.join(audioDir, `${mediaId}.mp3`);

console.log('📥 Downloading audio message...');
const buffer = await downloadMediaMessage(msg, 'buffer', {});
fs.writeFileSync(filePath, buffer);

console.log('✅ Audio saved to:', filePath);
return filePath;

} catch (error) { console.error(' Error handling audio message:', error); throw new Error(Failed to process audio message: ${error.message}); } }`

Good luck! ✌️

Thank you very much, just like you, I have managed to send audios by switching to the Baileys library. Greetings!

<!-- gh-comment-id:2614335952 --> @aledc7 commented on GitHub (Jan 26, 2025): > Hi! Did you manage to figure this out? > > If not, I was able to achieve it using whiskeysockets/baileys. Here's a snippet of my implementation that captures and processes voice audio from users and saves it locally: > > `import { downloadMediaMessage } from '@whiskeysockets/baileys'; import * as fs from 'fs'; import * as path from 'path'; > > private async handleAudioMessage(msg: any, sessionId: string): Promise { try { const audioDir = path.join('media_downloads', sessionId, 'audio'); fs.mkdirSync(audioDir, { recursive: true }); > > ``` > const mediaId = msg.message.audioMessage.mediaKey.toString('hex'); > const filePath = path.join(audioDir, `${mediaId}.mp3`); > > console.log('📥 Downloading audio message...'); > const buffer = await downloadMediaMessage(msg, 'buffer', {}); > fs.writeFileSync(filePath, buffer); > > console.log('✅ Audio saved to:', filePath); > return filePath; > ``` > > } catch (error) { console.error('❌ Error handling audio message:', error); throw new Error(`Failed to process audio message: ${error.message}`); } }` > > Good luck! ✌️ Thank you very much, just like you, I have managed to send audios by switching to the Baileys library. Greetings!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/wa-multi-session-mimamch#32
No description provided.