Reading the mic input to send them over udp

Hii everyone I am trying to send video and audio over udp to the server. Till now I am successfully sending the video in rtp packets but for audio I am getting issues i can not get the input of the mic and send the packets.
here I am giving my code for video part. Any help in sending the audio with this video will me much appriciated.
Thanks !!
#include <WiFi.h>
#include <WiFiUdp.h>
#include “VideoStream.h”

#define CHANNEL 0
VideoSetting config(1920, 1080, CAM_FPS, VIDEO_JPEG, 1);

char ssid = “ssid”;
char pass = “pass”;
WiFiUDP udp;

IPAddress serverIP(192, 168, 31, 68);
const uint16_t serverPort = 4000;

uint32_t img_addr = 0;
uint32_t img_len = 0;
uint16_t sequenceNumber = 0;
uint32_t timestamp = 0;
uint32_t ssrc = 0x12345678;

void buildRTPHeader(uint8_t* header, uint16_t seq, uint32_t ts, bool marker) {
header[0] = 0x80; // Version 2
header[1] = 26 | (marker ? 0x80 : 0x00); // PT = 26 for MJPEG
header[2] = seq >> 8;
header[3] = seq & 0xFF;
header[4] = ts >> 24;
header[5] = ts >> 16;
header[6] = ts >> 8;
header[7] = ts & 0xFF;
header[8] = ssrc >> 24;
header[9] = ssrc >> 16;
header[10] = ssrc >> 8;
header[11] = ssrc & 0xFF;
}

void sendJPEGasRTP(uint8_t* jpeg, uint32_t len) {
const uint32_t maxPayloadSize = 1400; // for safe MTU
uint32_t offset = 0;
timestamp += 3600; // simulate 25fps

while (offset < len) {
    uint32_t payloadLen = min(maxPayloadSize, len - offset);
    bool marker = (offset + payloadLen) >= len;

    uint8_t packet[1500];  // 12 + 8 + 1400 max

    // RTP Header (12 bytes)
    buildRTPHeader(packet, sequenceNumber++, timestamp, marker);

    // MJPEG RTP header (8 bytes) per RFC 2435
    uint8_t* mjpegHeader = packet + 12;
    mjpegHeader[0] = 0;  // Type-specific
    mjpegHeader[1] = (offset >> 16) & 0xFF;
    mjpegHeader[2] = (offset >> 8) & 0xFF;
    mjpegHeader[3] = offset & 0xFF;
    mjpegHeader[4] = 1;  // Type
    mjpegHeader[5] = 0;  // Q
    mjpegHeader[6] = 1920 / 8;  // Width in 8-pixel blocks
    mjpegHeader[7] = 1080 / 8;  // Height in 8-pixel blocks

    // Copy JPEG data
    memcpy(packet + 12 + 8, jpeg + offset, payloadLen);

    // ✅ Send packet via UDP
    udp.beginPacket(serverIP, serverPort);
    udp.write(packet, 12 + 8 + payloadLen);
    udp.endPacket();

    offset += payloadLen;
    delay(1);  // pacing
}

}

void setup() {
Serial.begin(115200);
while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
delay(5000);
}
Serial.println(WiFi.localIP());

Camera.configVideoChannel(CHANNEL, config);
Camera.videoInit();
Camera.channelBegin(CHANNEL);

udp.begin(12345);  // Any local port

}

void loop() {
Camera.getImage(CHANNEL, &img_addr, &img_len);
sendJPEGasRTP((uint8_t*)img_addr, img_len);
delay(40); // ~25fps
}

Hi @Bhanu_Pratap,

Can I double confirm if you are using the default mic on our AMB82-Mini?

Thank you.

yes I am using in built default mic. @Kelvin_Huang

@Kelvin_Huang please assist on this. Will be very helpful.

Hi @Bhanu_Pratap,

Have you check out this? Multimedia – RTP Audio Stream – Realtek IoT/Wi-Fi MCU Solutions

Thank you.

Hello @Kelvin_Huang , thanks for your reply.
I checked this solution but this example is made for just receiving the rtp audio packets.
But it did not help me in sending rtp audio packets out of the device. Please check again and let me know if you can provide any other solution or resource.
Thank you.

Hi @Bhanu_Pratap,

There is no existing example at the moment.

However, please take reference to these two examples:

RTP Audio Stream: RTP->decoder-> Audio

Audio Classification example: Audio → NN engine to do audio classification.

Your actual use case is Audio->encoder->RTP or Audio-> RTP.

You can write your own module and try to send the RTP packets.

Thank you.