roboportal / bot_box

Universal remote control for robots. Works via the internet.
https://roboportal.io
MIT License
44 stars 6 forks source link

Audio Not Transmitting from Raspberry Pi to Browser in Webrtc Bot #16

Closed kadharsh closed 11 months ago

kadharsh commented 11 months ago

Thank you for this great project.

I've been working on setting up a Webrtc bot following the provided instructions. The project works wonderfully overall. However, I've encountered an issue with audio transmission from the Raspberry Pi to the browser. I can successfully talk on my PC, and the Raspberry Pi is playing the sound. However, the audio is not transmitted from the Raspberry Pi to the browser. The camera and controls work as expected.

I've tested the audio recording on the Raspberry Pi using the arecord command, and it works fine. I can record and playback without any issues. I have also tried the gen2brain/malgo example code capture which was also working fine.

.env file:

srv_url = "wss://api.roboportal.io:8001"

public_key = "xxxxxx-xxxxxxxxx-xxxxxxxxx-xxxxxx"
secret_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

stun_urls = "stun:stun.l.google.com:19302"
video_codec_bit_rate = 1000000
frame_format = "RGBA"
video_width = 800
video_frame_rate = 30

audio_input_enabled = true
audio_output_enabled = true

output_mode = console
port_name = "/dev/serial/by-id/..."
baud_rate = 115200

bot_box_ipc_port = 5555
robot_ipc_port = 5556
robot_ipc_host = 127.0.0.1

camera_multiplexor_i2c_bus = 1

debug = true

I am using a generic USB audio card for capturing and playing the audio, which I have set as the default card in /usr/share/alsa/alsa.conf

My setup:

Let me know if you need more details. Appreciate your help!

malykhin commented 11 months ago

Thanks for reporting this, @kadharsh.

We'll need a few days to ensure there is no regression and that the software is functioning correctly. We'll get back to you after confirming.

kadharsh commented 11 months ago

Hi @malykhin

Thanks a ton for the quick response! Take your time, and I appreciate your efforts. Feel free to reach out if you need any more info or testing on my end.

malykhin commented 11 months ago

Hi @kadharsh I've checked the microphone and it works well. The mic that I tested (it's just the one that I was able to get quickly). Steps I used to set it up:

  1. Getting the record device details: Screenshot 2023-11-17 at 7 15 02 PM
  2. Configuration: Screenshot 2023-11-17 at 7 15 23 PM
  3. Setting the gain: Screenshot 2023-11-17 at 7 13 35 PM
kadharsh commented 11 months ago

Hi @malykhin

I've reviewed my setup, and I seem to be following similar steps, but unfortunately, the audio is not coming through on the other side. Am I missing something? Here is the configuration I'm using: 1 .env file is the same

  1. record device details and OS: Screenshot from 2023-11-20 11-22-38
  2. Alsa Configuration Screenshot from 2023-11-20 11-54-36
  3. alsamixer Screenshot from 2023-11-20 11-22-04
  4. pion debug log Screenshot from 2023-11-20 11-35-21

But no audio output from the browser, the speaker option in the video player is blacked out. Screenshot from 2023-11-20 11-38-32

I've tested the microphone by recording a small audio file using this command arecord -f S16_LE -r 44100 audio_file.wav, and that's working.

malykhin commented 11 months ago

The setup looks good to me. Could you please try using headphones instead of speakers on your computer? I've noticed that my browser disables WebRTC audio if feedback occurs. Could you please share the link to the audio device you're using? I can test it on my end.

kadharsh commented 11 months ago

I tried using headphones with my PC, but unfortunately, the issue persists. The USB device I am using is Plextone GS3. Additionally, I attempted to use the microphone of the USB webcam Logitech C270, and the problem remained the same.

kadharsh commented 11 months ago

I've identified the issue – it was related to ALSA. After installing pulseaudio, the miniaudio started selecting it as the backend, resolving the problem. Now, the audio works in both directions. Additionally, I encountered distorted audio, and I solved it using this patch: https://github.com/pion/mediadevices/issues/500 Thank you @malykhin for your time and support; I appreciate it.