Skip to content

fix audio playback problems#102

Merged
9cb14c1ec0 merged 2 commits intomasterfrom
fix-audio
Oct 13, 2025
Merged

fix audio playback problems#102
9cb14c1ec0 merged 2 commits intomasterfrom
fix-audio

Conversation

@9cb14c1ec0
Copy link
Copy Markdown
Collaborator

@9cb14c1ec0 9cb14c1ec0 commented Oct 13, 2025

Fixes # .

Changes proposed in this pull request

Whatsapp on android has voice message playback problems unless the message is sent via ogg format. This PR updates venom to allow ogg files, which can be created like this:

ffmpeg(inputPath)
    .audioCodec('libopus')
    .audioChannels(1)
    .audioFrequency(16000)
    .audioBitrate('16k')
    .format('ogg')
    .outputOptions([
      '-vn', // no video
      '-application',
      'voip', // optimize opus for voice
      '-map_metadata',
      '-1' // remove all metadata
    ])
    .output(out)

Summary by CodeRabbit

  • New Features
    • Added support for sending OGG audio as voice messages, expanding compatibility beyond MP3/MPEG.
  • Tests
    • Updated test flow to generate an OGG sample and send it as a voice message for validation.
  • Chores
    • Added a runtime dependency to enable on-the-fly audio processing for OGG support.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Oct 13, 2025

Walkthrough

Adds a runtime dependency fluent-ffmpeg, extends sender logic to accept audio/ogg alongside audio/mp3/audio/mpeg for voice sending, and updates the test script to transcode test.mp3test.ogg (Opus) and send it as a voice message.

Changes

Cohort / File(s) Summary of edits
Dependencies
package.json
Added runtime dependency fluent-ffmpeg.
Audio sending logic
src/api/layers/sender.layer.ts
Expanded MIME checks to include audio/ogg where audio/mp3/audio/mpeg were previously validated (base64 download, PTT eligibility); no exported API/signature changes.
Test workflow
test/index.js
Imported fluent-ffmpeg; added FFmpeg pipeline to convert test.mp3test.ogg (libopus, mono, 16 kHz, ~16 kbps), and send resulting test.ogg as a voice message with basic completion/error handling.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant Test as test/index.js
  participant FF as FFmpeg (fluent-ffmpeg)
  participant Sender as sender.layer

  Dev->>Test: start()
  Test->>FF: transcode test.mp3 → test.ogg (libopus, mono, 16kHz)
  FF-->>Test: test.ogg (on end)
  Test->>Sender: sendVoice('test.ogg')
  Sender-->>Test: resolve/reject
Loading
sequenceDiagram
  autonumber
  participant Client as Caller
  participant Sender as sender.layer
  participant Net as Downloader

  Client->>Sender: sendVoice(src)
  alt src is URL/Path
    Sender->>Net: download/read as base64
    Net-->>Sender: base64 + MIME (audio/ogg|audio/mpeg|audio/mp3)
  end
  alt MIME in {audio/ogg, audio/mpeg, audio/mp3}
    Sender-->>Client: proceed with PTT/sendVoice flow
  else Unsupported MIME
    Sender-->>Client: reject or alternate handling
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I tuned my ears to Opus breeze,
I hopped and piped the bytes with ease,
FFmpeg hummed, OGG came through,
Now voices hop where formats grew.
A rabbit cheer — send PTT anew! 🐇🎶

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title Check ❓ Inconclusive The current title “fix audio playback problems” is overly generic and does not highlight the specific change of adding OGG support for WhatsApp voice messages, making it unclear what exact issue is being addressed and reducing its usefulness when browsing the project history. Please update the title to explicitly reference OGG support and the context of WhatsApp voice messages, for example “Add OGG support to fix WhatsApp audio playback issues,” so that the primary change is directly conveyed.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-audio

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d33f4d5 and 5dbdc47.

📒 Files selected for processing (1)
  • src/api/layers/sender.layer.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/api/layers/sender.layer.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@9cb14c1ec0 9cb14c1ec0 changed the title fix script loading problems fix audio playback problems Oct 13, 2025
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/api/layers/sender.layer.ts (2)

902-906: Update error message to reflect OGG support.

The error message still states "Use the MP3 format" but the code now accepts both MP3 and OGG formats.

Apply this diff to update the error message:

         } else {
           obj = {
             erro: true,
             to: to,
-            text: 'Use the MP3 format to be able to send an audio!'
+            text: 'Unsupported audio format. Use MP3 or OGG format to send audio.'
           };
           return reject(obj);
         }

811-834: Inconsistency: sendVoiceBase64 lacks audio/ogg support.

The sendVoice function now supports audio/ogg, but sendVoiceBase64 (lines 811-834) only checks for audio/mpeg and audio/mp3. This creates an API inconsistency where users can send OGG files via sendVoice but not via sendVoiceBase64.

Additionally, line 812 has a pre-existing logic bug: the condition !mimeType || mimeType.includes('audio/mpeg') || mimeType.includes('audio/mp3') will pass if !mimeType is true, allowing invalid base64 through the MIME check.

Apply this diff to add OGG support and fix the logic bug:

 public async sendVoiceBase64(to: string, base64: string, passId?: any) {
   return new Promise(async (resolve, reject) => {
     const mimeType: any = base64MimeType(base64);

     if (!mimeType) {
       obj = {
         erro: true,
         to: to,
         text: 'Invalid base64!'
       };
       return reject(obj);
     }

     if (
-      !mimeType ||
-      mimeType.includes('audio/mpeg') ||
-      mimeType.includes('audio/mp3')
+      mimeType.includes('audio/mpeg') ||
+      mimeType.includes('audio/mp3') ||
+      mimeType.includes('audio/ogg')
     ) {
       const result = await this.page.evaluate(
         ({ to, base64, passId }) => {
           return WAPI.sendPtt(base64, to, passId);
         },
         { to, base64, passId }
       );
       if (result['erro'] == true) {
         reject(result);
       } else {
         resolve(result);
       }
     } else {
       obj = {
         erro: true,
         to: to,
-        text: 'Use the MP3 format to be able to send an audio!'
+        text: 'Unsupported audio format. Use MP3 or OGG format to send audio.'
       };
       return reject(obj);
     }
   });
 }
🧹 Nitpick comments (1)
test/index.js (1)

26-27: Hard-coded file paths reduce test flexibility.

The test uses hard-coded paths (test.mp3, test.ogg) which may not exist or may vary across environments.

Consider making these configurable or checking file existence:

+ const inputPath = process.env.TEST_AUDIO_INPUT || 'test.mp3';
+ const out = process.env.TEST_AUDIO_OUTPUT || 'test.ogg';
- let inputPath = 'test.mp3';
- let out = 'test.ogg';
+ 
+ // Verify input file exists before processing
+ const fs = await import('fs');
+ if (!fs.existsSync(inputPath)) {
+   console.error(`Input file not found: ${inputPath}`);
+   return;
+ }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 490b070 and d33f4d5.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/api/layers/sender.layer.ts (2 hunks)
  • test/index.js (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
test/index.js

📄 CodeRabbit inference engine (CLAUDE.md)

Use test/index.js as the main test script; tests are basic scripts without a formal framework

Files:

  • test/index.js
src/api/layers/*.layer.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Keep functionality layers in src/api/layers using the *.layer.ts naming (e.g., sender.layer.ts, listener.layer.ts, group.layer.ts, profile.layer.ts, controls.layer.ts, retriever.layer.ts)

Files:

  • src/api/layers/sender.layer.ts
🔇 Additional comments (1)
test/index.js (1)

43-43: Placeholder user ID in test.

The user ID '000000000000@c.us' appears to be a placeholder and will fail to deliver the message.

Confirm whether this is intentional for local testing or if it should be replaced with a configurable recipient. If this is intended for CI/CD testing, consider skipping the actual send operation or using a mock.

@9cb14c1ec0 9cb14c1ec0 merged commit 7433238 into master Oct 13, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant