How do I purposely delay an audio streaming?

Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Tobari
Level 2
Level 2
Posts: 73
Joined: Tue Jun 02, 2020 5:24 am

How do I purposely delay an audio streaming?

Post by Tobari »

Hello there!

I use my smartphone as a webcam with DroidCam. The video is slightly delayed.

Since the video is slightly delayed while my sound input (not through DroidCam) is not delayed, audio and video are not in sync.

How do I set things so that the sound input is also delayed as much as the video is delayed?

I played with "Latency offset" in pavucontrol, thinking it was the trick, but it doesn't change a thing.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Tobari
Level 2
Level 2
Posts: 73
Joined: Tue Jun 02, 2020 5:24 am

Re: How do I purposely delay an audio streaming?

Post by Tobari »

I'd like to add latency to the microphone so that the audio input is in sync with a lagging webcam.

Configuring latency offset on pavucontrol doesn't work. Then, I types two lines in the terminal:

Code: Select all

pactl load-module module-null-sink sink_name=delayed
pactl load-module module-loopback latency_msec=2000 source=delayed.monitor sink=alsa_output.pci-0000_00_1b.0.analog-stereo
After I type the first line, the terminal indicates a number. After I run the second line, it says Failure: Module initialization failed

Also, /etc/pulse/client.conf only has comment lines (starting with ; or #). Is it normal?
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: How do I purposely delay an audio streaming?

Post by MrEen »

Hi Tobari,

Yes, client.conf is normal. They are showing the defaults, so if you want to change them, you remove the semicolon and space at the beginning of the line you are changing. You then need to run pulseaudio -k in the terminal to restart the sound daemon or reboot for the change to take effect.

I have no experience at all with what you're trying to do, but your idea seems like the right one to me.
Tobari
Level 2
Level 2
Posts: 73
Joined: Tue Jun 02, 2020 5:24 am

Re: How do I purposely delay an audio streaming?

Post by Tobari »

Thanks for the encouragement!

In fact, if I understand correctly, pactl load-module module-loopback is to hear myself in realm time. I got it to work this way.

But it's not what I want. What I want is for my mic in Zoom (or Skype, or whatever) to be delayed.

Do you know a command line to do that?

Do you have any suggestion?
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: How do I purposely delay an audio streaming?

Post by MrEen »

I do not know how to do something like that. The issue is the two different devices each have their own latencies, and obviously they aren't in sync.

If I get any free time this weekend I'll see if I can find anything that might be helpful.
Tobari
Level 2
Level 2
Posts: 73
Joined: Tue Jun 02, 2020 5:24 am

Re: How do I purposely delay an audio streaming?

Post by Tobari »

MrEen wrote: Sat Feb 20, 2021 10:15 pm I do not know how to do something like that. The issue is the two different devices each have their own latencies, and obviously they aren't in sync.

If I get any free time this weekend I'll see if I can find anything that might be helpful.
Thank you, MrEen!

For today, I'll teach with both audio and video from droidcam. This way, both will be in sync, but the sound is a little trashy. It's better than nothing. If I plug my mic on the computer, the sound is better, but it arrives before the slightly delayed video from droidcam.

So, my ideal solution would be to have a good sound intentionally delayed to be in sync with the video. If that makes sense.
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: How do I purposely delay an audio streaming?

Post by MrEen »

Not having much luck yet, but I have an idea that we can test.

Install (if necessary) and run PulseAudio Volume Control (pavucontrol) and on the Input Devices tab click on Advanced under the mic you want to delay. Try 2000 there for Latency offset. If it makes no difference, run pulseaudio -k and try again. And if the sound gets even further ahead of the video, try -2000.

It sounds like this is what might be needed, but it doesn't seem to have worked for anyone that I could find. But one person did have them get further out of sync, so it must have done something.

If the above doesn't do anything at all with both 2000 and -2000, I don't know what else to try. If one of them has any sort of impact, even in the wrong direction, maybe we can do some more tweaking to get it right.
Tobari
Level 2
Level 2
Posts: 73
Joined: Tue Jun 02, 2020 5:24 am

Re: How do I purposely delay an audio streaming?

Post by Tobari »

Thank you for your time!

Unfortunately, it doesn't work. I've tried it already and came to the same conclusion.

I vaguely remember reading somewhere that such settings in Pavucontrol don't take effect because there is another piece of software (possibly ALSA) that overrides Pavucontrol. Can that be the case?
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: How do I purposely delay an audio streaming?

Post by MrEen »

Well ALSA is pretty vanilla. PulseAudio is where things like latency can be tweaked.

Please realize my specialty is getting sound working properly, not mucking it up! :lol:

I suspect you're going to need a LADSPA plugin to accomplish this but I don't know if you can use them successfully without using JACK. Either way, I can't offer much help on that. This is getting into advanced territory that I stopped playing with a couple of years ago. You might have better luck asking on linuxmusicians.com as the people there actually use this stuff. I tried searching for answers there, but their search is even worse than the one on the this forum.
Tobari
Level 2
Level 2
Posts: 73
Joined: Tue Jun 02, 2020 5:24 am

Re: How do I purposely delay an audio streaming?

Post by Tobari »

Thanks for your help.

I still have a question, then. Do you that if I buy an actual camera and plug my Rode mic on the camera, the video will not lag and the sound and the video will be in sync?

All this issue is due to the lagging video with droidcam. I tested other soft, such as iriun: the video was not lagging, and therefore the sound was in sync even when it was not connected to the phone, but the video quality was poorer.

So far, my understanding is: with turning a smartphone into a webcam, the better the quality video, the more lag. I assume there is no such problem with an actual camera, since it has its own software.
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: How do I purposely delay an audio streaming?

Post by MrEen »

Assuming the mic can plug into the camera, I would assume there'd be no lag as they would be sharing the same connection to the computer. Mind you, I have no experience with something like this.
Tobari
Level 2
Level 2
Posts: 73
Joined: Tue Jun 02, 2020 5:24 am

Re: How do I purposely delay an audio streaming?

Post by Tobari »

Thanks for your assistance,

You helped me a great deal. :D

I've just managed to delay the sound input with OBS Studio. It's a proper way of mucking it up.
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: How do I purposely delay an audio streaming?

Post by MrEen »

Tobari wrote: Mon Feb 22, 2021 8:26 am I've just managed to delay the sound input with OBS Studio. It's a proper way of mucking it up.
LOL!

One thing I should mention. While you're mucking about, you may confuse PulseAudio from time to time. For example, when you want mic input to be normal, it may be messed up somehow. Deleting the files in /home/YourUserName/.config/pulse then running pulseaudio -k in the terminal should clear it up again. This is a somewhat common need for people that keep changing things sound-wise.
Tobari
Level 2
Level 2
Posts: 73
Joined: Tue Jun 02, 2020 5:24 am

Re: How do I purposely delay an audio streaming?

Post by Tobari »

MrEen wrote: Mon Feb 22, 2021 10:22 pm
Tobari wrote: Mon Feb 22, 2021 8:26 am I've just managed to delay the sound input with OBS Studio. It's a proper way of mucking it up.
LOL!

One thing I should mention. While you're mucking about, you may confuse PulseAudio from time to time. For example, when you want mic input to be normal, it may be messed up somehow. Deleting the files in /home/YourUserName/.config/pulse then running pulseaudio -k in the terminal should clear it up again. This is a somewhat common need for people that keep changing things sound-wise.
Thank you! I'll keep that in mind.

Anyway, I had a false joy. OBS still doesn't work with zoom and I gave up. So normally I won't need to kill pulseaudio.
sebalis
Level 1
Level 1
Posts: 1
Joined: Fri Jul 09, 2021 3:28 am

Re: How do I purposely delay an audio streaming?

Post by sebalis »

I made myself a useful script for this and would like to share it here, because this posting is what got me on the way. I am not a Mint user but I hope the script will not depend on the distro. Details and code at https://superuser.com/a/1661554/1459918.
Locked

Return to “Sound”