# Adding Delay Time for Audio Source

**URL:** <https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813>\
**Category:** Jetson Nano\
**Tags:** audio\
**Created:** [July 20, 2020, 7:48pm UTC](https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813 "2020-07-20T19:48:00Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![myagmur](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@myagmur](https://forums.developer.nvidia.com/u/myagmur)\
**Post date:** [July 20, 2020, 7:48pm UTC](https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813/1 "2020-07-20T19:48:00Z")

</div>

Hi,

I want to introduce some delay to audio output in order to synchronize it with a video camera source. Is that possible by changing any parameters on Nano?

Thank you

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [July 21, 2020, 12:08am UTC](https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813/3 "2020-07-21T00:08:05Z")

</div>

Hi,  
Please share your release version( $ head -1 /etc/nv\_tegra\_release ) and audio device for reference. Not sure but you run audio/video recording on Jetson Nano? Do you run gstreamer command?

---

<div class="post-metadata">

**Author:** ![myagmur](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@myagmur](https://forums.developer.nvidia.com/u/myagmur)\
**Post date:** [July 21, 2020, 12:37am UTC](https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813/4 "2020-07-21T00:37:17Z")

</div>

Hi @DaneLLL,

The version is R32, 3.1  
I don’t use gstreamer because I want to connect the microphone to the browser for video conferencing, such as Hangouts Meeting.The only thing I need is to stream the auido to the browser with some delay.

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [July 21, 2020, 8:51am UTC](https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813/5 "2020-07-21T08:51:22Z")

</div>

Hi,  
Does the microphone go through USB or audio codec? Please share _arecord -l_ for information.

---

<div class="post-metadata">

**Author:** ![myagmur](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@myagmur](https://forums.developer.nvidia.com/u/myagmur)\
**Post date:** [July 21, 2020, 5:25pm UTC](https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813/6 "2020-07-21T17:25:15Z")

</div>

Hi @DaneLLL,

It is connected to USB port. Attaching arecord output as below. The device shown in rectangle is what I am trying to adjust for a delay.

 ![IMG_6081](https://global.discourse-cdn.com/nvidia/original/3X/5/6/567d03c5f589aced5e6f99732b221b82efbd8370.jpeg)

Thank you

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [July 24, 2020, 2:25am UTC](https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813/7 "2020-07-24T02:25:11Z")

</div>

Hi,  
You would need to check if the application supports the function. In _arecord_, there is an option:

```auto
-R, --start-delay=# delay for automatic PCM start is # microseconds
                        (relative to buffer size if <= 0)

```

Please set it and try.

---

<div class="post-metadata">

**Author:** ![myagmur](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@myagmur](https://forums.developer.nvidia.com/u/myagmur)\
**Post date:** [July 24, 2020, 10:11am UTC](https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813/8 "2020-07-24T10:11:47Z")

</div>

Hi @DaneLLL,

Thank you for your help  
I applied that but got the following weird result:  
I also connected the microphone to the browser application to check if delay introduced, but nothing has changed, it still in real-time

![Screenshot from 2020-07-24 13-06-28](https://global.discourse-cdn.com/nvidia/original/3X/3/d/3d0e992cb6d11a285d872290a6674835bf227d1c.png)

---

<div class="post-metadata">

**Author:** ![jonathanh](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/jonathanh/32/14043_2.png) [@jonathanh](https://forums.developer.nvidia.com/u/jonathanh)\
**Post date:** [July 29, 2020, 1:12pm UTC](https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813/9 "2020-07-29T13:12:48Z")

</div>

Hello!

You should be able to adjust the latency using pavucontrol. To install …

```auto
$ sudo apt install pavucontrol

```

Then open the ‘PulseAudio Volume Control’ desktop application from the ubuntu menu. Under the ‘Output Devices’ tab, if you expand the ‘Advanced’ option for the appropriate sound card, you should be able to increase the ‘latency’ to delay the audio. See the attached screen shot.

 ![pavucontrol](https://global.discourse-cdn.com/nvidia/original/3X/c/d/cdc23074319e39da8ef52aa2a34315f4ae94c499.png)  
Regards  
Jon

---

<div class="post-metadata">

**Author:** ![Andrey1984](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/andrey1984/32/14130_2.png) [@Andrey1984](https://forums.developer.nvidia.com/u/Andrey1984)\
**Post date:** [August 1, 2020, 5:24pm UTC](https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813/10 "2020-08-01T17:24:13Z")

</div>

the pavucontrol doesn’t appear to impact the input device latency;  
tested with usb microphone & web meeting app connected from other network computer  
despite the latency values for the micrphone , the audio stream will have no latency at web browser

> <https://unix.stackexchange.com/questions/492716/latency-doesnt-work-with-pulseaudio-on-linux>

In the latter article they proposed

```auto
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

```

Not sure how to adopt it for usb microphone use case though

```auto
 pactl load-module module-loopback latency_msec=2000 source=delayed.monitor sink=alsa_output.pci-0000_00_1b.0.analog-stereo
Failure: Module initialization failed

```

---

<div class="post-metadata">

**Author:** ![jonathanh](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/jonathanh/32/14043_2.png) [@jonathanh](https://forums.developer.nvidia.com/u/jonathanh)\
**Post date:** [August 4, 2020, 12:16pm UTC](https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813/11 "2020-08-04T12:16:47Z")

</div>

Hello!

I tested audio playback from the web browser and verified that the latency is applied. In other words, I can see that the audio and video becomes out-of-sync when increasing the latency. How do you determine that the latency applied to the input is not taking effect? Are you looping the audio back?

Regards,  
Jon

---

<div class="post-metadata">

**Author:** ![Andrey1984](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/andrey1984/32/14130_2.png) [@Andrey1984](https://forums.developer.nvidia.com/u/Andrey1984)\
**Post date:** [August 4, 2020, 4:07pm UTC](https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813/12 "2020-08-04T16:07:08Z")

</div>

Hello!  
Thank you for you rresponse!  
were you able to select in the browser the input source as a virtual microphone? virtual microphone with latency? or as a hardware microphone? both? neither of the two?  
How did you introduce the latency in the tested scenario? In case that you managed to verify in the web browser?  
Could you share steps how to reproduce it, please?  
I am still trying to determine how to make sure the hardware microphone is looped to a virtual adudio device microphone.  
I was testing with web video chat from Jetson NX using jitsi meet application;  
First I would` modprobe snd-aloop`,  
It would create the card3 device

```auto
 ls /proc/asound/card3
cable#0 cable#1 id pcm0c pcm0p pcm1c pcm1p

```

Also I would try to sink to the virtual device [card 3]

```auto
pacmd load-module module-alsa-sink device=hw:3,1

```

Then I would make the virtual microphone the default source with first listing sources and then setting up the default source:

```auto
index: 0
	name: <alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo.monitor>
		device.string = "2"
  * index: 1
	name: <alsa_input.usb-Logitech_Logitech_USB_Headset-00.analog-mono>
		device.string = "hw:2"
    index: 2
	name: <alsa_output.platform-sound.analog-stereo.monitor>
		device.string = "1"
    index: 3
	name: <alsa_input.platform-sound.analog-stereo>
		device.string = "front:1"
    index: 4
	name: <alsa_output.platform-snd_aloop.0.analog-stereo.monitor>
		device.string = "3"
    index: 5
	name: <alsa_input.platform-snd_aloop.0.analog-stereo>
		device.string = "front:3"
    index: 6
	name: <alsa_output.hw_3_1.monitor>

```

`pacmd "set-default-source alsa_input.platform-snd_aloop.0.analog-stereo"`  
Then I would try connecting to web browser video web chat application [this time tested with jitsi], but still it wouldn’t appear to list virtual devices at all, it would still seem top recognize hardware usb microphone input as the only working;  
I also tryed doing gsteramer streaming with the default source , then conencted from network computer with VLC to the rtsp gstreamer pipeline, and there wold be silence if it uses the virtual source that I specified in the scenario above.

```auto
/test-launch 'videotestsrc ! nvvidconv ! nvv4l2h264enc ! h264parse ! queue ! rtph264pay name=pay0 pt=96 alsasrc buffer-time=32000 latency-time=16000 ! voaacenc ! queue ! rtpmp4apay pt=97 name=pay1'

```

> [@jonathanh](#):
>
> How do you determine that the latency applied to the input is not taking effect?

Initially I used pulse audio volume control → advanced added maximal delay 2 seconds [2000]. the delay was added to the input source, not to the playing source , then opened a browser and found that the gUI method doesn’t seem to work as the delay wasn;'t introduced. Did you try otherwise?

> [@jonathanh](#):
>
> Are you looping the audio back?

That is what I am trying to figure out how to add a delay and loop it with a delay to anywhere, e.g. to virtual microphone device. Or otherwise back to where? Back to the hardware microphone?  
Probably I missed some factors trying to loop audio and introducing latency.  
If you could share your steps that would be helpful, Thanks.

---

<div class="post-metadata">

**Author:** ![Andrey1984](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/andrey1984/32/14130_2.png) [@Andrey1984](https://forums.developer.nvidia.com/u/Andrey1984)\
**Post date:** [August 12, 2020, 8:01am UTC](https://forums.developer.nvidia.com/t/adding-delay-time-for-audio-source/142813/13 "2020-08-12T08:01:15Z")

</div>

@Jon,  
It seems that it fails with error?

```auto
sudo modprobe snd-aloop
pulseaudio -D
pacmd list-sources | grep -e 'index:' -e device.string -e 'name:'
 index: 0
	name: <alsa_output.platform-snd_aloop.0.analog-stereo.monitor>
		device.string = "2"
    index: 1
	name: <alsa_input.platform-snd_aloop.0.analog-stereo>
		device.string = "front:2"
    index: 2
	name: <alsa_output.platform-sound.analog-stereo.monitor>
		device.string = "1"
  * index: 3
	name: <alsa_input.platform-sound.analog-stereo>
		device.string = "front:1"
    index: 4
	name: <alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo.monitor>
		device.string = "3"
 pacmd list-sources | grep -e 'index:' -e device.string -e 'name:'
    index: 0
	name: <alsa_output.platform-snd_aloop.0.analog-stereo.monitor>
		device.string = "2"
  * index: 1
	name: <alsa_input.platform-snd_aloop.0.analog-stereo>
		device.string = "front:2"
    index: 2
	name: <alsa_output.platform-sound.analog-stereo.monitor>
		device.string = "1"
    index: 3
	name: <alsa_input.platform-sound.analog-stereo>
		device.string = "front:1"
    index: 4
	name: <alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo.monitor>
		device.string = "3"

ls /proc/asound/card2
cable#0 cable#1 id pcm0c pcm0p pcm1c pcm1p
pactl load-module module-null-sink sink_name=delayed
 pactl load-module module-null-sink sink_name=delayed
25
 pacmd list-sources | grep -e 'index:' -e device.string -e 'name:'
    index: 0
	name: <alsa_output.platform-snd_aloop.0.analog-stereo.monitor>
		device.string = "2"
  * index: 1
	name: <alsa_input.platform-snd_aloop.0.analog-stereo>
		device.string = "front:2"
    index: 2
	name: <alsa_output.platform-sound.analog-stereo.monitor>
		device.string = "1"
    index: 3
	name: <alsa_input.platform-sound.analog-stereo>
		device.string = "front:1"
    index: 4
	name: <alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo.monitor>
		device.string = "3"
    index: 5
	name: <delayed.monitor>
pacmd list-sources | grep -e 'index:' -e device.string -e 'name:'
    index: 0
	name: <alsa_output.platform-snd_aloop.0.analog-stereo.monitor>
		device.string = "2"
    index: 1
	name: <alsa_input.platform-snd_aloop.0.analog-stereo>
		device.string = "front:2"
    index: 2
	name: <alsa_output.platform-sound.analog-stereo.monitor>
		device.string = "1"
    index: 3
	name: <alsa_input.platform-sound.analog-stereo>
		device.string = "front:1"
    index: 4
	name: <alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo.monitor>
		device.string = "3"
  * index: 5
	name: <delayed.monitor>

 pactl load-module module-loopback latency_msec=2000 source=delayed.monitor sink=alsa_input.platform-snd_aloop.0.analog-stereo
Failure: Module initialization failed
nvidia@nx:~$ pactl load-module module-loopback latency_msec=2000 source=delayed.monitor sink=alsa_output.platform-snd_aloop.0.analog-stereo.monitor
Failure: Module initialization failed

```

Upd:  
I got something working

```auto
pactl load-module module-loopback latency_msec=10000
37

```

in my current environment due to multiple loopback it plays twice using it: at once and with the specified delay;

ref: [pulseaudio - How to listen live sounds from input from external sound card? - Ask Ubuntu](https://askubuntu.com/questions/403416/how-to-listen-live-sounds-from-input-from-external-sound-card)

```auto
pacmd list-sources | grep -e 'index:' -e device.string -e 'name:'
    index: 0
	name: <alsa_input.usb-Logitech_Logitech_USB_Headset-00.analog-mono>
		device.string = "hw:2"
    index: 1
	name: <alsa_output.platform-sound.analog-stereo.monitor>
		device.string = "1"
    index: 2
	name: <alsa_input.platform-sound.analog-stereo>
		device.string = "front:1"
  * index: 3
	name: <delayed.monitor>
    index: 4
	name: <alsa_output.platform-snd_aloop.0.analog-stereo.monitor>
		device.string = "3"
    index: 5
	name: <alsa_input.platform-snd_aloop.0.analog-stereo>
		device.string = "front:3"
    index: 6
	name: <delayed.2.monitor>

```

```auto
$ pactl load-module module-loopback latency_msec=3000 source=0 sink=5
Failure: Module initialization failed

```

What actually works, but requires manual actions in Graphical interface:

````auto
1. ```nx:~$ sudo reboot```
at nx open browser and conenct e.g to https://meet.jit.si/test123321 ; then connect to the same url from another computer to hear audio
open Settings Pulse volume Control- Recordings

````

```auto
pactl load-module module-loopback latency_msec=30000 source=0
pactl load-module module-null-sink sink_name=delayed

```

select the null device in the recordings list;  
upd: proved to work at nx by now if to listen at other computer it will have the delay  
further possible optimization - to find out how to manage it from terminal without GUI at all
